Bump versions
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage.pm
index dbbdf85..1309e8d 100644 (file)
@@ -5,7 +5,7 @@ use Moose qw(confess);
 use MooseX::Storage::Meta::Attribute::DoNotSerialize;
 use String::RewritePrefix ();
 
-our $VERSION   = '0.21';
+our $VERSION   = '0.25';
 our $AUTHORITY = 'cpan:STEVAN';
 
 sub import {
@@ -19,21 +19,35 @@ sub import {
     $pkg->meta->add_method('Storage' => __PACKAGE__->meta->find_method_by_name('_injected_storage_role_generator'));
 }
 
+my %HORRIBLE_GC_AVOIDANCE_HACK;
+
 sub __expand_role {
     my ($base, $value) = @_;
 
     return unless defined $value;
 
     if (ref $value) {
-        confess "references for roles are not yet handled";
+        my ($class, $param, $no) = @$value;
+        confess "too many args in arrayref role declaration" if defined $no;
+
+        $class = __expand_role($base => $class);
+        Class::MOP::load_class($class);
+
+        my $role = $class->meta->generate_role(parameters => $param);
+
+        $HORRIBLE_GC_AVOIDANCE_HACK{ $role->name } = $role;
+        return $role->name;
     } else {
-        return scalar String::RewritePrefix->rewrite(
+        my $role = scalar String::RewritePrefix->rewrite(
             {
                 ''  => "MooseX::Storage::$base\::",
                 '=' => '',
             },
             $value,
         );
+
+        Class::MOP::load_class($role);
+        return $role;
     }
 }
 
@@ -70,10 +84,6 @@ sub _injected_storage_role_generator {
         push @roles, __expand_role(Traits => $trait);
     }
 
-    for my $role ( @roles ) {
-        Class::MOP::load_class($role) or die "Could not load role ($role)";
-    }
-
     return @roles;
 }
 
@@ -261,6 +271,21 @@ 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
 hand if you like.
 
+By default, options are assumed to be short forms.  For example, this:
+
+  Storage(format => 'JSON');
+
+...will result in looking for MooseX::Storage::Format::JSON.  To use a role
+that is not under the default namespace prefix, start with an equal sign:
+
+  Storage(format => '=My::Private::JSONFormat');
+
+To use a parameterized role (for which, see L<MooseX::Role::Parameterized>) you
+can pass an arrayref of the role name (in short or long form, as above) and its
+parameters:
+
+  Storage(format => [ JSONpm => { json_opts => { pretty => 1 } } ]);
+
 =back
 
 =head1 METHODS