bump version to 0.11
[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
88412c09 6our $VERSION = '0.11';
f77be127 7
88b7f2c8 8use Moose::Util::MetaRole;
63fcc508 9use MooseX::ClassAttribute::Trait::Application::ToClass;
10use MooseX::ClassAttribute::Trait::Application::ToInstance;
88b7f2c8 11
12use namespace::autoclean;
13use Moose::Role;
14
63fcc508 15with 'MooseX::ClassAttribute::Trait::Application';
88b7f2c8 16
4cbcd0f0 17sub _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
551;
04b89789 56
57__END__
58
59=pod
60
61=head1 NAME
62
63MooseX::ClassAttribute::Trait::Application::ToRole - A trait that supports applying class attributes to roles
64
65=head1 DESCRIPTION
66
67This trait is used to allow the application of roles containing class
68attributes to roles.
69
70=head1 AUTHOR
71
72Dave Rolsky, C<< <autarch@urth.org> >>
73
74=head1 BUGS
75
76See L<MooseX::ClassAttribute> for details.
77
78=head1 COPYRIGHT & LICENSE
79
80Copyright 2007-2008 Dave Rolsky, All Rights Reserved.
81
82This program is free software; you can redistribute it and/or modify
83it under the same terms as Perl itself.
84
85=cut