From: Florian Ragwitz Date: Mon, 28 Dec 2009 21:01:06 +0000 (+0100) Subject: Turn composition_class_roles into a plain method. X-Git-Tag: 0.93_01~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4701ceff41cbfffb881d2a6cda1914d13891ac1a;p=gitmo%2FMoose.git Turn composition_class_roles into a plain method. --- diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 9bc4310..e387a05 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -159,12 +159,6 @@ $META->add_attribute( default => 'Moose::Meta::Role::Application::ToInstance', ); -$META->add_attribute( - 'composition_class_roles', - reader => 'composition_class_roles', - predicate => 'has_composition_class_roles', -); - ## some things don't always fit, so they go here ... sub add_attribute { @@ -395,6 +389,8 @@ sub apply { return $application_class->new(@args)->apply($self, $other); } +sub composition_class_roles { } + sub combine { my ($class, @role_specs) = @_; @@ -697,6 +693,14 @@ and C<-alias> keys to control how methods are composed from the role. The return value is a new L that represents the combined roles. +=item B<< $metarole->composition_class_roles >> + +When combining multiple roles using C, this method is used to obtain a +list of role names to be applied to the L +instance returned by C. The default implementation returns an empty +list. Extensions that need to hook into role combination may wrap this method +to return additional role names. + =item B<< Moose::Meta::Role->create($name, %options) >> This method is identical to the L C diff --git a/lib/Moose/Meta/Role/Composite.pm b/lib/Moose/Meta/Role/Composite.pm index ee86b7f..522fc5b 100644 --- a/lib/Moose/Meta/Role/Composite.pm +++ b/lib/Moose/Meta/Role/Composite.pm @@ -48,9 +48,7 @@ sub new { } my @composition_roles = map { - $_->has_composition_class_roles - ? @{ $_->composition_class_roles } - : () + $_->composition_class_roles } @{ $params{roles} }; if (@composition_roles) { diff --git a/t/050_metaclasses/030_metarole_combination.t b/t/050_metaclasses/030_metarole_combination.t index 2b1e928..c9291bc 100644 --- a/t/050_metaclasses/030_metarole_combination.t +++ b/t/050_metaclasses/030_metarole_combination.t @@ -97,9 +97,10 @@ our @applications; package Role::WithCustomApplication; use Moose::Role; - has '+composition_class_roles' => ( - default => ['Role::Composite'], - ); + around composition_class_roles => sub { + my ($orig, $self) = @_; + return $self->$orig, 'Role::Composite'; + }; } { @@ -138,7 +139,7 @@ ok( My::Role::Special->meta->isa('Moose::Meta::Role'), ); ok( My::Role::Special->meta->meta->does_role('Role::WithCustomApplication'), "the role's metaobject has custom applications" ); -is_deeply( My::Role::Special->meta->composition_class_roles, +is_deeply( [My::Role::Special->meta->composition_class_roles], ['Role::Composite'], "the role knows about the specified composition class" );