1 package MooseX::ClassAttribute::Trait::Mixin::HasClassAttributes;
6 use namespace::autoclean;
9 has _class_attribute_map => (
12 isa => 'HashRef[Class::MOP::Mixin::AttributeCore]',
14 '_add_class_attribute' => 'set',
15 'has_class_attribute' => 'exists',
16 'get_class_attribute' => 'get',
17 '_remove_class_attribute' => 'delete',
18 'get_class_attribute_list' => 'keys',
20 default => sub { {} },
25 sub get_class_attribute_map {
26 return $_[0]->_class_attribute_map();
29 sub add_class_attribute {
31 my $attribute = shift;
33 ( $attribute->isa('Class::MOP::Mixin::AttributeCore') )
35 "Your attribute must be an instance of Class::MOP::Mixin::AttributeCore (or a subclass)";
37 $self->_attach_class_attribute($attribute);
39 my $attr_name = $attribute->name;
41 $self->remove_class_attribute($attr_name)
42 if $self->has_class_attribute($attr_name);
44 my $order = ( scalar keys %{ $self->_attribute_map } );
45 $attribute->_set_insertion_order($order);
47 $self->_add_class_attribute( $attr_name => $attribute );
49 # This method is called to allow for installing accessors. Ideally, we'd
50 # use method overriding, but then the subclass would be responsible for
51 # making the attribute, which would end up with lots of code
52 # duplication. Even more ideally, we'd use augment/inner, but this is
54 $self->_post_add_class_attribute($attribute)
55 if $self->can('_post_add_class_attribute');
60 sub remove_class_attribute {
64 ( defined $name && $name )
65 || confess 'You must provide an attribute name';
67 my $removed_attr = $self->get_class_attribute($name);
68 return unless $removed_attr;
70 $self->_remove_class_attribute($name);
83 MooseX::ClassAttribute::Trait::Mixin::HasClassAttributes - A mixin trait for things which have class attributes
87 This trait is like L<Class::MOP::Mixin::HasAttributes>, except that it works
88 with class attributes instead of object attributes.
90 See L<MooseX::ClassAttribute::Trait::Class> and
91 L<MooseX::ClassAttribute::Trait::Role> for API details.
95 Dave Rolsky, C<< <autarch@urth.org> >>
99 See L<MooseX::ClassAttribute> for details.
101 =head1 COPYRIGHT & LICENSE
103 Copyright 2007-2008 Dave Rolsky, All Rights Reserved.
105 This program is free software; you can redistribute it and/or modify
106 it under the same terms as Perl itself.