Skip to content

Commit

Permalink
Fix ::Row::NumifyGet breaking when using select/as or columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Axel 'fREW' Schmidt committed Mar 1, 2012
1 parent 7f1c966 commit 6667fd9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,6 +1,7 @@
Revision history for {{$dist->name}}

{{$NEXT}}
- Fix ::Row::NumifyGet breaking when using select/as or columns

2.007002 2012-01-09 16:23:08 CST6CDT
- Fix POD in AutoRemoveColumns (mattp)
Expand Down
6 changes: 4 additions & 2 deletions lib/DBIx/Class/Helper/Row/NumifyGet.pm
Expand Up @@ -3,6 +3,8 @@ package DBIx::Class::Helper::Row::NumifyGet;
use strict;
use warnings;

use Try::Tiny;

# ABSTRACT: Force numeric "context" on numeric columns

sub get_column {
Expand All @@ -11,7 +13,7 @@ sub get_column {
my $value = $self->next::method($col);

$value += 0 if defined($value) and # for nullable and autoinc fields
$self->_is_column_numeric($col);
try { $self->_is_column_numeric($col) };

return $value;
}
Expand All @@ -24,7 +26,7 @@ sub get_columns {
for (keys %columns) {
$columns{$_} += 0
if defined($columns{$_}) and # for nullable and autoinc fields
$self->_is_column_numeric($_);
try { $self->_is_column_numeric($_) };
}

return %columns;
Expand Down
11 changes: 11 additions & 0 deletions t/08-getnum.t
Expand Up @@ -6,6 +6,7 @@ use warnings;
use lib 't/lib';
use Test::More;
use Test::Deep;
use Test::Exception;
use List::Util 'first';

use TestSchema;
Expand Down Expand Up @@ -37,4 +38,14 @@ for (map +{$_->get_inflated_columns}, $schema->resultset('Foo')->all) {
ok(is_numeric($_->{id}), "id $_->{id} has been 'numified'");
}

for (map +{$_->get_inflated_columns}, $schema->resultset('Foo')->all) {
ok(is_numeric($_->{id}), "id $_->{id} has been 'numified'");
}

for ($schema->resultset('Foo')->search(undef, {
columns => { lol => 'id' },
})->all) {
lives_ok { $_->get_column('lol') } "doesn't break when using columns";
}

done_testing;

0 comments on commit 6667fd9

Please sign in to comment.