File Coverage

blib/lib/MooseX/ClassAttribute/Trait/Role.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 29 30 96.6


line stmt bran cond sub pod time code
1             package MooseX::ClassAttribute::Trait::Role;
2              
3 8     8   30 use strict;
  8         8  
  8         205  
4 8     8   28 use warnings;
  8         9  
  8         303  
5              
6             our $VERSION = '0.29';
7              
8 8     8   3048 use MooseX::ClassAttribute::Meta::Role::Attribute;
  8         18  
  8         285  
9 8     8   40 use Scalar::Util qw( blessed );
  8         10  
  8         319  
10              
11 8     8   32 use namespace::autoclean;
  8         8  
  8         30  
12 8     8   393 use Moose::Role;
  8         10  
  8         55  
13              
14             with 'MooseX::ClassAttribute::Trait::Mixin::HasClassAttributes';
15              
16             around 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              
30             sub _attach_class_attribute {
31 32     32   32 my ( $self, $attribute ) = @_;
32              
33 32         65 $attribute->attach_to_role($self);
34             }
35              
36             sub composition_class_roles {
37 5     5 0 2019 return 'MooseX::ClassAttribute::Trait::Role::Composite';
38             }
39              
40             1;
41              
42             # ABSTRACT: A trait for roles with class attributes
43              
44             __END__
45              
46             =pod
47              
48             =encoding UTF-8
49              
50             =head1 NAME
51              
52             MooseX::ClassAttribute::Trait::Role - A trait for roles with class attributes
53              
54             =head1 VERSION
55              
56             version 0.29
57              
58             =head1 SYNOPSIS
59              
60             for my $attr ( HasClassAttributes->meta()->get_all_class_attributes() )
61             {
62             print $attr->name();
63             }
64              
65             =head1 DESCRIPTION
66              
67             This role adds awareness of class attributes to a role metaclass object. It
68             provides a set of introspection methods that largely parallel the existing
69             attribute methods, except they operate on class attributes.
70              
71             =head1 METHODS
72              
73             Every method provided by this role has an analogous method in
74             C<Class::MOP::Class> or C<Moose::Meta::Class> for regular attributes.
75              
76             =head2 $meta->has_class_attribute($name)
77              
78             =head2 $meta->get_class_attribute($name)
79              
80             =head2 $meta->get_class_attribute_list()
81              
82             These methods are exactly like their counterparts in
83             L<MooseX::ClassAttribute::Trait::Class>.
84              
85             =head2 $meta->add_class_attribute(...)
86              
87             This accepts the same options as the L<Moose::Meta::Attribute>
88             C<add_attribute()> method. However, if an attribute is specified as
89             "required" an error will be thrown.
90              
91             =head2 $meta->remove_class_attribute($name)
92              
93             If the named class attribute exists, it is removed from the role.
94              
95             =head1 BUGS
96              
97             See L<MooseX::ClassAttribute> for details.
98              
99             Bugs may be submitted through L<the RT bug tracker|http://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-ClassAttribute>
100             (or L<bug-moosex-classattribute@rt.cpan.org|mailto:bug-moosex-classattribute@rt.cpan.org>).
101              
102             I am also usually active on IRC as 'drolsky' on C<irc://irc.perl.org>.
103              
104             =head1 AUTHOR
105              
106             Dave Rolsky <autarch@urth.org>
107              
108             =head1 COPYRIGHT AND LICENCE
109              
110             This software is Copyright (c) 2016 by Dave Rolsky.
111              
112             This is free software, licensed under:
113              
114             The Artistic License 2.0 (GPL Compatible)
115              
116             =cut