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);
36 # ABSTRACT: A trait for roles with class attributes
44 for my $attr ( HasClassAttributes->meta()->get_all_class_attributes() )
51 This role adds awareness of class attributes to a role metaclass object. It
52 provides a set of introspection methods that largely parallel the existing
53 attribute methods, except they operate on class attributes.
57 Every method provided by this role has an analogous method in
58 C<Class::MOP::Class> or C<Moose::Meta::Class> for regular attributes.
60 =head2 $meta->has_class_attribute($name)
62 =head2 $meta->get_class_attribute($name)
64 =head2 $meta->get_class_attribute_list()
66 These methods are exactly like their counterparts in
67 L<MooseX::ClassAttribute::Trait::Class>.
69 =head2 $meta->add_class_attribute(...)
71 This accepts the same options as the L<Moose::Meta::Attribute>
72 C<add_attribute()> method. However, if an attribute is specified as
73 "required" an error will be thrown.
75 =head2 $meta->remove_class_attribute($name)
77 If the named class attribute exists, it is removed from the role.
81 See L<MooseX::ClassAttribute> for details.