Commit | Line | Data |
63fcc508 |
1 | package MooseX::ClassAttribute::Trait::Application::ToRole; |
88b7f2c8 |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
f77be127 |
6 | our $VERSION = '0.10'; |
7 | |
88b7f2c8 |
8 | use Moose::Util::MetaRole; |
63fcc508 |
9 | use MooseX::ClassAttribute::Trait::Application::ToClass; |
10 | use MooseX::ClassAttribute::Trait::Application::ToInstance; |
88b7f2c8 |
11 | |
12 | use namespace::autoclean; |
13 | use Moose::Role; |
14 | |
63fcc508 |
15 | with 'MooseX::ClassAttribute::Trait::Application'; |
88b7f2c8 |
16 | |
4cbcd0f0 |
17 | sub _apply_class_attributes { |
88b7f2c8 |
18 | my $self = shift; |
19 | my $role1 = shift; |
20 | my $role2 = shift; |
21 | |
22 | $role2 = Moose::Util::MetaRole::apply_metaclass_roles( |
23 | for => $role2, |
24 | role_metaroles => { |
63fcc508 |
25 | role => ['MooseX::ClassAttribute::Trait::Role'], |
88b7f2c8 |
26 | application_to_class => |
63fcc508 |
27 | ['MooseX::ClassAttribute::Trait::Application::ToClass'], |
88b7f2c8 |
28 | application_to_role => |
63fcc508 |
29 | ['MooseX::ClassAttribute::Trait::Application::ToRole'], |
88b7f2c8 |
30 | application_to_instance => [ |
63fcc508 |
31 | 'MooseX::ClassAttribute::Trait::Application::ToInstance' |
88b7f2c8 |
32 | ], |
33 | }, |
34 | ); |
35 | |
36 | foreach my $attribute_name ( $role1->get_class_attribute_list() ) { |
37 | if ( $role2->has_class_attribute($attribute_name) |
38 | && $role2->get_class_attribute($attribute_name) |
39 | != $role1->get_class_attribute($attribute_name) ) { |
40 | |
41 | require Moose; |
42 | Moose->throw_error( "Role '" |
43 | . $role1->name() |
44 | . "' has encountered a class attribute conflict " |
45 | . "during composition. This is fatal error and cannot be disambiguated." |
46 | ); |
47 | } |
48 | else { |
49 | $role2->add_class_attribute( |
50 | $role1->get_class_attribute($attribute_name)->clone() ); |
51 | } |
52 | } |
53 | } |
54 | |
55 | 1; |
04b89789 |
56 | |
57 | __END__ |
58 | |
59 | =pod |
60 | |
61 | =head1 NAME |
62 | |
63 | MooseX::ClassAttribute::Trait::Application::ToRole - A trait that supports applying class attributes to roles |
64 | |
65 | =head1 DESCRIPTION |
66 | |
67 | This trait is used to allow the application of roles containing class |
68 | attributes to roles. |
69 | |
70 | =head1 AUTHOR |
71 | |
72 | Dave Rolsky, C<< <autarch@urth.org> >> |
73 | |
74 | =head1 BUGS |
75 | |
76 | See L<MooseX::ClassAttribute> for details. |
77 | |
78 | =head1 COPYRIGHT & LICENSE |
79 | |
80 | Copyright 2007-2008 Dave Rolsky, All Rights Reserved. |
81 | |
82 | This program is free software; you can redistribute it and/or modify |
83 | it under the same terms as Perl itself. |
84 | |
85 | =cut |