bump version to 0.12
[gitmo/MooseX-ClassAttribute.git] / lib / MooseX / ClassAttribute / Trait / Role.pm
CommitLineData
63fcc508 1package MooseX::ClassAttribute::Trait::Role;
88b7f2c8 2
3use strict;
4use warnings;
5
eeee5ccb 6our $VERSION = '0.12';
f77be127 7
88b7f2c8 8use MooseX::ClassAttribute::Meta::Role::Attribute;
9use Scalar::Util qw( blessed );
10
11use namespace::autoclean;
12use Moose::Role;
13
63fcc508 14with 'MooseX::ClassAttribute::Trait::Mixin::HasClassAttributes';
88b7f2c8 15
16around add_class_attribute => sub {
17 my $orig = shift;
18 my $self = shift;
19 my $attr = (
20 blessed $_[0] && $_[0]->isa('Class::MOP::Mixin::AttributeCore')
21 ? $_[0]
22 : MooseX::ClassAttribute::Meta::Role::Attribute->new(@_)
23 );
24
25 $self->$orig($attr);
26
27 return $attr;
28};
29
30sub _attach_class_attribute {
31 my ( $self, $attribute ) = @_;
32
33 $attribute->attach_to_role($self);
34}
35
361;
37
38__END__
39
40=pod
41
42=head1 NAME
43
04b89789 44MooseX::ClassAttribute::Trait::Role - A trait for roles with class attributes
88b7f2c8 45
46=head1 SYNOPSIS
47
48 for my $attr ( HasClassAttributes->meta()->get_all_class_attributes() )
49 {
50 print $attr->name();
51 }
52
53=head1 DESCRIPTION
54
04b89789 55This role adds awareness of class attributes to a role metaclass object. It
56provides a set of introspection methods that largely parallel the existing
57attribute methods, except they operate on class attributes.
88b7f2c8 58
59=head1 METHODS
60
61Every method provided by this role has an analogous method in
62C<Class::MOP::Class> or C<Moose::Meta::Class> for regular attributes.
63
64=head2 $meta->has_class_attribute($name)
65
66=head2 $meta->get_class_attribute($name)
67
68=head2 $meta->get_class_attribute_list()
69
04b89789 70These methods are exactly like their counterparts in
71L<MooseX::ClassAttribute::Trait::Class>.
88b7f2c8 72
73=head2 $meta->add_class_attribute(...)
74
75This accepts the same options as the L<Moose::Meta::Attribute>
76C<add_attribute()> method. However, if an attribute is specified as
77"required" an error will be thrown.
78
79=head2 $meta->remove_class_attribute($name)
80
04b89789 81If the named class attribute exists, it is removed from the role.
88b7f2c8 82
83=head1 AUTHOR
84
85Dave Rolsky, C<< <autarch@urth.org> >>
86
87=head1 BUGS
88
89See L<MooseX::ClassAttribute> for details.
90
91=head1 COPYRIGHT & LICENSE
92
0cee5df4 93Copyright 2007-2010 Dave Rolsky, All Rights Reserved.
88b7f2c8 94
95This program is free software; you can redistribute it and/or modify
96it under the same terms as Perl itself.
97
98=cut