X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FStorage%2FEngine.pm;h=999dbb90f82e3a475d96ec512b3e6c6b2692dc74;hb=04990d7a1d61ecde1238e6fd224b6b23b462d05a;hp=07aeae284d9ca2ccf63e87e341c2c2f2a04e2b11;hpb=d691721b11887b3ce12fbf5e4b854bf292033a4e;p=gitmo%2FMooseX-Storage.git diff --git a/lib/MooseX/Storage/Engine.pm b/lib/MooseX/Storage/Engine.pm index 07aeae2..999dbb9 100644 --- a/lib/MooseX/Storage/Engine.pm +++ b/lib/MooseX/Storage/Engine.pm @@ -2,7 +2,7 @@ package MooseX::Storage::Engine; use Moose; -our $VERSION = '0.02'; +our $VERSION = '0.05'; our $AUTHORITY = 'cpan:STEVAN'; # the class marker when @@ -56,12 +56,15 @@ sub expand_object { sub collapse_attribute { my ($self, $attr, $options) = @_; - $self->storage->{$attr->name} = $self->collapse_attribute_value($attr, $options) || return; + 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 { @@ -132,7 +135,7 @@ sub map_attributes { $self->$method_name($_, @args) } grep { # Skip our special skip attribute :) - !$_->isa('MooseX::Storage::Meta::Attribute::DoNotSerialize') + !$_->does('MooseX::Storage::Meta::Attribute::Trait::DoNotSerialize') } ($self->object || $self->class)->meta->compute_all_applicable_attributes; } @@ -200,9 +203,13 @@ my %OBJECT_HANDLERS = ( my %TYPES = ( - # These are boring ones, so they use the identity function ... - 'Int' => { expand => sub { shift }, collapse => sub { shift } }, - 'Num' => { expand => sub { shift }, collapse => sub { shift } }, + # NOTE: + # we need to make sure that we properly numify the numbers + # before and after them being futzed with, because some of + # the JSON engines are stupid/annoying/frustrating + 'Int' => { expand => sub { $_[0] + 0 }, collapse => sub { $_[0] + 0 } }, + 'Num' => { expand => sub { $_[0] + 0 }, collapse => sub { $_[0] + 0 } }, + # These are boring ones, so they use the identity function ... 'Str' => { expand => sub { shift }, collapse => sub { shift } }, 'Bool' => { expand => sub { shift }, collapse => sub { shift } }, # These are the trickier ones, (see notes) @@ -419,7 +426,7 @@ Stevan Little Estevan.little@iinteractive.comE =head1 COPYRIGHT AND LICENSE -Copyright 2007 by Infinity Interactive, Inc. +Copyright 2007-2008 by Infinity Interactive, Inc. L