1 package MooseX::ClassAttribute::Trait::CompositeRole;
6 use Moose::Util::MetaRole;
7 use Moose::Util qw(does_role);
9 use namespace::autoclean;
12 with 'MooseX::ClassAttribute::Trait::Role';
14 sub _merge_class_attributes {
18 foreach my $role ( @{ $self->get_roles } ) {
19 if ( does_role( $role, 'MooseX::ClassAttribute::Trait::Role' ) ) {
21 map { $role->get_class_attribute($_) }
22 $role->get_class_attribute_list;
28 foreach my $attribute (@all_attributes) {
29 my $name = $attribute->name;
30 if ( exists $seen{$name} ) {
31 next if $seen{$name} == $attribute;
34 Moose->throw_error( "Role '"
36 . "' has encountered a class attribute conflict "
37 . "during composition. This is fatal error and cannot be disambiguated."
40 $seen{$name} = $attribute;
42 foreach my $attribute (@all_attributes) {
43 $self->add_class_attribute( $attribute->clone() );
49 around apply_params => sub {
50 my ( $orig, $self, @args ) = @_;
52 my $metarole = Moose::Util::MetaRole::apply_metaroles(
53 for => $self->$orig(@args),
55 application_to_class =>
56 ['MooseX::ClassAttribute::Trait::Application::ToClass'],
57 application_to_role =>
58 ['MooseX::ClassAttribute::Trait::Application::ToRole'],
61 $metarole->_merge_class_attributes;
67 # ABSTRACT: A trait that supports applying multiple roles at once
75 This trait is used to allow the application of multiple roles (one
76 or more of which contain class attributes) to a class or role.
80 See L<MooseX::ClassAttribute> for details.