Revision history for MooseX-Storage
* Fix warnings when types do not have a parent type.
+ * allow the use of roles outside MooseX::Storage:: (rjbs)
+ * allow the use of parameterized roles (rjbs)
0.21
* Fix inconsistent dist versions with Perl::Version
$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;
}
}
push @roles, __expand_role(Traits => $trait);
}
- for my $role ( @roles ) {
- Class::MOP::load_class($role) or die "Could not load role ($role)";
- }
-
return @roles;
}
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+BEGIN {
+ local $@;
+ plan skip_all => "MooseX::Storage::Format::JSONpm required for this test"
+ unless eval "require MooseX::Storage::Format::JSONpm; 1";
+}
+
+plan tests => 3;
+use_ok('MooseX::Storage');
+
+{
+
+ package Foo;
+ use Moose;
+ use MooseX::Storage;
+
+ with Storage(format => [ JSONpm => { json_opts => { pretty => 1 } } ] );
+ # with Storage(format => 'JSONpm');
+
+ has 'string' => ( is => 'ro', isa => 'Str' );
+ has 'float' => ( is => 'ro', isa => 'Num' );
+}
+
+{
+ my $foo = Foo->new(
+ string => 'foo',
+ float => 10.5,
+ );
+ isa_ok( $foo, 'Foo' );
+
+ my $json = $foo->freeze;
+
+ isnt(
+ index($json, "\n"),
+ -1,
+ "there are newlines in our JSON, because it is pretty",
+ ) or diag $json;
+
+}
+