2 DBIx::Class::CDBICompat::ColumnsAsHash;
7 use base 'DBIx::Class';
11 DBIx::Class::CDBICompat::ColumnsAsHash - Emulates the behavior of Class::DBI where the object can be accessed as a hash of columns.
15 See DBIx::Class::CDBICompat for usage directions.
19 Emulates the I<undocumented> behavior of Class::DBI where the object can be accessed as a hash of columns. This is often used as a performance hack.
21 my $column = $result->{column};
23 =head2 Differences from Class::DBI
25 If C<DBIC_CDBICOMPAT_HASH_WARN> is true it will warn when a column is accessed as a hash key.
32 my $new = $class->next::method(@_);
34 $new->_make_columns_as_hash;
42 my $new = $class->next::method(@_);
44 $new->_make_columns_as_hash;
50 sub _make_columns_as_hash {
53 for my $col ($self->columns) {
54 if( exists $self->{$col} ) {
55 warn "Skipping mapping $col to a hash key because it exists";
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"
85 if $ENV{DBIC_CDBICOMPAT_HASH_WARN};
87 return $obj->column_info($col)->{_inflate_info}
88 ? $obj->get_inflated_column($col)
89 : $obj->get_column($col);
94 my($obj, $col) = @$self;
98 carp "Column '$col' of '$class/$id' was stored as a hash"
99 if $ENV{DBIC_CDBICOMPAT_HASH_WARN};
101 return $obj->column_info($col)->{_inflate_info}
102 ? $obj->set_inflated_column($col => shift)
103 : $obj->set_column($col => shift);
106 =head1 FURTHER QUESTIONS?
108 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
110 =head1 COPYRIGHT AND LICENSE
112 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
113 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
114 redistribute it and/or modify it under the same terms as the
115 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.