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 {
return $application_class->new(@args)->apply($self, $other);
}
+sub composition_class_roles { }
+
sub combine {
my ($class, @role_specs) = @_;
The return value is a new L<Moose::Meta::Role::Composite> that
represents the combined roles.
+=item B<< $metarole->composition_class_roles >>
+
+When combining multiple roles using C<combine>, this method is used to obtain a
+list of role names to be applied to the L<Moose::Meta::Role::Composite>
+instance returned by C<combine>. 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<Moose::Meta::Class> C<create>
}
my @composition_roles = map {
- $_->has_composition_class_roles
- ? @{ $_->composition_class_roles }
- : ()
+ $_->composition_class_roles
} @{ $params{roles} };
if (@composition_roles) {
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';
+ };
}
{
);
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" );