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