line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moose::Meta::Role::Attribute; |
2
|
|
|
|
|
|
|
our $VERSION = '2.2206'; |
3
|
|
|
|
|
|
|
|
4
|
378
|
|
|
378
|
|
2875
|
use strict; |
|
378
|
|
|
|
|
992
|
|
|
378
|
|
|
|
|
11633
|
|
5
|
378
|
|
|
378
|
|
2251
|
use warnings; |
|
378
|
|
|
|
|
1066
|
|
|
378
|
|
|
|
|
14138
|
|
6
|
|
|
|
|
|
|
|
7
|
378
|
|
|
378
|
|
2434
|
use List::Util 1.33 'all'; |
|
378
|
|
|
|
|
11205
|
|
|
378
|
|
|
|
|
28892
|
|
8
|
378
|
|
|
378
|
|
3062
|
use Scalar::Util 'blessed', 'weaken'; |
|
378
|
|
|
|
|
1198
|
|
|
378
|
|
|
|
|
21492
|
|
9
|
|
|
|
|
|
|
|
10
|
378
|
|
|
378
|
|
2904
|
use parent 'Moose::Meta::Mixin::AttributeCore', 'Class::MOP::Object'; |
|
378
|
|
|
|
|
1166
|
|
|
378
|
|
|
|
|
2734
|
|
11
|
|
|
|
|
|
|
|
12
|
378
|
|
|
378
|
|
34250
|
use Moose::Util 'throw_exception'; |
|
378
|
|
|
|
|
1169
|
|
|
378
|
|
|
|
|
3326
|
|
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
|
4459
|
my ( $class, $name, %options ) = @_; |
51
|
|
|
|
|
|
|
|
52
|
729
|
100
|
|
|
|
2358
|
(defined $name) |
53
|
|
|
|
|
|
|
|| throw_exception( MustProvideANameForTheAttribute => params => \%options, |
54
|
|
|
|
|
|
|
class => $class |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
726
|
|
|
|
|
1778
|
my $role = delete $options{_original_role}; |
58
|
|
|
|
|
|
|
|
59
|
726
|
|
|
|
|
7270
|
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
|
1969
|
my ( $self, $role ) = @_; |
69
|
|
|
|
|
|
|
|
70
|
728
|
100
|
66
|
|
|
5931
|
( blessed($role) && $role->isa('Moose::Meta::Role') ) |
71
|
|
|
|
|
|
|
|| throw_exception( MustPassAMooseMetaRoleInstanceOrSubclass => class => $self, |
72
|
|
|
|
|
|
|
role => $role |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
727
|
|
|
|
|
4843
|
weaken( $self->{'associated_role'} = $role ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub original_role { |
79
|
949
|
|
|
949
|
1
|
1757
|
my $self = shift; |
80
|
|
|
|
|
|
|
|
81
|
949
|
|
66
|
|
|
33702
|
return $self->_original_role || $self->associated_role; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub attribute_for_class { |
85
|
657
|
|
|
657
|
1
|
2036
|
my $self = shift; |
86
|
|
|
|
|
|
|
|
87
|
657
|
|
|
|
|
2056
|
my $metaclass = $self->original_role->applied_attribute_metaclass; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
return $metaclass->interpolate_class_and_new( |
90
|
657
|
|
|
|
|
2627
|
$self->name => %{ $self->original_options }, |
|
657
|
|
|
|
|
20094
|
|
91
|
|
|
|
|
|
|
role_attribute => $self, |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub clone { |
96
|
292
|
|
|
292
|
1
|
676
|
my $self = shift; |
97
|
|
|
|
|
|
|
|
98
|
292
|
|
|
|
|
924
|
my $role = $self->original_role; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
return ( ref $self )->new( |
101
|
|
|
|
|
|
|
$self->name, |
102
|
292
|
|
|
|
|
1568
|
%{ $self->original_options }, |
|
292
|
|
|
|
|
9308
|
|
103
|
|
|
|
|
|
|
_original_role => $role, |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub is_same_as { |
108
|
8
|
|
|
8
|
1
|
22
|
my $self = shift; |
109
|
8
|
|
|
|
|
18
|
my $attr = shift; |
110
|
|
|
|
|
|
|
|
111
|
8
|
|
|
|
|
276
|
my $self_options = $self->original_options; |
112
|
8
|
|
|
|
|
260
|
my $other_options = $attr->original_options; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
return 0 |
115
|
8
|
50
|
|
|
|
30
|
unless ( join q{|}, sort keys %{$self_options} ) eq ( join q{|}, sort keys %{$other_options} ); |
|
8
|
|
|
|
|
68
|
|
|
8
|
|
|
|
|
53
|
|
116
|
|
|
|
|
|
|
|
117
|
8
|
|
|
|
|
25
|
for my $key ( keys %{$self_options} ) { |
|
8
|
|
|
|
|
30
|
|
118
|
13
|
50
|
33
|
|
|
98
|
return 0 if defined $self_options->{$key} && ! defined $other_options->{$key}; |
119
|
13
|
50
|
33
|
|
|
49
|
return 0 if ! defined $self_options->{$key} && defined $other_options->{$key}; |
120
|
|
|
|
|
|
|
|
121
|
13
|
50
|
|
13
|
|
87
|
next if all { ! defined } $self_options->{$key}, $other_options->{$key}; |
|
13
|
|
|
|
|
43
|
|
122
|
|
|
|
|
|
|
|
123
|
13
|
100
|
|
|
|
94
|
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.2206 |
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 |