X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FStorage.pm;h=7e7d30d5682fe6b168918cd83954aa215e609cf7;hb=cfee09ad9535c50ee223c90fb34afd9667866bcb;hp=6d7f6e3da4a762d7d08833d986ea539fbd52d7a4;hpb=45d9a73cb319d9cd4d3e30d07526d72cb3e11ad2;p=gitmo%2FMooseX-Storage.git diff --git a/lib/MooseX/Storage.pm b/lib/MooseX/Storage.pm index 6d7f6e3..7e7d30d 100644 --- a/lib/MooseX/Storage.pm +++ b/lib/MooseX/Storage.pm @@ -4,7 +4,8 @@ use Moose qw(confess); use MooseX::Storage::Meta::Attribute::DoNotSerialize; -our $VERSION = '0.02'; +our $VERSION = '0.11'; +our $AUTHORITY = 'cpan:STEVAN'; sub import { my $pkg = caller(); @@ -17,7 +18,12 @@ sub import { $pkg->meta->alias_method('Storage' => sub { my %params = @_; - $params{'base'} ||= 'Basic'; + if (exists $params{'base'}) { + $params{'base'} = ('Base::' . $params{'base'}); + } + else { + $params{'base'} = 'Basic'; + } my @roles = ( ('MooseX::Storage::' . $params{'base'}), @@ -31,12 +37,16 @@ sub import { if exists $params{'format'}; # NOTE: - # if you do choose an IO role, then - # you *must* have a format role chosen - # since load/store require freeze/thaw + # many IO roles don't make sense unless + # you have also have a format role chosen + # too, the exception being StorableFile if (exists $params{'io'}) { - (exists $params{'format'}) - || confess "You must specify a format role in order to use an IO role"; + # NOTE: + # we dont need this code anymore, cause + # the role composition will catch it for + # us. This allows the StorableFile to work + #(exists $params{'format'}) + # || confess "You must specify a format role in order to use an IO role"; push @roles => 'MooseX::Storage::IO::' . $params{'io'}; } @@ -64,6 +74,8 @@ MooseX::Storage - An serialization framework for Moose classes use Moose; use MooseX::Storage; + our $VERSION = '0.01'; + with Storage('format' => 'JSON', 'io' => 'File'); has 'x' => (is => 'rw', isa => 'Int'); @@ -77,20 +89,20 @@ MooseX::Storage - An serialization framework for Moose classes ## object in perl data structures # pack the class into a hash - $p->pack(); # { __CLASS__ => 'Point', x => 10, y => 10 } + $p->pack(); # { __CLASS__ => 'Point-0.01', x => 10, y => 10 } # unpack the hash into a class - my $p2 = Point->unpack({ __CLASS__ => 'Point', x => 10, y => 10 }); + my $p2 = Point->unpack({ __CLASS__ => 'Point-0.01', x => 10, y => 10 }); ## methods to freeze/thaw into ## a specified serialization format ## (in this case JSON) # pack the class into a JSON string - $p->freeze(); # { "__CLASS__" : "Point", "x" : 10, "y" : 10 } + $p->freeze(); # { "__CLASS__" : "Point-0.01", "x" : 10, "y" : 10 } # unpack the JSON string into a class - my $p2 = Point->thaw('{ "__CLASS__" : "Point", "x" : 10, "y" : 10 }'); + my $p2 = Point->thaw('{ "__CLASS__" : "Point-0.01", "x" : 10, "y" : 10 }'); ## methods to load/store a class ## on the file system @@ -145,8 +157,8 @@ have it. You can just use C/C instead. The third (io) level is C and C. In this level we are reading and writing data to file/network/database/etc. -This level is also optional, it does however require the C level -to be present (at least the current state does). +This level is also optional, in most cases it does require a C role +to also be used, the expection being the C role. =back @@ -245,9 +257,11 @@ Chris Prather Echris.prather@iinteractive.comE Stevan Little Estevan.little@iinteractive.comE +Yuval Kogman Eyuval.kogman@iinteractive.comE + =head1 COPYRIGHT AND LICENSE -Copyright 2007 by Infinity Interactive, Inc. +Copyright 2007-2008 by Infinity Interactive, Inc. L