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);
34 sub composition_class_roles {
35 return 'MooseX::ClassAttribute::Trait::Role::Composite';
40 # ABSTRACT: 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 See L<MooseX::ClassAttribute> for details.