line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::MOP::Mixin::HasAttributes; |
2
|
|
|
|
|
|
|
our $VERSION = '2.2203'; |
3
|
|
|
|
|
|
|
|
4
|
462
|
|
|
462
|
|
2927
|
use strict; |
|
462
|
|
|
|
|
967
|
|
|
462
|
|
|
|
|
12230
|
|
5
|
462
|
|
|
462
|
|
2093
|
use warnings; |
|
462
|
|
|
|
|
891
|
|
|
462
|
|
|
|
|
11078
|
|
6
|
|
|
|
|
|
|
|
7
|
462
|
|
|
462
|
|
2254
|
use Scalar::Util 'blessed'; |
|
462
|
|
|
|
|
841
|
|
|
462
|
|
|
|
|
19723
|
|
8
|
|
|
|
|
|
|
|
9
|
462
|
|
|
462
|
|
2734
|
use parent 'Class::MOP::Mixin'; |
|
462
|
|
|
|
|
1076
|
|
|
462
|
|
|
|
|
2792
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub add_attribute { |
12
|
59043
|
|
|
59043
|
0
|
91967
|
my $self = shift; |
13
|
|
|
|
|
|
|
|
14
|
59043
|
100
|
|
|
|
252465
|
my $attribute |
15
|
|
|
|
|
|
|
= blessed( $_[0] ) ? $_[0] : $self->attribute_metaclass->new(@_); |
16
|
|
|
|
|
|
|
|
17
|
59041
|
100
|
|
|
|
225813
|
( $attribute->isa('Class::MOP::Mixin::AttributeCore') ) |
18
|
|
|
|
|
|
|
|| $self->_throw_exception( AttributeMustBeAnClassMOPMixinAttributeCoreOrSubclass => attribute => $attribute, |
19
|
|
|
|
|
|
|
class_name => $self->name, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
59039
|
|
|
|
|
178152
|
$self->_attach_attribute($attribute); |
23
|
|
|
|
|
|
|
|
24
|
59039
|
|
|
|
|
142184
|
my $attr_name = $attribute->name; |
25
|
|
|
|
|
|
|
|
26
|
59039
|
100
|
|
|
|
118882
|
$self->remove_attribute($attr_name) |
27
|
|
|
|
|
|
|
if $self->has_attribute($attr_name); |
28
|
|
|
|
|
|
|
|
29
|
59039
|
|
|
|
|
89372
|
my $order = ( scalar keys %{ $self->_attribute_map } ); |
|
59039
|
|
|
|
|
138723
|
|
30
|
59039
|
|
|
|
|
167965
|
$attribute->_set_insertion_order($order); |
31
|
|
|
|
|
|
|
|
32
|
59039
|
|
|
|
|
136717
|
$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
|
59039
|
100
|
|
|
|
254511
|
$self->_post_add_attribute($attribute) |
40
|
|
|
|
|
|
|
if $self->can('_post_add_attribute'); |
41
|
|
|
|
|
|
|
|
42
|
59017
|
|
|
|
|
766682
|
return $attribute; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub has_attribute { |
46
|
90987
|
|
|
90987
|
0
|
157288
|
my ( $self, $attribute_name ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
90987
|
100
|
|
|
|
160389
|
( defined $attribute_name ) |
49
|
|
|
|
|
|
|
|| $self->_throw_exception( MustDefineAnAttributeName => class_name => $self->name ); |
50
|
|
|
|
|
|
|
|
51
|
90985
|
|
|
|
|
324693
|
exists $self->_attribute_map->{$attribute_name}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub get_attribute { |
55
|
56273
|
|
|
56273
|
0
|
101002
|
my ( $self, $attribute_name ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
56273
|
100
|
|
|
|
101222
|
( defined $attribute_name ) |
58
|
|
|
|
|
|
|
|| $self->_throw_exception( MustDefineAnAttributeName => class_name => $self->name ); |
59
|
|
|
|
|
|
|
|
60
|
56271
|
|
|
|
|
200271
|
return $self->_attribute_map->{$attribute_name}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub remove_attribute { |
64
|
52
|
|
|
52
|
0
|
202
|
my ( $self, $attribute_name ) = @_; |
65
|
|
|
|
|
|
|
|
66
|
52
|
100
|
|
|
|
182
|
( defined $attribute_name ) |
67
|
|
|
|
|
|
|
|| $self->_throw_exception( MustDefineAnAttributeName => class_name => $self->name ); |
68
|
|
|
|
|
|
|
|
69
|
50
|
|
|
|
|
208
|
my $removed_attribute = $self->_attribute_map->{$attribute_name}; |
70
|
49
|
100
|
|
|
|
147
|
return unless defined $removed_attribute; |
71
|
|
|
|
|
|
|
|
72
|
48
|
|
|
|
|
156
|
delete $self->_attribute_map->{$attribute_name}; |
73
|
|
|
|
|
|
|
|
74
|
48
|
|
|
|
|
207
|
return $removed_attribute; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub get_attribute_list { |
78
|
15722
|
|
|
15722
|
0
|
26195
|
my $self = shift; |
79
|
15722
|
|
|
|
|
20539
|
keys %{ $self->_attribute_map }; |
|
15722
|
|
|
|
|
77934
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _restore_metaattributes_from { |
83
|
129
|
|
|
129
|
|
266
|
my $self = shift; |
84
|
129
|
|
|
|
|
729
|
my ($old_meta) = @_; |
85
|
|
|
|
|
|
|
|
86
|
129
|
|
|
|
|
346
|
for my $attr (sort { $a->insertion_order <=> $b->insertion_order } |
|
0
|
|
|
|
|
0
|
|
87
|
23
|
|
|
|
|
56
|
map { $old_meta->get_attribute($_) } |
88
|
|
|
|
|
|
|
$old_meta->get_attribute_list) { |
89
|
23
|
|
|
|
|
126
|
$attr->_make_compatible_with($self->attribute_metaclass); |
90
|
23
|
|
|
|
|
64
|
$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.2203 |
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 |