From: Michael G Schwern Date: Wed, 13 Feb 2008 01:46:17 +0000 (-0800) Subject: Emulate that Class::DBI inflates immediately X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1c779eb2212fac3c44e615418c2b516e18cbc5e2;p=dbsrgits%2FDBIx-Class-Historic.git Emulate that Class::DBI inflates immediately --- diff --git a/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm b/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm index dd02a63..b5f1168 100644 --- a/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm +++ b/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm @@ -83,7 +83,9 @@ sub FETCH { carp "Column '$col' of '$class/$id' was fetched as a hash" if $ENV{DBIC_CDBICOMPAT_HASH_WARN}; - return $obj->get_column($col); + return $obj->column_info($col)->{_inflate_info} + ? $obj->get_inflated_column($col) + : $obj->get_column($col); } sub STORE { @@ -95,7 +97,9 @@ sub STORE { carp "Column '$col' of '$class/$id' was stored as a hash" if $ENV{DBIC_CDBICOMPAT_HASH_WARN}; - $obj->set_column($col => shift); + return $obj->column_info($col)->{_inflate_info} + ? $obj->set_inflated_column($col => shift) + : $obj->set_column($col => shift); } 1; diff --git a/t/cdbi-t/columns_as_hashes.t b/t/cdbi-t/columns_as_hashes.t index 70f887e..24dbc2a 100644 --- a/t/cdbi-t/columns_as_hashes.t +++ b/t/cdbi-t/columns_as_hashes.t @@ -87,4 +87,19 @@ warning_is { ok !eval { $actor->film }; is $actor->{film}->id, $waves->id, 'hash access still works despite lack of accessor'; +} + + +# Emulate that Class::DBI inflates immediately +{ + require_ok 'MyFoo'; + + my $foo = MyFoo->insert({ + name => 'Whatever', + tdate => '1949-02-01', + }); + isa_ok $foo, 'MyFoo'; + + isa_ok $foo->{tdate}, 'Date::Simple'; + is $foo->{tdate}->year, 1949; } \ No newline at end of file