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