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