Commit | Line | Data |
63fcc508 |
1 | package MooseX::ClassAttribute::Trait::Application::ToRole; |
88b7f2c8 |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Moose::Util::MetaRole; |
63fcc508 |
7 | use MooseX::ClassAttribute::Trait::Application::ToClass; |
88b7f2c8 |
8 | |
9 | use namespace::autoclean; |
10 | use Moose::Role; |
11 | |
63fcc508 |
12 | with 'MooseX::ClassAttribute::Trait::Application'; |
88b7f2c8 |
13 | |
4cbcd0f0 |
14 | sub _apply_class_attributes { |
88b7f2c8 |
15 | my $self = shift; |
16 | my $role1 = shift; |
17 | my $role2 = shift; |
dbf3ee23 |
18 | $role2 = Moose::Util::MetaRole::apply_metaroles( |
88b7f2c8 |
19 | for => $role2, |
20 | role_metaroles => { |
63fcc508 |
21 | role => ['MooseX::ClassAttribute::Trait::Role'], |
88b7f2c8 |
22 | application_to_class => |
63fcc508 |
23 | ['MooseX::ClassAttribute::Trait::Application::ToClass'], |
88b7f2c8 |
24 | application_to_role => |
63fcc508 |
25 | ['MooseX::ClassAttribute::Trait::Application::ToRole'], |
88b7f2c8 |
26 | }, |
27 | ); |
28 | |
29 | foreach my $attribute_name ( $role1->get_class_attribute_list() ) { |
30 | if ( $role2->has_class_attribute($attribute_name) |
31 | && $role2->get_class_attribute($attribute_name) |
32 | != $role1->get_class_attribute($attribute_name) ) { |
33 | |
34 | require Moose; |
35 | Moose->throw_error( "Role '" |
36 | . $role1->name() |
37 | . "' has encountered a class attribute conflict " |
38 | . "during composition. This is fatal error and cannot be disambiguated." |
39 | ); |
40 | } |
41 | else { |
42 | $role2->add_class_attribute( |
43 | $role1->get_class_attribute($attribute_name)->clone() ); |
44 | } |
45 | } |
46 | } |
47 | |
48 | 1; |
04b89789 |
49 | |
0d0bf8c3 |
50 | # ABSTRACT: A trait that supports applying class attributes to roles |
51 | |
04b89789 |
52 | __END__ |
53 | |
54 | =pod |
55 | |
04b89789 |
56 | =head1 DESCRIPTION |
57 | |
58 | This trait is used to allow the application of roles containing class |
59 | attributes to roles. |
60 | |
04b89789 |
61 | =head1 BUGS |
62 | |
63 | See L<MooseX::ClassAttribute> for details. |
64 | |
04b89789 |
65 | =cut |