X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FStorage%2FDeferred.pm;h=1924490d75deacdebe3ad67ef2d359df6eb8bff6;hb=a99b06bc698f521b77656a1015fb4c572e39dfeb;hp=2326dafefc4850762799be68be7a614d45f5d728;hpb=bf33d7c7a646b2ddc69b7f662e91ebb001f4ff37;p=gitmo%2FMooseX-Storage.git diff --git a/lib/MooseX/Storage/Deferred.pm b/lib/MooseX/Storage/Deferred.pm index 2326daf..1924490 100644 --- a/lib/MooseX/Storage/Deferred.pm +++ b/lib/MooseX/Storage/Deferred.pm @@ -1,23 +1,27 @@ package MooseX::Storage::Deferred; use Moose::Role; -our $VERSION = '0.03'; +our $VERSION = '0.27'; our $AUTHORITY = 'cpan:STEVAN'; with 'MooseX::Storage::Basic'; +sub __get_method { + my ( $self, $basename, $value, $method_name ) = @_; + + my $role = MooseX::Storage->_expand_role($basename => $value)->meta; + my $method = $role->get_method($method_name)->body; +} + sub thaw { my ( $class, $packed, $type, @args ) = @_; (exists $type->{format}) || confess "You must specify a format type to thaw from"; - my $class_to_load = 'MooseX::Storage::Format::' . $type->{format}; - Class::MOP::load_class($class_to_load); + my $code = $class->__get_method(Format => $type->{format} => 'thaw'); - my $method_to_call = $class_to_load . '::thaw'; - - $class->$method_to_call($packed, @args); + $class->$code($packed, @args); } sub freeze { @@ -26,12 +30,9 @@ sub freeze { (exists $type->{format}) || confess "You must specify a format type to freeze into"; - my $class_to_load = 'MooseX::Storage::Format::' . $type->{format}; - Class::MOP::load_class($class_to_load); - - my $method_to_call = $class_to_load . '::freeze'; + my $code = $self->__get_method(Format => $type->{format} => 'freeze'); - $self->$method_to_call(@args); + $self->$code(@args); } sub load { @@ -40,12 +41,9 @@ sub load { (exists $type->{io}) || confess "You must specify an I/O type to load with"; - my $class_to_load = 'MooseX::Storage::IO::' . $type->{io}; - Class::MOP::load_class($class_to_load); + my $code = $class->__get_method(IO => $type->{io} => 'load'); - my $method_to_call = $class_to_load . '::load'; - - $class->$method_to_call($filename, $type, @args); + $class->$code($filename, $type, @args); } sub store { @@ -54,14 +52,13 @@ sub store { (exists $type->{io}) || confess "You must specify an I/O type to store with"; - my $class_to_load = 'MooseX::Storage::IO::' . $type->{io}; - Class::MOP::load_class($class_to_load); - - my $method_to_call = $class_to_load . '::store'; + my $code = $self->__get_method(IO => $type->{io} => 'store'); - $self->$method_to_call($filename, $type, @args); + $self->$code($filename, $type, @args); } +no Moose::Role; + 1; __END__ @@ -96,6 +93,9 @@ MooseX::Storage::Deferred - A role for undecisive programmers # pack the class into a JSON string $p->freeze({ format => 'JSON' }); # { "__CLASS__" : "Point", "x" : 10, "y" : 10 } + # pack the class into a JSON string using parameterized JSONpm role + $p->freeze({ format => [ JSONpm => { json_opts => { pretty => 1 } } ] }); + # unpack the JSON string into a class my $p2 = Point->thaw( '{ "__CLASS__" : "Point", "x" : 10, "y" : 10 }', @@ -117,6 +117,8 @@ SYNOPSIS for more info) =item I +=item I + =item I =item I @@ -133,12 +135,12 @@ SYNOPSIS for more info) =back -B The B I/O option is not supported, -this is because it does not mix well with options who also +B The B I/O option is not supported, +this is because it does not mix well with options who also have a C and C methods like this. It is possible -to probably work around this issue, but I don't currently +to probably work around this issue, but I don't currently have the need for it. If you need this supported, talk to me -and I will see what I can do. +and I will see what I can do. =head1 METHODS