X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FStorage.pm;h=549b15ab991872507c358eae460986ed548cb5ee;hb=b430caa3fe1898fd40d743f5ff1347b7df9671f2;hp=e3e2c3ecf5155857b3808115b4cc24a20c235231;hpb=e97396242e8acc8dff6cf3f4f5961ee1fbd8498e;p=gitmo%2FMooseX-Storage.git diff --git a/lib/MooseX/Storage.pm b/lib/MooseX/Storage.pm index e3e2c3e..549b15a 100644 --- a/lib/MooseX/Storage.pm +++ b/lib/MooseX/Storage.pm @@ -1,32 +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 $engine_name = 'MooseX::Storage::' . (shift); - Class::MOP::load_class($engine_name) - || die "Could not load engine ($engine_name) for package ($pkg)"; - return $engine_name; + my %params = @_; + + $params{'base'} ||= 'Basic'; + + my @roles = ( + ('MooseX::Storage::' . $params{'base'}), + ); + + # 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($_) + || die "Could not load role (" . $_ . ") for package ($pkg)" + foreach @roles; + + return @roles; }); } -package MooseX::Storage::Base; -use Moose::Role; +1; -requires 'pack'; -requires 'unpack'; +__END__ -requires 'freeze'; -requires 'thaw'; +=pod -requires 'load'; -requires 'store'; +=head1 NAME -1; +MooseX::Storage - An serialization 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