line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moose::Meta::Role::Attribute; |
2
|
|
|
|
|
|
|
our $VERSION = '2.2205'; |
3
|
|
|
|
|
|
|
|
4
|
378
|
|
|
378
|
|
2838
|
use strict; |
|
378
|
|
|
|
|
914
|
|
|
378
|
|
|
|
|
11652
|
|
5
|
378
|
|
|
378
|
|
2259
|
use warnings; |
|
378
|
|
|
|
|
1051
|
|
|
378
|
|
|
|
|
13974
|
|
6
|
|
|
|
|
|
|
|
7
|
378
|
|
|
378
|
|
2473
|
use List::Util 1.33 'all'; |
|
378
|
|
|
|
|
11300
|
|
|
378
|
|
|
|
|
28769
|
|
8
|
378
|
|
|
378
|
|
3044
|
use Scalar::Util 'blessed', 'weaken'; |
|
378
|
|
|
|
|
1184
|
|
|
378
|
|
|
|
|
21561
|
|
9
|
|
|
|
|
|
|
|
10
|
378
|
|
|
378
|
|
2862
|
use parent 'Moose::Meta::Mixin::AttributeCore', 'Class::MOP::Object'; |
|
378
|
|
|
|
|
1072
|
|
|
378
|
|
|
|
|
2748
|
|
11
|
|
|
|
|
|
|
|
12
|
378
|
|
|
378
|
|
34246
|
use Moose::Util 'throw_exception'; |
|
378
|
|
|
|
|
1137
|
|
|
378
|
|
|
|
|
3229
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute( |
15
|
|
|
|
|
|
|
'metaclass' => ( |
16
|
|
|
|
|
|
|
reader => 'metaclass', |
17
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
18
|
|
|
|
|
|
|
) |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute( |
22
|
|
|
|
|
|
|
'associated_role' => ( |
23
|
|
|
|
|
|
|
reader => 'associated_role', |
24
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
25
|
|
|
|
|
|
|
) |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute( |
29
|
|
|
|
|
|
|
'_original_role' => ( |
30
|
|
|
|
|
|
|
reader => '_original_role', |
31
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
32
|
|
|
|
|
|
|
) |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute( |
36
|
|
|
|
|
|
|
'is' => ( |
37
|
|
|
|
|
|
|
reader => 'is', |
38
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
39
|
|
|
|
|
|
|
) |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute( |
43
|
|
|
|
|
|
|
'original_options' => ( |
44
|
|
|
|
|
|
|
reader => 'original_options', |
45
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
46
|
|
|
|
|
|
|
) |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new { |
50
|
729
|
|
|
729
|
1
|
4457
|
my ( $class, $name, %options ) = @_; |
51
|
|
|
|
|
|
|
|
52
|
729
|
100
|
|
|
|
2310
|
(defined $name) |
53
|
|
|
|
|
|
|
|| throw_exception( MustProvideANameForTheAttribute => params => \%options, |
54
|
|
|
|
|
|
|
class => $class |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
726
|
|
|
|
|
1738
|
my $role = delete $options{_original_role}; |
58
|
|
|
|
|
|
|
|
59
|
726
|
|
|
|
|
7501
|
return bless { |
60
|
|
|
|
|
|
|
name => $name, |
61
|
|
|
|
|
|
|
original_options => \%options, |
62
|
|
|
|
|
|
|
_original_role => $role, |
63
|
|
|
|
|
|
|
%options, |
64
|
|
|
|
|
|
|
}, $class; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub attach_to_role { |
68
|
728
|
|
|
728
|
1
|
1859
|
my ( $self, $role ) = @_; |
69
|
|
|
|
|
|
|
|
70
|
728
|
100
|
66
|
|
|
6144
|
( blessed($role) && $role->isa('Moose::Meta::Role') ) |
71
|
|
|
|
|
|
|
|| throw_exception( MustPassAMooseMetaRoleInstanceOrSubclass => class => $self, |
72
|
|
|
|
|
|
|
role => $role |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
727
|
|
|
|
|
4902
|
weaken( $self->{'associated_role'} = $role ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub original_role { |
79
|
949
|
|
|
949
|
1
|
1752
|
my $self = shift; |
80
|
|
|
|
|
|
|
|
81
|
949
|
|
66
|
|
|
33901
|
return $self->_original_role || $self->associated_role; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub attribute_for_class { |
85
|
657
|
|
|
657
|
1
|
1983
|
my $self = shift; |
86
|
|
|
|
|
|
|
|
87
|
657
|
|
|
|
|
2039
|
my $metaclass = $self->original_role->applied_attribute_metaclass; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
return $metaclass->interpolate_class_and_new( |
90
|
657
|
|
|
|
|
2739
|
$self->name => %{ $self->original_options }, |
|
657
|
|
|
|
|
20201
|
|
91
|
|
|
|
|
|
|
role_attribute => $self, |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub clone { |
96
|
292
|
|
|
292
|
1
|
663
|
my $self = shift; |
97
|
|
|
|
|
|
|
|
98
|
292
|
|
|
|
|
916
|
my $role = $self->original_role; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
return ( ref $self )->new( |
101
|
|
|
|
|
|
|
$self->name, |
102
|
292
|
|
|
|
|
1638
|
%{ $self->original_options }, |
|
292
|
|
|
|
|
8967
|
|
103
|
|
|
|
|
|
|
_original_role => $role, |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub is_same_as { |
108
|
8
|
|
|
8
|
1
|
19
|
my $self = shift; |
109
|
8
|
|
|
|
|
18
|
my $attr = shift; |
110
|
|
|
|
|
|
|
|
111
|
8
|
|
|
|
|
261
|
my $self_options = $self->original_options; |
112
|
8
|
|
|
|
|
238
|
my $other_options = $attr->original_options; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
return 0 |
115
|
8
|
50
|
|
|
|
33
|
unless ( join q{|}, sort keys %{$self_options} ) eq ( join q{|}, sort keys %{$other_options} ); |
|
8
|
|
|
|
|
62
|
|
|
8
|
|
|
|
|
45
|
|
116
|
|
|
|
|
|
|
|
117
|
8
|
|
|
|
|
34
|
for my $key ( keys %{$self_options} ) { |
|
8
|
|
|
|
|
29
|
|
118
|
14
|
50
|
33
|
|
|
169
|
return 0 if defined $self_options->{$key} && ! defined $other_options->{$key}; |
119
|
14
|
50
|
33
|
|
|
55
|
return 0 if ! defined $self_options->{$key} && defined $other_options->{$key}; |
120
|
|
|
|
|
|
|
|
121
|
14
|
50
|
|
14
|
|
93
|
next if all { ! defined } $self_options->{$key}, $other_options->{$key}; |
|
14
|
|
|
|
|
43
|
|
122
|
|
|
|
|
|
|
|
123
|
14
|
100
|
|
|
|
87
|
return 0 unless $self_options->{$key} eq $other_options->{$key}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
2
|
|
|
|
|
12
|
return 1; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# ABSTRACT: The Moose attribute metaclass for Roles |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=pod |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=encoding UTF-8 |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 NAME |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Moose::Meta::Role::Attribute - The Moose attribute metaclass for Roles |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 VERSION |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
version 2.2205 |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 DESCRIPTION |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
This class implements the API for attributes in roles. Attributes in roles are |
150
|
|
|
|
|
|
|
more like attribute prototypes than full blown attributes. While they are |
151
|
|
|
|
|
|
|
introspectable, they have very little behavior. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 METHODS |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 Moose::Meta::Role::Attribute->new(...) |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This method accepts all the options that would be passed to the constructor |
158
|
|
|
|
|
|
|
for L<Moose::Meta::Attribute>. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 $attr->metaclass |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 $attr->is |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Returns the option as passed to the constructor. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 $attr->associated_role |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Returns the L<Moose::Meta::Role> to which this attribute belongs, if any. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 $attr->original_role |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Returns the L<Moose::Meta::Role> in which this attribute was first |
173
|
|
|
|
|
|
|
defined. This may not be the same as the value of C<associated_role()> for |
174
|
|
|
|
|
|
|
attributes in a composite role, or when one role consumes other roles. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 $attr->original_options |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Returns a hash reference of options passed to the constructor. This is used |
179
|
|
|
|
|
|
|
when creating a L<Moose::Meta::Attribute> object from this object. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 $attr->attach_to_role($role) |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Attaches the attribute to the given L<Moose::Meta::Role>. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 $attr->attribute_for_class($metaclass) |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Given an attribute metaclass name, this method calls C<< |
188
|
|
|
|
|
|
|
$metaclass->interpolate_class_and_new >> to construct an attribute object |
189
|
|
|
|
|
|
|
which can be added to a L<Moose::Meta::Class>. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 $attr->clone |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Creates a new object identical to the object on which the method is called. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 $attr->is_same_as($other_attr) |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Compares two role attributes and returns true if they are identical. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
In addition, this class implements all informational predicates implements by |
200
|
|
|
|
|
|
|
L<Moose::Meta::Attribute> (and L<Class::MOP::Attribute>). |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 BUGS |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
See L<Moose/BUGS> for details on reporting bugs. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 AUTHORS |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=over 4 |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item * |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Stevan Little <stevan@cpan.org> |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item * |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Jesse Luehrs <doy@cpan.org> |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item * |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Shawn M Moore <sartak@cpan.org> |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=item * |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item * |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=item * |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=item * |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Hans Dieter Pearcey <hdp@cpan.org> |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=item * |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Chris Prather <chris@prather.org> |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=item * |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Matt S Trout <mstrout@cpan.org> |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=back |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
This software is copyright (c) 2006 by Infinity Interactive, Inc. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
257
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=cut |