dzilize this distro
[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;
18
19 $role2 = Moose::Util::MetaRole::apply_metaclass_roles(
20 for => $role2,
21 role_metaroles => {
63fcc508 22 role => ['MooseX::ClassAttribute::Trait::Role'],
88b7f2c8 23 application_to_class =>
63fcc508 24 ['MooseX::ClassAttribute::Trait::Application::ToClass'],
88b7f2c8 25 application_to_role =>
63fcc508 26 ['MooseX::ClassAttribute::Trait::Application::ToRole'],
88b7f2c8 27 },
28 );
29
30 foreach my $attribute_name ( $role1->get_class_attribute_list() ) {
31 if ( $role2->has_class_attribute($attribute_name)
32 && $role2->get_class_attribute($attribute_name)
33 != $role1->get_class_attribute($attribute_name) ) {
34
35 require Moose;
36 Moose->throw_error( "Role '"
37 . $role1->name()
38 . "' has encountered a class attribute conflict "
39 . "during composition. This is fatal error and cannot be disambiguated."
40 );
41 }
42 else {
43 $role2->add_class_attribute(
44 $role1->get_class_attribute($attribute_name)->clone() );
45 }
46 }
47}
48
491;
04b89789 50
0d0bf8c3 51# ABSTRACT: A trait that supports applying class attributes to roles
52
04b89789 53__END__
54
55=pod
56
04b89789 57=head1 DESCRIPTION
58
59This trait is used to allow the application of roles containing class
60attributes to roles.
61
04b89789 62=head1 BUGS
63
64See L<MooseX::ClassAttribute> for details.
65
04b89789 66=cut