From: Michael G Schwern Date: Wed, 13 Feb 2008 01:16:29 +0000 (-0800) Subject: When emulating $obj->{column} do not call any custom column method, just X-Git-Tag: v0.08240~541^2~35 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=92a23d906134d27d929dc103e37e28cb4541a006;p=dbsrgits%2FDBIx-Class.git When emulating $obj->{column} do not call any custom column method, just access the data directly with get/set_column(). --- diff --git a/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm b/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm index 50acf88..9a006d6 100644 --- a/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm +++ b/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm @@ -84,7 +84,7 @@ sub FETCH { carp "Column '$col' of '$class/$id' was fetched as a hash" if $ENV{DBIC_CDBICOMPAT_HASH_WARN}; - return $obj->$col(); + return $obj->get_column($col); } sub STORE { @@ -96,7 +96,7 @@ sub STORE { carp "Column '$col' of '$class/$id' was stored as a hash" if $ENV{DBIC_CDBICOMPAT_HASH_WARN}; - $obj->$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 4e39cb7..1280f6f 100644 --- a/t/cdbi-t/columns_as_hashes.t +++ b/t/cdbi-t/columns_as_hashes.t @@ -7,7 +7,7 @@ use Test::Warn; BEGIN { eval "use DBIx::Class::CDBICompat;"; plan $@ ? (skip_all => "Class::Trigger and DBIx::ContextualFetch required: $@") - : (tests=> 9); + : (tests=> 10); } use lib 't/testlib'; @@ -50,4 +50,19 @@ is @films, 1, "column updated as hash was saved"; warning_is { local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 0; $waves->{rating} -} '', 'DBIC_CDBICOMPAT_HASH_WARN controls warnings'; \ No newline at end of file +} '', 'DBIC_CDBICOMPAT_HASH_WARN controls warnings'; + + +{ + local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 0; + + $waves->rating("R"); + $waves->update; + + no warnings 'redefine'; + local *Film::rating = sub { + return "wibble"; + }; + + is $waves->{rating}, "R"; +}