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::Role - A trait for roles with class attributes
46 for my $attr ( HasClassAttributes->meta()->get_all_class_attributes() )
53 This role adds awareness of class attributes to a role metaclass object. It
54 provides a set of introspection methods that largely parallel the existing
55 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 These methods are exactly like their counterparts in
69 L<MooseX::ClassAttribute::Trait::Class>.
71 =head2 $meta->add_class_attribute(...)
73 This accepts the same options as the L<Moose::Meta::Attribute>
74 C<add_attribute()> method. However, if an attribute is specified as
75 "required" an error will be thrown.
77 =head2 $meta->remove_class_attribute($name)
79 If the named class attribute exists, it is removed from the role.
83 Dave Rolsky, C<< <autarch@urth.org> >>
87 See L<MooseX::ClassAttribute> for details.
89 =head1 COPYRIGHT & LICENSE
91 Copyright 2007-2008 Dave Rolsky, All Rights Reserved.
93 This program is free software; you can redistribute it and/or modify
94 it under the same terms as Perl itself.