From: Michael G Schwern Date: Thu, 17 Jan 2008 21:57:39 +0000 (-0800) Subject: Make the hash-key warning dependent on DBIC_CDBICOMPAT_HASH_WARN because X-Git-Tag: v0.08240~541^2~42 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=10221b7913431aa88a47aafdd357b93de062c7c2;p=dbsrgits%2FDBIx-Class.git Make the hash-key warning dependent on DBIC_CDBICOMPAT_HASH_WARN because boy is it annoying! --- diff --git a/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm b/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm index 9f265d6..50acf88 100644 --- a/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm +++ b/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm @@ -21,7 +21,7 @@ Emulates the I behavior of Class::DBI where the object can be acces =head2 Differences from Class::DBI -This will warn when a column is accessed as a hash key. +If C is true it will warn when a column is accessed as a hash key. =cut @@ -81,7 +81,8 @@ sub FETCH { my $class = ref $obj; my $id = $obj->id; - carp "Column '$col' of '$class/$id' was fetched as a hash"; + carp "Column '$col' of '$class/$id' was fetched as a hash" + if $ENV{DBIC_CDBICOMPAT_HASH_WARN}; return $obj->$col(); } @@ -92,7 +93,8 @@ sub STORE { my $class = ref $obj; my $id = $obj->id; - carp "Column '$col' of '$class/$id' was stored as a hash"; + carp "Column '$col' of '$class/$id' was stored as a hash" + if $ENV{DBIC_CDBICOMPAT_HASH_WARN}; $obj->$col(shift); } diff --git a/t/cdbi-t/columns_as_hashes.t b/t/cdbi-t/columns_as_hashes.t index 5a5811f..4e39cb7 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=> 8); + : (tests=> 9); } use lib 't/testlib'; @@ -19,6 +19,8 @@ my $waves = Film->insert({ Rating => 'R' }); +local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 1; + warnings_like { my $rating = $waves->{rating}; $waves->Rating("PG"); @@ -43,3 +45,9 @@ warnings_like { $waves->update; my @films = Film->search( Rating => "PG", Title => "Breaking the Waves" ); 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