X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FStorage.pm;h=c28194b6377f2c1c8a8ec930fd59b04cabefb5ff;hb=ec9c19230a64659b0550d8bb3c3686f76ce42588;hp=c6101b952f7e0c32f406db5130d40cd2e5462ea8;hpb=b5384d082ce9b7c4fc23c74c4dfc4479ddbe7a67;p=gitmo%2FMooseX-Storage.git diff --git a/lib/MooseX/Storage.pm b/lib/MooseX/Storage.pm index c6101b9..c28194b 100644 --- a/lib/MooseX/Storage.pm +++ b/lib/MooseX/Storage.pm @@ -1,50 +1,98 @@ package MooseX::Storage; +use Moose qw(confess); sub import { my $pkg = caller(); + + return if $pkg eq 'main'; + + ($pkg->can('meta')) + || confess "This package can only be used in Moose based classes"; + $pkg->meta->alias_method('Storage' => sub { my %params = @_; + $params{'base'} ||= 'Basic'; + my @roles = ( - 'MooseX::Storage::Basic' + ('MooseX::Storage::' . $params{'base'}), ); - push @roles => 'MooseX::Storage::Format::' . $params{'format'}; - Class::MOP::load_class($roles[-1]) - || die "Could not load format role (" . $roles[-1] . ") for package ($pkg)"; - + # NOTE: + # you don't have to have a format + # role, this just means you dont + # get anything other than pack/unpack + push @roles => 'MooseX::Storage::Format::' . $params{'format'} + 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 if (exists $params{'io'}) { + (exists $params{'format'}) + || confess "You must specify a format role in order to use an IO role"; push @roles => 'MooseX::Storage::IO::' . $params{'io'}; - Class::MOP::load_class($roles[-1]) - || die "Could not load IO role (" . $roles[-1] . ") for package ($pkg)"; } + Class::MOP::load_class($_) + || die "Could not load role (" . $_ . ") for package ($pkg)" + foreach @roles; + return @roles; }); } -package MooseX::Storage::Basic; -use Moose::Role; +1; -use MooseX::Storage::Engine; +__END__ -sub pack { - my $self = shift; - my $e = MooseX::Storage::Engine->new( object => $self ); - $e->collapse_object; -} +=pod -sub unpack { - my ( $class, $data ) = @_; - my $e = MooseX::Storage::Engine->new( class => $class ); - $class->new( $e->expand_object($data) ); -} +=head1 NAME -1; +MooseX::Storage - A persistence framework for Moose classes -__END__ +=head1 SYNOPSIS -=pod +=head1 DESCRIPTION + +=head1 METHODS + +=over 4 + +=item B + +=back + +=head2 Introspection + +=over 4 + +=item B + +=back + +=head1 BUGS + +All complex software has bugs lurking in it, and this module is no +exception. If you find a bug please either email me, or add the bug +to cpan-RT. + +=head1 AUTHOR + +Chris Prather Echris.prather@iinteractive.comE + +Stevan Little Estevan.little@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2007 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. =cut