line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moose::Meta::Role::Attribute; |
2
|
|
|
|
|
|
|
our $VERSION = '2.2203'; |
3
|
|
|
|
|
|
|
|
4
|
389
|
|
|
389
|
|
2558
|
use strict; |
|
389
|
|
|
|
|
805
|
|
|
389
|
|
|
|
|
10669
|
|
5
|
389
|
|
|
389
|
|
1845
|
use warnings; |
|
389
|
|
|
|
|
783
|
|
|
389
|
|
|
|
|
11725
|
|
6
|
|
|
|
|
|
|
|
7
|
389
|
|
|
389
|
|
1991
|
use List::Util 1.33 'all'; |
|
389
|
|
|
|
|
8962
|
|
|
389
|
|
|
|
|
23611
|
|
8
|
389
|
|
|
389
|
|
2442
|
use Scalar::Util 'blessed', 'weaken'; |
|
389
|
|
|
|
|
831
|
|
|
389
|
|
|
|
|
18439
|
|
9
|
|
|
|
|
|
|
|
10
|
389
|
|
|
389
|
|
2427
|
use parent 'Moose::Meta::Mixin::AttributeCore', 'Class::MOP::Object'; |
|
389
|
|
|
|
|
868
|
|
|
389
|
|
|
|
|
2611
|
|
11
|
|
|
|
|
|
|
|
12
|
389
|
|
|
389
|
|
30691
|
use Moose::Util 'throw_exception'; |
|
389
|
|
|
|
|
902
|
|
|
389
|
|
|
|
|
2655
|
|
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
|
730
|
|
|
730
|
1
|
3824
|
my ( $class, $name, %options ) = @_; |
51
|
|
|
|
|
|
|
|
52
|
730
|
100
|
|
|
|
2012
|
(defined $name) |
53
|
|
|
|
|
|
|
|| throw_exception( MustProvideANameForTheAttribute => params => \%options, |
54
|
|
|
|
|
|
|
class => $class |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
727
|
|
|
|
|
1485
|
my $role = delete $options{_original_role}; |
58
|
|
|
|
|
|
|
|
59
|
727
|
|
|
|
|
6089
|
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
|
729
|
|
|
729
|
1
|
1558
|
my ( $self, $role ) = @_; |
69
|
|
|
|
|
|
|
|
70
|
729
|
100
|
66
|
|
|
5195
|
( blessed($role) && $role->isa('Moose::Meta::Role') ) |
71
|
|
|
|
|
|
|
|| throw_exception( MustPassAMooseMetaRoleInstanceOrSubclass => class => $self, |
72
|
|
|
|
|
|
|
role => $role |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
728
|
|
|
|
|
4133
|
weaken( $self->{'associated_role'} = $role ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub original_role { |
79
|
950
|
|
|
950
|
1
|
1502
|
my $self = shift; |
80
|
|
|
|
|
|
|
|
81
|
950
|
|
66
|
|
|
29289
|
return $self->_original_role || $self->associated_role; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub attribute_for_class { |
85
|
658
|
|
|
658
|
1
|
1637
|
my $self = shift; |
86
|
|
|
|
|
|
|
|
87
|
658
|
|
|
|
|
1754
|
my $metaclass = $self->original_role->applied_attribute_metaclass; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
return $metaclass->interpolate_class_and_new( |
90
|
658
|
|
|
|
|
2340
|
$self->name => %{ $self->original_options }, |
|
658
|
|
|
|
|
17213
|
|
91
|
|
|
|
|
|
|
role_attribute => $self, |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub clone { |
96
|
292
|
|
|
292
|
1
|
553
|
my $self = shift; |
97
|
|
|
|
|
|
|
|
98
|
292
|
|
|
|
|
805
|
my $role = $self->original_role; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
return ( ref $self )->new( |
101
|
|
|
|
|
|
|
$self->name, |
102
|
292
|
|
|
|
|
1281
|
%{ $self->original_options }, |
|
292
|
|
|
|
|
7531
|
|
103
|
|
|
|
|
|
|
_original_role => $role, |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub is_same_as { |
108
|
8
|
|
|
8
|
1
|
21
|
my $self = shift; |
109
|
8
|
|
|
|
|
28
|
my $attr = shift; |
110
|
|
|
|
|
|
|
|
111
|
8
|
|
|
|
|
287
|
my $self_options = $self->original_options; |
112
|
8
|
|
|
|
|
221
|
my $other_options = $attr->original_options; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
return 0 |
115
|
8
|
50
|
|
|
|
19
|
unless ( join q{|}, sort keys %{$self_options} ) eq ( join q{|}, sort keys %{$other_options} ); |
|
8
|
|
|
|
|
51
|
|
|
8
|
|
|
|
|
45
|
|
116
|
|
|
|
|
|
|
|
117
|
8
|
|
|
|
|
22
|
for my $key ( keys %{$self_options} ) { |
|
8
|
|
|
|
|
22
|
|
118
|
13
|
50
|
33
|
|
|
95
|
return 0 if defined $self_options->{$key} && ! defined $other_options->{$key}; |
119
|
13
|
50
|
33
|
|
|
44
|
return 0 if ! defined $self_options->{$key} && defined $other_options->{$key}; |
120
|
|
|
|
|
|
|
|
121
|
13
|
50
|
|
13
|
|
76
|
next if all { ! defined } $self_options->{$key}, $other_options->{$key}; |
|
13
|
|
|
|
|
37
|
|
122
|
|
|
|
|
|
|
|
123
|
13
|
100
|
|
|
|
86
|
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.2203 |
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 |