Update spelling list
[gitmo/MooseX-ClassAttribute.git] / lib / MooseX / ClassAttribute / Trait / Role.pm
CommitLineData
63fcc508 1package MooseX::ClassAttribute::Trait::Role;
88b7f2c8 2
3use strict;
4use warnings;
5
6use MooseX::ClassAttribute::Meta::Role::Attribute;
7use Scalar::Util qw( blessed );
8
9use namespace::autoclean;
10use Moose::Role;
11
63fcc508 12with 'MooseX::ClassAttribute::Trait::Mixin::HasClassAttributes';
88b7f2c8 13
14around add_class_attribute => sub {
15 my $orig = shift;
16 my $self = shift;
17 my $attr = (
18 blessed $_[0] && $_[0]->isa('Class::MOP::Mixin::AttributeCore')
19 ? $_[0]
20 : MooseX::ClassAttribute::Meta::Role::Attribute->new(@_)
21 );
22
23 $self->$orig($attr);
24
25 return $attr;
26};
27
28sub _attach_class_attribute {
29 my ( $self, $attribute ) = @_;
30
31 $attribute->attach_to_role($self);
32}
33
341;
35
36__END__
37
38=pod
39
40=head1 NAME
41
63fcc508 42MooseX::ClassAttribute::Trait::Class - A metaclass role for classes with class attributes
88b7f2c8 43
44=head1 SYNOPSIS
45
46 for my $attr ( HasClassAttributes->meta()->get_all_class_attributes() )
47 {
48 print $attr->name();
49 }
50
51=head1 DESCRIPTION
52
53This role adds awareness of class attributes to a metaclass object. It
54provides a set of introspection methods that largely parallel the
55existing attribute methods, except they operate on class attributes.
56
57=head1 METHODS
58
59Every method provided by this role has an analogous method in
60C<Class::MOP::Class> or C<Moose::Meta::Class> for regular attributes.
61
62=head2 $meta->has_class_attribute($name)
63
64=head2 $meta->get_class_attribute($name)
65
66=head2 $meta->get_class_attribute_list()
67
68=head2 $meta->get_class_attribute_map()
69
70These methods operate on the current metaclass only.
71
72=head2 $meta->add_class_attribute(...)
73
74This accepts the same options as the L<Moose::Meta::Attribute>
75C<add_attribute()> method. However, if an attribute is specified as
76"required" an error will be thrown.
77
78=head2 $meta->remove_class_attribute($name)
79
80If the named class attribute exists, it is removed from the class,
81along with its accessor methods.
82
83=head2 $meta->get_all_class_attributes()
84
85This method returns a list of attribute objects for the class and all
86its parent classes.
87
88=head2 $meta->find_class_attribute_by_name($name)
89
90This method looks at the class and all its parent classes for the
91named class attribute.
92
93=head2 $meta->get_class_attribute_value($name)
94
95=head2 $meta->set_class_attribute_value($name, $value)
96
97=head2 $meta->set_class_attribute_value($name)
98
99=head2 $meta->clear_class_attribute_value($name)
100
101These methods operate on the storage for class attribute values, which
102is attached to the metaclass object.
103
104There's really no good reason for you to call these methods unless
105you're doing some deep hacking. They are named as public methods
106solely because they are used by other meta roles and classes in this
107distribution.
108
109=head2 inline_class_slot_access($name)
110
111=head2 inline_get_class_slot_value($name)
112
113=head2 inline_set_class_slot_value($name, $val_name)
114
115=head2 inline_is_class_slot_initialized($name)
116
117=head2 inline_deinitialize_class_slot($name)
118
119=head2 inline_weaken_class_slot_value($name)
120
121These methods return code snippets for inlining.
122
123There's really no good reason for you to call these methods unless
124you're doing some deep hacking. They are named as public methods
125solely because they are used by other meta roles and classes in this
126distribution.
127
128=head1 AUTHOR
129
130Dave Rolsky, C<< <autarch@urth.org> >>
131
132=head1 BUGS
133
134See L<MooseX::ClassAttribute> for details.
135
136=head1 COPYRIGHT & LICENSE
137
138Copyright 2007-2008 Dave Rolsky, All Rights Reserved.
139
140This program is free software; you can redistribute it and/or modify
141it under the same terms as Perl itself.
142
143=cut