use strict;
use warnings;
-
+use Scalar::Util qw/blessed/;
use base qw/DBIx::Class::Row/;
sub _deflated_column {
my ($self, $col, $value) = @_;
- return $value unless ref $value; # If it's not an object, don't touch it
+ return $value unless ref $value && blessed($value); # If it's not an object, don't touch it
my $info = $self->column_info($col) or
$self->throw_exception("No column info for $col");
return $value unless exists $info->{_inflate_info};
sub set_inflated_column {
my ($self, $col, $obj) = @_;
$self->set_column($col, $self->_deflated_column($col, $obj));
- return $self->store_inflated_column($col, $obj);
+ if (blessed $obj) {
+ $self->{_inflated_column}{$col} = $obj;
+ } else {
+ delete $self->{_inflated_column}{$col};
+ }
+ return $obj;
}
=head2 store_inflated_column
sub store_inflated_column {
my ($self, $col, $obj) = @_;
- return $self->{_inflated_column}{$col} = $obj;
-}
-
-=head2 get_column
-
-Gets a column value in the same way as L<DBIx::Class::Row/get_column>. 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) = @_;
- use Carp; confess unless ref $self;
- 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);
-}
-
-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))
- unless exists $self->{_column_data}{$col};
- }
+ unless (blessed $obj) {
+ delete $self->{_inflated_column}{$col};
+ $self->store_column($col => $obj);
+ return $obj;
}
- return $self->next::method;
-}
-
-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<DBIx::Class::Row/update>, handling
-inflation and deflation of columns appropriately.
-
-=cut
-
-sub update {
- my ($class, $attrs, @rest) = @_;
- foreach my $key (keys %{$attrs||{}}) {
- if (ref $attrs->{$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<DBIx::Class::Row/new>, 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} && exists $class->column_info($key)->{_inflate_info};
- }
- my $obj = $class->next::method($attrs, @rest);
- $obj->{_inflated_column} = $inflated if $inflated;
- return $obj;
+ delete $self->{_column_data}{$col};
+ return $self->{_inflated_column}{$col} = $obj;
}
=head1 SEE ALSO