line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::MOP::Mixin::HasAttributes; |
2
|
|
|
|
|
|
|
our $VERSION = '2.2205'; |
3
|
|
|
|
|
|
|
|
4
|
450
|
|
|
450
|
|
3337
|
use strict; |
|
450
|
|
|
|
|
1043
|
|
|
450
|
|
|
|
|
13552
|
|
5
|
450
|
|
|
450
|
|
2341
|
use warnings; |
|
450
|
|
|
|
|
1063
|
|
|
450
|
|
|
|
|
12347
|
|
6
|
|
|
|
|
|
|
|
7
|
450
|
|
|
450
|
|
2628
|
use Scalar::Util 'blessed'; |
|
450
|
|
|
|
|
1009
|
|
|
450
|
|
|
|
|
21442
|
|
8
|
|
|
|
|
|
|
|
9
|
450
|
|
|
450
|
|
2939
|
use parent 'Class::MOP::Mixin'; |
|
450
|
|
|
|
|
1053
|
|
|
450
|
|
|
|
|
3591
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub add_attribute { |
12
|
57513
|
|
|
57513
|
0
|
102123
|
my $self = shift; |
13
|
|
|
|
|
|
|
|
14
|
57513
|
100
|
|
|
|
282185
|
my $attribute |
15
|
|
|
|
|
|
|
= blessed( $_[0] ) ? $_[0] : $self->attribute_metaclass->new(@_); |
16
|
|
|
|
|
|
|
|
17
|
57511
|
100
|
|
|
|
253895
|
( $attribute->isa('Class::MOP::Mixin::AttributeCore') ) |
18
|
|
|
|
|
|
|
|| $self->_throw_exception( AttributeMustBeAnClassMOPMixinAttributeCoreOrSubclass => attribute => $attribute, |
19
|
|
|
|
|
|
|
class_name => $self->name, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
57509
|
|
|
|
|
196576
|
$self->_attach_attribute($attribute); |
23
|
|
|
|
|
|
|
|
24
|
57509
|
|
|
|
|
159243
|
my $attr_name = $attribute->name; |
25
|
|
|
|
|
|
|
|
26
|
57509
|
100
|
|
|
|
130652
|
$self->remove_attribute($attr_name) |
27
|
|
|
|
|
|
|
if $self->has_attribute($attr_name); |
28
|
|
|
|
|
|
|
|
29
|
57509
|
|
|
|
|
101149
|
my $order = ( scalar keys %{ $self->_attribute_map } ); |
|
57509
|
|
|
|
|
151980
|
|
30
|
57509
|
|
|
|
|
185759
|
$attribute->_set_insertion_order($order); |
31
|
|
|
|
|
|
|
|
32
|
57509
|
|
|
|
|
153021
|
$self->_attribute_map->{$attr_name} = $attribute; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# This method is called to allow for installing accessors. Ideally, we'd |
35
|
|
|
|
|
|
|
# use method overriding, but then the subclass would be responsible for |
36
|
|
|
|
|
|
|
# making the attribute, which would end up with lots of code |
37
|
|
|
|
|
|
|
# duplication. Even more ideally, we'd use augment/inner, but this is |
38
|
|
|
|
|
|
|
# Class::MOP! |
39
|
57509
|
100
|
|
|
|
285792
|
$self->_post_add_attribute($attribute) |
40
|
|
|
|
|
|
|
if $self->can('_post_add_attribute'); |
41
|
|
|
|
|
|
|
|
42
|
57487
|
|
|
|
|
861205
|
return $attribute; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub has_attribute { |
46
|
88818
|
|
|
88818
|
0
|
175279
|
my ( $self, $attribute_name ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
88818
|
100
|
|
|
|
178431
|
( defined $attribute_name ) |
49
|
|
|
|
|
|
|
|| $self->_throw_exception( MustDefineAnAttributeName => class_name => $self->name ); |
50
|
|
|
|
|
|
|
|
51
|
88816
|
|
|
|
|
366093
|
exists $self->_attribute_map->{$attribute_name}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub get_attribute { |
55
|
54787
|
|
|
54787
|
0
|
111931
|
my ( $self, $attribute_name ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
54787
|
100
|
|
|
|
111870
|
( defined $attribute_name ) |
58
|
|
|
|
|
|
|
|| $self->_throw_exception( MustDefineAnAttributeName => class_name => $self->name ); |
59
|
|
|
|
|
|
|
|
60
|
54785
|
|
|
|
|
225976
|
return $self->_attribute_map->{$attribute_name}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub remove_attribute { |
64
|
52
|
|
|
52
|
0
|
252
|
my ( $self, $attribute_name ) = @_; |
65
|
|
|
|
|
|
|
|
66
|
52
|
100
|
|
|
|
189
|
( defined $attribute_name ) |
67
|
|
|
|
|
|
|
|| $self->_throw_exception( MustDefineAnAttributeName => class_name => $self->name ); |
68
|
|
|
|
|
|
|
|
69
|
50
|
|
|
|
|
235
|
my $removed_attribute = $self->_attribute_map->{$attribute_name}; |
70
|
49
|
100
|
|
|
|
178
|
return unless defined $removed_attribute; |
71
|
|
|
|
|
|
|
|
72
|
48
|
|
|
|
|
173
|
delete $self->_attribute_map->{$attribute_name}; |
73
|
|
|
|
|
|
|
|
74
|
48
|
|
|
|
|
274
|
return $removed_attribute; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub get_attribute_list { |
78
|
15336
|
|
|
15336
|
0
|
28344
|
my $self = shift; |
79
|
15336
|
|
|
|
|
23082
|
keys %{ $self->_attribute_map }; |
|
15336
|
|
|
|
|
98813
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _restore_metaattributes_from { |
83
|
128
|
|
|
128
|
|
306
|
my $self = shift; |
84
|
128
|
|
|
|
|
731
|
my ($old_meta) = @_; |
85
|
|
|
|
|
|
|
|
86
|
128
|
|
|
|
|
373
|
for my $attr (sort { $a->insertion_order <=> $b->insertion_order } |
|
0
|
|
|
|
|
0
|
|
87
|
23
|
|
|
|
|
71
|
map { $old_meta->get_attribute($_) } |
88
|
|
|
|
|
|
|
$old_meta->get_attribute_list) { |
89
|
23
|
|
|
|
|
138
|
$attr->_make_compatible_with($self->attribute_metaclass); |
90
|
23
|
|
|
|
|
82
|
$self->add_attribute($attr); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# ABSTRACT: Methods for metaclasses which have attributes |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=pod |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=encoding UTF-8 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 NAME |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Class::MOP::Mixin::HasAttributes - Methods for metaclasses which have attributes |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 VERSION |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
version 2.2205 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 DESCRIPTION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This class implements methods for metaclasses which have attributes |
115
|
|
|
|
|
|
|
(L<Class::MOP::Class> and L<Moose::Meta::Role>). See L<Class::MOP::Class> for |
116
|
|
|
|
|
|
|
API details. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHORS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=over 4 |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Stevan Little <stevan@cpan.org> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item * |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Jesse Luehrs <doy@cpan.org> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Shawn M Moore <sartak@cpan.org> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item * |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item * |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Hans Dieter Pearcey <hdp@cpan.org> |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item * |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Chris Prather <chris@prather.org> |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Matt S Trout <mstrout@cpan.org> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=back |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This software is copyright (c) 2006 by Infinity Interactive, Inc. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
169
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |