From: Jess Robinson Date: Tue, 2 Jan 2007 04:39:12 +0000 (+0000) Subject: Merge 'trunk' into 'DBIx-Class-current' X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=664a70fad7d9aaf7d38579cdafe934663ee4a9c3;p=dbsrgits%2FDBIx-Class-Historic.git Merge 'trunk' into 'DBIx-Class-current' --- 664a70fad7d9aaf7d38579cdafe934663ee4a9c3 diff --cc lib/DBIx/Class/InflateColumn.pm index b88ec0c,84f86b8..721894f --- a/lib/DBIx/Class/InflateColumn.pm +++ b/lib/DBIx/Class/InflateColumn.pm @@@ -145,16 -153,104 +153,17 @@@ as dirty. This is directly analogous t =cut sub store_inflated_column { - my ($self, $col, $obj) = @_; - unless (blessed $obj) { + my ($self, $col, $inflated) = @_; + # unless (blessed $inflated) { + unless (ref $inflated && ref($inflated) ne 'SCALAR') { delete $self->{_inflated_column}{$col}; - $self->store_column($col => $obj); - return $obj; + $self->store_column($col => $inflated); + return $inflated; } delete $self->{_column_data}{$col}; - return $self->{_inflated_column}{$col} = $obj; + return $self->{_inflated_column}{$col} = $inflated; } -=head2 get_column - -Gets a column value in the same way as L. If there -is an inflated value stored that has not yet been deflated, it is deflated -when the method is invoked. - -=cut - -sub get_column { - my ($self, $col) = @_; - if (exists $self->{_inflated_column}{$col} - && !exists $self->{_column_data}{$col}) { - $self->store_column($col, $self->_deflated_column($col, $self->{_inflated_column}{$col})); - } - return $self->next::method($col); -} - -=head2 get_columns - -Returns the get_column info for all columns as a hash, -just like L. Handles inflation just -like L. - -=cut - -sub get_columns { - my $self = shift; - if (exists $self->{_inflated_column}) { - foreach my $col (keys %{$self->{_inflated_column}}) { - $self->store_column($col, $self->_deflated_column($col, $self->{_inflated_column}{$col})) - unless exists $self->{_column_data}{$col}; - } - } - return $self->next::method; -} - -=head2 has_column_loaded - -Like L, but also returns true if there -is an inflated value stored. - -=cut - -sub has_column_loaded { - my ($self, $col) = @_; - return 1 if exists $self->{_inflated_column}{$col}; - return $self->next::method($col); -} - -=head2 update - -Updates a row in the same way as L, handling -inflation and deflation of columns appropriately. - -=cut - -sub update { - my ($class, $attrs, @rest) = @_; - foreach my $key (keys %{$attrs||{}}) { - if (ref $attrs->{$key} && $class->has_column($key) - && exists $class->column_info($key)->{_inflate_info}) { - $class->set_inflated_column($key, delete $attrs->{$key}); - } - } - return $class->next::method($attrs, @rest); -} - -=head2 new - -Creates a row in the same way as L, handling -inflation and deflation of columns appropriately. - -=cut - -sub new { - my ($class, $attrs, @rest) = @_; - my $inflated; - foreach my $key (keys %{$attrs||{}}) { - $inflated->{$key} = delete $attrs->{$key} - if ref $attrs->{$key} && $class->has_column($key) - && exists $class->column_info($key)->{_inflate_info}; - } - my $obj = $class->next::method($attrs, @rest); - $obj->{_inflated_column} = $inflated if $inflated; - return $obj; -} - =head1 SEE ALSO =over 4 diff --cc t/68inflate.t index 7afb0e9,2e7c374..ea917f8 --- a/t/68inflate.t +++ b/t/68inflate.t @@@ -10,11 -11,9 +10,11 @@@ my $schema = DBICTest->init_schema() eval { require DateTime }; plan skip_all => "Need DateTime for inflation tests" if $@; - plan tests => 4; + plan tests => 20; -DBICTest::Schema::CD->inflate_column( 'year', +$schema->class('CD') +#DBICTest::Schema::CD +->inflate_column( 'year', { inflate => sub { DateTime->new( year => shift ) }, deflate => sub { shift->year } } );