X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FCDBICompat%2FColumnsAsHash.pm;h=51b6e0baa08cb7005a260712d9173ce187439152;hb=5e0eea3522876a30453af24097507198bbbc9409;hp=9a006d6752e789b95368f603fb338bc98214f38d;hpb=92a23d906134d27d929dc103e37e28cb4541a006;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm b/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm index 9a006d6..51b6e0b 100644 --- a/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm +++ b/lib/DBIx/Class/CDBICompat/ColumnsAsHash.pm @@ -4,20 +4,21 @@ package use strict; use warnings; +use base 'DBIx::Class'; =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 -See DBIx::Class::CDBICompat for directions for use. +See DBIx::Class::CDBICompat for usage directions. =head1 DESCRIPTION -Emulates the I behavior of Class::DBI where the object can be accessed as a hash of columns. This is often used as a performance hack. +Emulates the I behavior of Class::DBI where the object can be accessed as a hash of columns. This is often used as a performance hack. - my $column = $row->{column}; + my $column = $result->{column}; =head2 Differences from Class::DBI @@ -39,22 +40,21 @@ sub inflate_result { my $class = shift; my $new = $class->next::method(@_); - + $new->_make_columns_as_hash; - + return $new; } sub _make_columns_as_hash { my $self = shift; - + for my $col ($self->columns) { if( exists $self->{$col} ) { 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; } @@ -84,7 +84,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 { @@ -96,7 +98,22 @@ 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); } +=head1 FURTHER QUESTIONS? + +Check the list of L. + +=head1 COPYRIGHT AND LICENSE + +This module is free software L +by the L. You can +redistribute it and/or modify it under the same terms as the +L. + +=cut + 1;