X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FStorage.pm;h=b5731d4f8a48de84b3384d4d8261d4470b3fdec6;hb=e44b5f5498b782752d2c91b6796698c86143a2f0;hp=bb851d4d0e740ff84106a6cbaccae140bef701a8;hpb=11d44bb52ca8164d34774985af7b550cfd0c60a0;p=gitmo%2FMooseX-Storage.git diff --git a/lib/MooseX/Storage.pm b/lib/MooseX/Storage.pm index bb851d4..b5731d4 100644 --- a/lib/MooseX/Storage.pm +++ b/lib/MooseX/Storage.pm @@ -5,7 +5,7 @@ use Moose qw(confess); use MooseX::Storage::Meta::Attribute::DoNotSerialize; use String::RewritePrefix (); -our $VERSION = '0.22'; +our $VERSION = '0.32'; our $AUTHORITY = 'cpan:STEVAN'; sub import { @@ -21,16 +21,28 @@ sub import { my %HORRIBLE_GC_AVOIDANCE_HACK; -sub __expand_role { - my ($base, $value) = @_; +sub _rewrite_role_name { + my ($self, $base, $string) = @_; + + my $role_name = scalar String::RewritePrefix->rewrite( + { + '' => "MooseX::Storage::$base\::", + '=' => '', + }, + $string, + ); +} + +sub _expand_role { + my ($self, $base, $value) = @_; return unless defined $value; if (ref $value) { - my ($class, $param, $no) = @$value; - confess "too many args in arrayref role declaration" if defined $no; + confess "too many args in arrayref role declaration" if @$value > 2; + my ($class, $param) = @$value; - $class = __expand_role($base => $class); + $class = $self->_rewrite_role_name($base => $class); Class::MOP::load_class($class); my $role = $class->meta->generate_role(parameters => $param); @@ -38,16 +50,20 @@ sub __expand_role { $HORRIBLE_GC_AVOIDANCE_HACK{ $role->name } = $role; return $role->name; } else { - my $role = scalar String::RewritePrefix->rewrite( - { - '' => "MooseX::Storage::$base\::", - '=' => '', - }, - $value, - ); - - Class::MOP::load_class($role); - return $role; + my $class = $self->_rewrite_role_name($base, $value); + Class::MOP::load_class($class); + + my $role = $class; + + if ($class->meta->isa( + 'MooseX::Role::Parameterized::Meta::Role::Parameterizable' + )) { + $role = $class->meta->generate_role(parameters => undef); + $HORRIBLE_GC_AVOIDANCE_HACK{ $role->name } = $role; + return $role->name; + } + + return $class; } } @@ -56,13 +72,13 @@ sub _injected_storage_role_generator { $params{base} = '=MooseX::Storage::Basic' unless defined $params{base}; - my @roles = __expand_role(Base => $params{base}); + my @roles = __PACKAGE__->_expand_role(Base => $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, __expand_role(Format => $params{format}); + push @roles, __PACKAGE__->_expand_role(Format => $params{format}); # NOTE: # many IO roles don't make sense unless @@ -75,13 +91,13 @@ sub _injected_storage_role_generator { # 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, __expand_role(IO => $params{io}); + push @roles, __PACKAGE__->_expand_role(IO => $params{io}); # Note: # These traits alter the behaviour of the engine, the user can # specify these per role-usage for my $trait ( @{ $params{'traits'} ||= [] } ) { - push @roles, __expand_role(Traits => $trait); + push @roles, __PACKAGE__->_expand_role(Traits => $trait); } return @roles; @@ -171,7 +187,7 @@ class name and each instance attribute is stored. Very simple. This level is not optional, it is the bare minumum that MooseX::Storage provides and all other levels build on top of this. -See L for the fundamental implementation and +See L for the fundamental implementation and options to C and C =item B @@ -190,7 +206,7 @@ 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, in most cases it does require a C role -to also be used, the expection being the C role. +to also be used, the exception being the C role. =back @@ -256,7 +272,7 @@ over anyway. =head1 CAVEAT -This is B a persistence framework, changes to your object after +This is B a persistence framework; changes to your object after you load or store it will not be reflected in the stored class. =head1 EXPORTS @@ -265,7 +281,7 @@ you load or store it will not be reflected in the stored class. =item B -This module will export the C method will can be used to +This module will export the C method and can be used to load a specific set of MooseX::Storage roles to implement a specific combination of features. It is meant to make things easier, but it is by no means the only way. You can still compose your roles by