X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FStorage%2FEngine.pm;h=7f3bbb4cce6e6252fd24feda7bfe2c99bffa61f3;hb=ba5bba75ba0c4f8af075e95ce3b00e5376bedf5c;hp=cae240700703d344ff923d4bc081e12a2f7c934d;hpb=95f31c36141c0108605fadf16d9abd9ec8bd63f3;p=gitmo%2FMooseX-Storage.git diff --git a/lib/MooseX/Storage/Engine.pm b/lib/MooseX/Storage/Engine.pm index cae2407..7f3bbb4 100644 --- a/lib/MooseX/Storage/Engine.pm +++ b/lib/MooseX/Storage/Engine.pm @@ -2,6 +2,12 @@ package MooseX::Storage::Engine; use Moose; +our $VERSION = '0.01'; + +# the class marker when +# serializing an object. +our $CLASS_MARKER = '__CLASS__'; + has 'storage' => ( is => 'rw', isa => 'HashRef', @@ -16,7 +22,7 @@ has 'class' => (is => 'rw', isa => 'Str'); sub collapse_object { my $self = shift; $self->map_attributes('collapse_attribute'); - $self->storage->{'__class__'} = $self->object->meta->name; + $self->storage->{$CLASS_MARKER} = $self->object->meta->name; return $self->storage; } @@ -81,9 +87,9 @@ sub map_attributes { my %OBJECT_HANDLERS = ( expand => sub { my $data = shift; - (exists $data->{'__class__'}) + (exists $data->{$CLASS_MARKER}) || confess "Serialized item has no class marker"; - $data->{'__class__'}->unpack($data); + $data->{$CLASS_MARKER}->unpack($data); }, collapse => sub { my $obj = shift; @@ -115,7 +121,7 @@ my %TYPES = ( my $array = shift; foreach my $i (0 .. $#{$array}) { next unless ref($array->[$i]) eq 'HASH' - && exists $array->[$i]->{'__class__'}; + && exists $array->[$i]->{$CLASS_MARKER}; $array->[$i] = $OBJECT_HANDLERS{expand}->($array->[$i]) } $array; @@ -138,7 +144,7 @@ my %TYPES = ( my $hash = shift; foreach my $k (keys %$hash) { next unless ref($hash->{$k}) eq 'HASH' - && exists $hash->{$k}->{'__class__'}; + && exists $hash->{$k}->{$CLASS_MARKER}; $hash->{$k} = $OBJECT_HANDLERS{expand}->($hash->{$k}) } $hash;