From: Justin DeVuyst Date: Fri, 17 Apr 2009 04:10:47 +0000 (-0400) Subject: Change method_metaclass to an attr for metarole application. X-Git-Tag: 0.75~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b05518b28ab5b18a5373b5acc655a0fc60c68e87;p=gitmo%2FMoose.git Change method_metaclass to an attr for metarole application. --- diff --git a/Changes b/Changes index 040744f..ec18004 100644 --- a/Changes +++ b/Changes @@ -15,6 +15,10 @@ for, noteworthy changes. - Users can now select a different metaclass with the "-metaclass" option to import, for classes and roles (Sartak) + * Moose::Meta::Role + - Make method_metaclass an attr so can accept a metarole application. + (jdv) + 0.74 Tue, April 7, 2009 * Moose::Meta::Role * Moose::Meta::Method::Destructor diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 2ca0c91..4a5ba5e 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -117,6 +117,12 @@ foreach my $action ( }) if exists $methods->{remove}; } +$META->add_attribute( + 'method_metaclass', + reader => 'method_metaclass', + default => 'Moose::Meta::Role::Method', +); + ## some things don't always fit, so they go here ... sub add_attribute { @@ -286,8 +292,6 @@ sub does_role { ## ------------------------------------------------------------------ ## methods -sub method_metaclass { 'Moose::Meta::Role::Method' } - sub get_method_map { my $self = shift; diff --git a/t/050_metaclasses/015_metarole.t b/t/050_metaclasses/015_metarole.t index cd0c7d2..a7c4c07 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 => 78; +use Test::More tests => 80; use Test::Exception; use Moose::Util::MetaRole; @@ -531,3 +531,50 @@ lives_ok { ExportsMoose->import; } 'import module which loads a role from disk during init_meta'; +{ + package Foo::Meta::Role; + + use Moose::Role; +} +{ + package Foo::Role; + + Moose::Exporter->setup_import_methods( + also => 'Moose::Role', + ); + + sub init_meta { + shift; + my %p = @_; + Moose::Role->init_meta(%p); + return Moose::Util::MetaRole::apply_metaclass_roles( + for_class => $p{for_class}, + method_metaclass_roles => [ 'Foo::Meta::Role', ], + ); + } +} +{ + package Role::Baz; + + Foo::Role->import; + + sub bla {} +} +{ + package My::Class12; + + use Moose; + + with( 'Role::Baz' ); +} +{ + ok( + My::Class12->meta->does_role( 'Role::Baz' ), + 'role applied' + ); + my $method = My::Class12->meta->get_method( 'bla' ); + ok( + $method->meta->does_role( 'Foo::Meta::Role' ), + 'method_metaclass_role applied' + ); +}