2 DBIx::Class::CDBICompat::ColumnsAsHash;
10 DBIx::Class::CDBICompat::ColumnsAsHash
14 See DBIx::Class::CDBICompat for directions for use.
18 Emulates the I<undocumnted> behavior of Class::DBI where the object can be accessed as a hash of columns. This is often used as a performance hack.
20 my $column = $row->{column};
22 =head2 Differences from Class::DBI
24 This will warn when a column is accessed as a hash key.
31 my $new = $class->next::method(@_);
33 $new->_make_columns_as_hash;
41 my $new = $class->next::method(@_);
43 $new->_make_columns_as_hash;
49 sub _make_columns_as_hash {
52 for my $col ($self->columns) {
53 if( exists $self->{$col} ) {
54 warn "Skipping mapping $col to a hash key because it exists";
57 next unless $self->can($col);
58 tie $self->{$col}, 'DBIx::Class::CDBICompat::Tied::ColumnValue',
64 package DBIx::Class::CDBICompat::Tied::ColumnValue;
67 use Scalar::Util qw(weaken isweak);
71 my($class, $obj, $col) = @_;
72 my $self = [$obj, $col];
75 return bless $self, $_[0];
80 my($obj, $col) = @$self;
84 carp "Column '$col' of '$class/$id' was fetched as a hash";
91 my($obj, $col) = @$self;
95 carp "Column '$col' of '$class/$id' was stored as a hash";