RT45195 various indexer fixes
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat / ColumnsAsHash.pm
index 9f265d6..7b81f09 100644 (file)
@@ -7,7 +7,7 @@ use warnings;
 
 =head1 NAME
 
-DBIx::Class::CDBICompat::ColumnsAsHash
+DBIx::Class::CDBICompat::ColumnsAsHash - Emulates the behavior of Class::DBI where the object can be accessed as a hash of columns.
 
 =head1 SYNOPSIS
 
@@ -21,7 +21,7 @@ Emulates the I<undocumnted> 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<DBIC_CDBICOMPAT_HASH_WARN> is true it will warn when a column is accessed as a hash key.
 
 =cut
 
@@ -54,7 +54,6 @@ sub _make_columns_as_hash {
             warn "Skipping mapping $col to a hash key because it exists";
         }
 
-        next unless $self->can($col);
         tie $self->{$col}, 'DBIx::Class::CDBICompat::Tied::ColumnValue',
             $self, $col;
     }
@@ -81,9 +80,12 @@ 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();
+    return $obj->column_info($col)->{_inflate_info}
+                ? $obj->get_inflated_column($col)
+                : $obj->get_column($col);
 }
 
 sub STORE {
@@ -92,9 +94,12 @@ 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);
+    return $obj->column_info($col)->{_inflate_info}
+                ? $obj->set_inflated_column($col => shift)
+                : $obj->set_column($col => shift);
 }
 
 1;