merged with delegation_bugs branch
[gitmo/MooseX-ClassAttribute.git] / lib / MooseX / ClassAttribute / Trait / Application / ToRole.pm
CommitLineData
63fcc508 1package MooseX::ClassAttribute::Trait::Application::ToRole;
88b7f2c8 2
3use strict;
4use warnings;
5
6use Moose::Util::MetaRole;
63fcc508 7use MooseX::ClassAttribute::Trait::Application::ToClass;
88b7f2c8 8
9use namespace::autoclean;
10use Moose::Role;
11
63fcc508 12with 'MooseX::ClassAttribute::Trait::Application';
88b7f2c8 13
4cbcd0f0 14sub _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
481;
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
58This trait is used to allow the application of roles containing class
59attributes to roles.
60
04b89789 61=head1 BUGS
62
63See L<MooseX::ClassAttribute> for details.
64
04b89789 65=cut