From: Florian Ragwitz Date: Sat, 14 Feb 2009 01:10:05 +0000 (+0000) Subject: Allow Moose::Util::MetaRole to apply roles to wrapped_method_metaclass. X-Git-Tag: 0.70~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8286fcd669ad6cf375c2bf7be8563975cb3fb91b;p=gitmo%2FMoose.git Allow Moose::Util::MetaRole to apply roles to wrapped_method_metaclass. --- diff --git a/lib/Moose/Util/MetaRole.pm b/lib/Moose/Util/MetaRole.pm index af786e1..48ca528 100644 --- a/lib/Moose/Util/MetaRole.pm +++ b/lib/Moose/Util/MetaRole.pm @@ -48,6 +48,7 @@ sub _make_new_metaclass { metaclass attribute_metaclass method_metaclass + wrapped_method_metaclass instance_metaclass ); @@ -64,6 +65,7 @@ sub _make_new_metaclass { qw( attribute_metaclass method_metaclass + wrapped_method_metaclass instance_metaclass ); @@ -199,6 +201,8 @@ This specifies the class for which to alter the meta classes. =item * method_metaclass_roles => \@roles +=item * wrapped_method_metaclass_roles => \@roles + =item * instance_metaclass_roles => \@roles =item * constructor_class_roles => \@roles diff --git a/t/050_metaclasses/015_metarole.t b/t/050_metaclasses/015_metarole.t index a1a06c4..cd0c7d2 100644 --- a/t/050_metaclasses/015_metarole.t +++ b/t/050_metaclasses/015_metarole.t @@ -5,7 +5,7 @@ use warnings; use lib 't/lib', 'lib'; -use Test::More tests => 73; +use Test::More tests => 78; use Test::Exception; use Moose::Util::MetaRole; @@ -77,6 +77,26 @@ use Moose::Util::MetaRole; { Moose::Util::MetaRole::apply_metaclass_roles( + for_class => 'My::Class', + wrapped_method_metaclass_roles => ['Role::Foo'], + ); + + ok( My::Class->meta()->wrapped_method_metaclass()->meta()->does_role('Role::Foo'), + q{apply Role::Foo to My::Class->meta()'s wrapped method metaclass} ); + ok( My::Class->meta()->method_metaclass()->meta()->does_role('Role::Foo'), + '... My::Class->meta() still does Role::Foo' ); + ok( My::Class->meta()->meta()->does_role('Role::Foo'), + '... My::Class->meta() still does Role::Foo' ); + ok( My::Class->meta()->attribute_metaclass()->meta()->does_role('Role::Foo'), + q{... My::Class->meta()'s attribute metaclass still does Role::Foo} ); + + My::Class->meta()->add_after_method_modifier( 'bar' => sub { 'bar' } ); + is( My::Class->meta()->get_method('bar')->foo(), 10, + '... call foo() on a wrapped method metaclass object' ); +} + +{ + Moose::Util::MetaRole::apply_metaclass_roles( for_class => 'My::Class', instance_metaclass_roles => ['Role::Foo'], );