line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::ClassAttribute::Trait::Mixin::HasClassAttributes; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
4896
|
use strict; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
231
|
|
4
|
8
|
|
|
8
|
|
31
|
use warnings; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
341
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.29'; |
7
|
|
|
|
|
|
|
|
8
|
8
|
|
|
8
|
|
66
|
use namespace::autoclean; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
48
|
|
9
|
8
|
|
|
8
|
|
403
|
use Moose::Role; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
46
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has _class_attribute_map => ( |
12
|
|
|
|
|
|
|
traits => ['Hash'], |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
isa => 'HashRef[Class::MOP::Mixin::AttributeCore]', |
15
|
|
|
|
|
|
|
handles => { |
16
|
|
|
|
|
|
|
'_add_class_attribute' => 'set', |
17
|
|
|
|
|
|
|
'has_class_attribute' => 'exists', |
18
|
|
|
|
|
|
|
'get_class_attribute' => 'get', |
19
|
|
|
|
|
|
|
'_remove_class_attribute' => 'delete', |
20
|
|
|
|
|
|
|
'get_class_attribute_list' => 'keys', |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
default => sub { {} }, |
23
|
|
|
|
|
|
|
init_arg => undef, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# deprecated |
27
|
|
|
|
|
|
|
sub get_class_attribute_map { |
28
|
1
|
|
|
1
|
0
|
522
|
return $_[0]->_class_attribute_map(); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub add_class_attribute { |
32
|
127
|
|
|
127
|
0
|
150
|
my $self = shift; |
33
|
127
|
|
|
|
|
128
|
my $attribute = shift; |
34
|
|
|
|
|
|
|
|
35
|
127
|
50
|
|
|
|
419
|
( $attribute->isa('Class::MOP::Mixin::AttributeCore') ) |
36
|
|
|
|
|
|
|
|| confess |
37
|
|
|
|
|
|
|
"Your attribute must be an instance of Class::MOP::Mixin::AttributeCore (or a subclass)"; |
38
|
|
|
|
|
|
|
|
39
|
127
|
|
|
|
|
330
|
$self->_attach_class_attribute($attribute); |
40
|
|
|
|
|
|
|
|
41
|
127
|
|
|
|
|
1114
|
my $attr_name = $attribute->name; |
42
|
|
|
|
|
|
|
|
43
|
127
|
50
|
|
|
|
5059
|
$self->remove_class_attribute($attr_name) |
44
|
|
|
|
|
|
|
if $self->has_class_attribute($attr_name); |
45
|
|
|
|
|
|
|
|
46
|
127
|
|
|
|
|
140
|
my $order = ( scalar keys %{ $self->_attribute_map } ); |
|
127
|
|
|
|
|
687
|
|
47
|
127
|
|
|
|
|
397
|
$attribute->_set_insertion_order($order); |
48
|
|
|
|
|
|
|
|
49
|
127
|
|
|
|
|
5324
|
$self->_add_class_attribute( $attr_name => $attribute ); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# This method is called to allow for installing accessors. Ideally, we'd |
52
|
|
|
|
|
|
|
# use method overriding, but then the subclass would be responsible for |
53
|
|
|
|
|
|
|
# making the attribute, which would end up with lots of code |
54
|
|
|
|
|
|
|
# duplication. Even more ideally, we'd use augment/inner, but this is |
55
|
|
|
|
|
|
|
# Class::MOP! |
56
|
127
|
100
|
|
|
|
651
|
$self->_post_add_class_attribute($attribute) |
57
|
|
|
|
|
|
|
if $self->can('_post_add_class_attribute'); |
58
|
|
|
|
|
|
|
|
59
|
127
|
|
|
|
|
258
|
return $attribute; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub remove_class_attribute { |
63
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
64
|
1
|
|
|
|
|
1
|
my $name = shift; |
65
|
|
|
|
|
|
|
|
66
|
1
|
50
|
33
|
|
|
7
|
( defined $name && $name ) |
67
|
|
|
|
|
|
|
|| confess 'You must provide an attribute name'; |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
45
|
my $removed_attr = $self->get_class_attribute($name); |
70
|
1
|
50
|
|
|
|
13
|
return unless $removed_attr; |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
42
|
$self->_remove_class_attribute($name); |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
5
|
return $removed_attr; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# ABSTRACT: A mixin trait for things which have class attributes |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=pod |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=encoding UTF-8 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 NAME |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
MooseX::ClassAttribute::Trait::Mixin::HasClassAttributes - A mixin trait for things which have class attributes |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 VERSION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
version 0.29 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 DESCRIPTION |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This trait is like L<Class::MOP::Mixin::HasAttributes>, except that it works |
98
|
|
|
|
|
|
|
with class attributes instead of object attributes. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
See L<MooseX::ClassAttribute::Trait::Class> and |
101
|
|
|
|
|
|
|
L<MooseX::ClassAttribute::Trait::Role> for API details. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 BUGS |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
See L<MooseX::ClassAttribute> for details. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|http://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-ClassAttribute> |
108
|
|
|
|
|
|
|
(or L<bug-moosex-classattribute@rt.cpan.org|mailto:bug-moosex-classattribute@rt.cpan.org>). |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
I am also usually active on IRC as 'drolsky' on C<irc://irc.perl.org>. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHOR |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This software is Copyright (c) 2016 by Dave Rolsky. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This is free software, licensed under: |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |