1 package MooseX::ClassAttribute::Trait::Role;
6 use MooseX::ClassAttribute::Meta::Role::Attribute;
7 use Scalar::Util qw( blessed );
9 use namespace::autoclean;
12 with 'MooseX::ClassAttribute::Trait::Mixin::HasClassAttributes';
14 around add_class_attribute => sub {
18 blessed $_[0] && $_[0]->isa('Class::MOP::Mixin::AttributeCore')
20 : MooseX::ClassAttribute::Meta::Role::Attribute->new(@_)
28 sub _attach_class_attribute {
29 my ( $self, $attribute ) = @_;
31 $attribute->attach_to_role($self);
42 MooseX::ClassAttribute::Trait::Class - A metaclass role for classes with class attributes
46 for my $attr ( HasClassAttributes->meta()->get_all_class_attributes() )
53 This role adds awareness of class attributes to a metaclass object. It
54 provides a set of introspection methods that largely parallel the
55 existing attribute methods, except they operate on class attributes.
59 Every method provided by this role has an analogous method in
60 C<Class::MOP::Class> or C<Moose::Meta::Class> for regular attributes.
62 =head2 $meta->has_class_attribute($name)
64 =head2 $meta->get_class_attribute($name)
66 =head2 $meta->get_class_attribute_list()
68 =head2 $meta->get_class_attribute_map()
70 These methods operate on the current metaclass only.
72 =head2 $meta->add_class_attribute(...)
74 This accepts the same options as the L<Moose::Meta::Attribute>
75 C<add_attribute()> method. However, if an attribute is specified as
76 "required" an error will be thrown.
78 =head2 $meta->remove_class_attribute($name)
80 If the named class attribute exists, it is removed from the class,
81 along with its accessor methods.
83 =head2 $meta->get_all_class_attributes()
85 This method returns a list of attribute objects for the class and all
88 =head2 $meta->find_class_attribute_by_name($name)
90 This method looks at the class and all its parent classes for the
91 named class attribute.
93 =head2 $meta->get_class_attribute_value($name)
95 =head2 $meta->set_class_attribute_value($name, $value)
97 =head2 $meta->set_class_attribute_value($name)
99 =head2 $meta->clear_class_attribute_value($name)
101 These methods operate on the storage for class attribute values, which
102 is attached to the metaclass object.
104 There's really no good reason for you to call these methods unless
105 you're doing some deep hacking. They are named as public methods
106 solely because they are used by other meta roles and classes in this
109 =head2 inline_class_slot_access($name)
111 =head2 inline_get_class_slot_value($name)
113 =head2 inline_set_class_slot_value($name, $val_name)
115 =head2 inline_is_class_slot_initialized($name)
117 =head2 inline_deinitialize_class_slot($name)
119 =head2 inline_weaken_class_slot_value($name)
121 These methods return code snippets for inlining.
123 There's really no good reason for you to call these methods unless
124 you're doing some deep hacking. They are named as public methods
125 solely because they are used by other meta roles and classes in this
130 Dave Rolsky, C<< <autarch@urth.org> >>
134 See L<MooseX::ClassAttribute> for details.
136 =head1 COPYRIGHT & LICENSE
138 Copyright 2007-2008 Dave Rolsky, All Rights Reserved.
140 This program is free software; you can redistribute it and/or modify
141 it under the same terms as Perl itself.