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