From: Chris Weyl Date: Fri, 22 Apr 2011 03:12:19 +0000 (-0700) Subject: Moose::Meta::Role::create should honor "roles" X-Git-Tag: 2.0001~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2b76058a68bf25c4f2c7f62174ef5dc4d1825c2c;p=gitmo%2FMoose.git Moose::Meta::Role::create should honor "roles" Moose::Meta::Role's docs claim create() is "identical" to the create() in Moose::Meta::Class, yet it currently does not honor "roles" if passed to it. This commit fixes that by having Moose::Meta::Role::create() honor a roles named parameter, and adds tests to validate/ensure that behaviour. --- diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 2ee6d1f..33f6347 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -522,7 +522,12 @@ sub create { || confess "You must pass a HASH ref of methods" if exists $options{methods}; + (ref $options{roles} eq 'ARRAY') + || $class->throw_error("You must pass an ARRAY ref of roles", data => $options{roles}) + if exists $options{roles}; + my $package = delete $options{package}; + my $roles = delete $options{roles}; my $attributes = delete $options{attributes}; my $methods = delete $options{methods}; my $meta_name = exists $options{meta_name} @@ -548,6 +553,10 @@ sub create { } } + if ($roles) { + Moose::Util::apply_all_roles($meta, @$roles); + } + return $meta; } diff --git a/t/roles/create_role.t b/t/roles/create_role.t index 204c66d..3963dd1 100644 --- a/t/roles/create_role.t +++ b/t/roles/create_role.t @@ -30,4 +30,11 @@ ok(!$visored->is_worn, "method was consumed"); ok(!$role->is_anon_role, "the role is not anonymous"); +my $composed_role = Moose::Meta::Role->create( + 'MyItem::Role::Equipment2', + roles => [ $role ], +); + +ok($composed_role->does_role('MyItem::Role::Equipment2'), "Role composed into role"); + done_testing;