Commit | Line | Data |
63fcc508 |
1 | package MooseX::ClassAttribute::Trait::Application::ToClass; |
88b7f2c8 |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use namespace::autoclean; |
7 | use Moose::Role; |
8 | |
63fcc508 |
9 | with 'MooseX::ClassAttribute::Trait::Application'; |
88b7f2c8 |
10 | |
4cbcd0f0 |
11 | sub _apply_class_attributes { |
88b7f2c8 |
12 | my $self = shift; |
13 | my $role = shift; |
14 | my $class = shift; |
15 | |
16 | $class = Moose::Util::MetaRole::apply_metaclass_roles( |
17 | for => $class, |
18 | class_metaroles => { |
63fcc508 |
19 | class => ['MooseX::ClassAttribute::Trait::Class'], |
88b7f2c8 |
20 | }, |
21 | ); |
22 | |
23 | my $attr_metaclass = $class->attribute_metaclass(); |
24 | |
25 | foreach my $attribute_name ( $role->get_class_attribute_list() ) { |
26 | if ( $class->has_class_attribute($attribute_name) |
27 | && $class->get_class_attribute($attribute_name) |
28 | != $role->get_class_attribute($attribute_name) ) { |
29 | next; |
30 | } |
31 | else { |
32 | $class->add_class_attribute( |
33 | $role->get_class_attribute($attribute_name) |
34 | ->attribute_for_class($attr_metaclass) ); |
35 | } |
36 | } |
37 | } |
38 | |
39 | 1; |
04b89789 |
40 | |
41 | __END__ |
42 | |
43 | =pod |
44 | |
45 | =head1 NAME |
46 | |
47 | MooseX::ClassAttribute::Trait::Application::ToClass - A trait that supports applying class attributes to classes |
48 | |
49 | =head1 DESCRIPTION |
50 | |
51 | This trait is used to allow the application of roles containing class |
52 | attributes to classes. |
53 | |
54 | =head1 AUTHOR |
55 | |
56 | Dave Rolsky, C<< <autarch@urth.org> >> |
57 | |
58 | =head1 BUGS |
59 | |
60 | See L<MooseX::ClassAttribute> for details. |
61 | |
62 | =head1 COPYRIGHT & LICENSE |
63 | |
64 | Copyright 2007-2008 Dave Rolsky, All Rights Reserved. |
65 | |
66 | This program is free software; you can redistribute it and/or modify |
67 | it under the same terms as Perl itself. |
68 | |
69 | =cut |