package MooseX::Storage::Engine;
use Moose;
-our $VERSION = '0.02';
+our $VERSION = '0.03';
+our $AUTHORITY = 'cpan:STEVAN';
# the class marker when
# serializing an object.
## this is the internal API ...
sub collapse_attribute {
- my ($self, $attr, @args) = @_;
- $self->storage->{$attr->name} = $self->collapse_attribute_value($attr, @args) || return;
+ my ($self, $attr, $options) = @_;
+ my $value = $self->collapse_attribute_value($attr, $options);
+ return if !defined($value);
+ $self->storage->{$attr->name} = $value;
}
sub expand_attribute {
my ($self, $attr, $data, $options) = @_;
- $self->storage->{$attr->name} = $self->expand_attribute_value($attr, $data->{$attr->name}, $options) || return;
+ my $value = $self->expand_attribute_value($attr, $data->{$attr->name}, $options);
+ $self->storage->{$attr->name} = defined $value ? $value : return;
}
sub collapse_attribute_value {
- my ($self, $attr, @args) = @_;
+ my ($self, $attr, $options) = @_;
my $value = $attr->get_value($self->object);
# NOTE:
my $type_converter = $self->find_type_handler($attr->type_constraint);
(defined $type_converter)
|| confess "Cannot convert " . $attr->type_constraint->name;
- $value = $type_converter->{collapse}->($value, @args);
+ $value = $type_converter->{collapse}->($value, $options);
}
return $value;
}
my ( $obj, $options ) = @_;
# ($obj->can('does') && $obj->does('MooseX::Storage::Basic'))
# || confess "Bad object ($obj) does not do MooseX::Storage::Basic role";
+ ($obj->can('pack'))
+ || confess "Object does not have a &pack method, cannot collapse";
$obj->pack(%$options);
},
);
'Int' => { expand => sub { shift }, collapse => sub { shift } },
'Num' => { expand => sub { shift }, collapse => sub { shift } },
'Str' => { expand => sub { shift }, collapse => sub { shift } },
+ 'Bool' => { expand => sub { shift }, collapse => sub { shift } },
# These are the trickier ones, (see notes)
# NOTE:
# Because we are nice guys, we will check
# other real version.
+{ map {
blessed($hash->{$_})
- ? ($_ => $OBJECT_HANDLERS{collapse}->($hash->{$_}), @args)
+ ? ($_ => $OBJECT_HANDLERS{collapse}->($hash->{$_}, @args))
: ($_ => $hash->{$_})
} keys %$hash }
}
=head1 COPYRIGHT AND LICENSE
-Copyright 2007 by Infinity Interactive, Inc.
+Copyright 2007-2008 by Infinity Interactive, Inc.
L<http://www.iinteractive.com>