1 package MooseX::ClassAttribute::Trait::Role;
8 use MooseX::ClassAttribute::Meta::Role::Attribute;
9 use Scalar::Util qw( blessed );
11 use namespace::autoclean;
14 with 'MooseX::ClassAttribute::Trait::Mixin::HasClassAttributes';
16 around add_class_attribute => sub {
20 blessed $_[0] && $_[0]->isa('Class::MOP::Mixin::AttributeCore')
22 : MooseX::ClassAttribute::Meta::Role::Attribute->new(@_)
30 sub _attach_class_attribute {
31 my ( $self, $attribute ) = @_;
33 $attribute->attach_to_role($self);
44 MooseX::ClassAttribute::Trait::Role - A trait for roles with class attributes
48 for my $attr ( HasClassAttributes->meta()->get_all_class_attributes() )
55 This role adds awareness of class attributes to a role metaclass object. It
56 provides a set of introspection methods that largely parallel the existing
57 attribute methods, except they operate on class attributes.
61 Every method provided by this role has an analogous method in
62 C<Class::MOP::Class> or C<Moose::Meta::Class> for regular attributes.
64 =head2 $meta->has_class_attribute($name)
66 =head2 $meta->get_class_attribute($name)
68 =head2 $meta->get_class_attribute_list()
70 These methods are exactly like their counterparts in
71 L<MooseX::ClassAttribute::Trait::Class>.
73 =head2 $meta->add_class_attribute(...)
75 This accepts the same options as the L<Moose::Meta::Attribute>
76 C<add_attribute()> method. However, if an attribute is specified as
77 "required" an error will be thrown.
79 =head2 $meta->remove_class_attribute($name)
81 If the named class attribute exists, it is removed from the role.
85 Dave Rolsky, C<< <autarch@urth.org> >>
89 See L<MooseX::ClassAttribute> for details.
91 =head1 COPYRIGHT & LICENSE
93 Copyright 2007-2010 Dave Rolsky, All Rights Reserved.
95 This program is free software; you can redistribute it and/or modify
96 it under the same terms as Perl itself.