fixing the traits
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Engine.pm
index 07aeae2..999dbb9 100644 (file)
@@ -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 E<lt>stevan.little@iinteractive.comE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2007 by Infinity Interactive, Inc.
+Copyright 2007-2008 by Infinity Interactive, Inc.
 
 L<http://www.iinteractive.com>