line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::AttributeHelpers::MethodProvider::Array; |
2
|
22
|
|
|
22
|
|
85
|
use Moose::Role; |
|
22
|
|
|
|
|
31
|
|
|
22
|
|
|
|
|
106
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.25'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
with 'MooseX::AttributeHelpers::MethodProvider::List'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub push : method { |
9
|
5
|
|
|
5
|
1
|
27
|
my ($attr, $reader, $writer) = @_; |
10
|
|
|
|
|
|
|
|
11
|
5
|
50
|
33
|
|
|
167
|
if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) { |
12
|
5
|
|
|
|
|
316
|
my $container_type_constraint = $attr->type_constraint->type_parameter; |
13
|
|
|
|
|
|
|
return sub { |
14
|
17
|
|
|
17
|
|
95509
|
my $instance = CORE::shift; |
|
|
|
|
25
|
|
|
|
15
|
|
|
|
|
|
|
$container_type_constraint->check($_) |
16
|
|
|
|
|
|
|
|| confess "Value " . ($_||'undef') . " did not pass container type constraint '$container_type_constraint'" |
17
|
17
|
|
50
|
|
|
82
|
foreach @_; |
|
|
|
66
|
|
|
|
|
18
|
15
|
|
|
|
|
2271
|
CORE::push @{$reader->($instance)} => @_; |
|
15
|
|
|
|
|
105
|
|
19
|
5
|
|
|
|
|
186
|
}; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
else { |
22
|
|
|
|
|
|
|
return sub { |
23
|
0
|
|
|
0
|
|
0
|
my $instance = CORE::shift; |
24
|
0
|
|
|
|
|
0
|
CORE::push @{$reader->($instance)} => @_; |
|
0
|
|
|
|
|
0
|
|
25
|
0
|
|
|
|
|
0
|
}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub pop : method { |
30
|
2
|
|
|
2
|
1
|
14
|
my ($attr, $reader, $writer) = @_; |
31
|
|
|
|
|
|
|
return sub { |
32
|
4
|
|
|
4
|
|
1901
|
CORE::pop @{$reader->($_[0])} |
|
4
|
|
|
|
|
19
|
|
33
|
2
|
|
|
|
|
15
|
}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub unshift : method { |
37
|
4
|
|
|
8
|
1
|
23
|
my ($attr, $reader, $writer) = @_; |
38
|
4
|
50
|
33
|
|
|
132
|
if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) { |
39
|
4
|
|
|
|
|
246
|
my $container_type_constraint = $attr->type_constraint->type_parameter; |
40
|
|
|
|
|
|
|
return sub { |
41
|
6
|
|
|
6
|
|
4324
|
my $instance = CORE::shift; |
42
|
|
|
|
|
|
|
$container_type_constraint->check($_) |
43
|
|
|
|
|
|
|
|| confess "Value " . ($_||'undef') . " did not pass container type constraint '$container_type_constraint'" |
44
|
6
|
|
50
|
|
|
35
|
foreach @_; |
|
|
|
66
|
|
|
|
|
45
|
4
|
|
|
|
|
437
|
CORE::unshift @{$reader->($instance)} => @_; |
|
4
|
|
|
|
|
16
|
|
46
|
4
|
|
|
|
|
173
|
}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
|
|
|
|
|
|
return sub { |
50
|
0
|
|
|
6
|
|
0
|
my $instance = CORE::shift; |
51
|
0
|
|
|
|
|
0
|
CORE::unshift @{$reader->($instance)} => @_; |
|
0
|
|
|
|
|
0
|
|
52
|
0
|
|
|
|
|
0
|
}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub shift : method { |
57
|
2
|
|
|
2
|
1
|
11
|
my ($attr, $reader, $writer) = @_; |
58
|
|
|
|
|
|
|
return sub { |
59
|
4
|
|
|
4
|
|
1793
|
CORE::shift @{$reader->($_[0])} |
|
4
|
|
|
|
|
19
|
|
60
|
2
|
|
|
|
|
11
|
}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub get : method { |
64
|
3
|
|
|
7
|
1
|
18
|
my ($attr, $reader, $writer) = @_; |
65
|
|
|
|
|
|
|
return sub { |
66
|
16
|
|
|
16
|
|
8123
|
$reader->($_[0])->[$_[1]] |
67
|
3
|
|
|
|
|
32
|
}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub set : method { |
71
|
2
|
|
|
18
|
1
|
13
|
my ($attr, $reader, $writer) = @_; |
72
|
2
|
50
|
33
|
|
|
69
|
if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) { |
73
|
2
|
|
|
|
|
125
|
my $container_type_constraint = $attr->type_constraint->type_parameter; |
74
|
|
|
|
|
|
|
return sub { |
75
|
4
|
100
|
50
|
4
|
|
3378
|
($container_type_constraint->check($_[2])) |
76
|
|
|
|
|
|
|
|| confess "Value " . ($_[2]||'undef') . " did not pass container type constraint '$container_type_constraint'"; |
77
|
2
|
|
|
|
|
131
|
$reader->($_[0])->[$_[1]] = $_[2] |
78
|
2
|
|
|
|
|
74
|
}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
else { |
81
|
|
|
|
|
|
|
return sub { |
82
|
0
|
|
|
4
|
|
0
|
$reader->($_[0])->[$_[1]] = $_[2] |
83
|
0
|
|
|
|
|
0
|
}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub accessor : method { |
88
|
2
|
|
|
2
|
1
|
13
|
my ($attr, $reader, $writer) = @_; |
89
|
|
|
|
|
|
|
|
90
|
2
|
50
|
33
|
|
|
71
|
if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) { |
91
|
2
|
|
|
|
|
123
|
my $container_type_constraint = $attr->type_constraint->type_parameter; |
92
|
|
|
|
|
|
|
return sub { |
93
|
8
|
|
|
8
|
|
9108
|
my $self = shift; |
94
|
|
|
|
|
|
|
|
95
|
8
|
100
|
|
|
|
32
|
if (@_ == 1) { # reader |
|
|
100
|
|
|
|
|
|
96
|
2
|
|
|
|
|
11
|
return $reader->($self)->[$_[0]]; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
elsif (@_ == 2) { # writer |
99
|
2
|
50
|
0
|
|
|
8
|
($container_type_constraint->check($_[1])) |
100
|
|
|
|
|
|
|
|| confess "Value " . ($_[1]||'undef') . " did not pass container type constraint '$container_type_constraint'"; |
101
|
2
|
|
|
|
|
126
|
$reader->($self)->[$_[0]] = $_[1]; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else { |
104
|
4
|
|
|
|
|
50
|
confess "One or two arguments expected, not " . @_; |
105
|
|
|
|
|
|
|
} |
106
|
2
|
|
|
|
|
92
|
}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
else { |
109
|
|
|
|
|
|
|
return sub { |
110
|
0
|
|
|
8
|
|
0
|
my $self = shift; |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
0
|
if (@_ == 1) { # reader |
|
|
0
|
|
|
|
|
|
113
|
0
|
|
|
|
|
0
|
return $reader->($self)->[$_[0]]; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
elsif (@_ == 2) { # writer |
116
|
0
|
|
|
|
|
0
|
$reader->($self)->[$_[0]] = $_[1]; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
else { |
119
|
0
|
|
|
|
|
0
|
confess "One or two arguments expected, not " . @_; |
120
|
|
|
|
|
|
|
} |
121
|
0
|
|
|
|
|
0
|
}; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub clear : method { |
126
|
2
|
|
|
2
|
1
|
13
|
my ($attr, $reader, $writer) = @_; |
127
|
|
|
|
|
|
|
return sub { |
128
|
8
|
|
|
8
|
|
3551
|
@{$reader->($_[0])} = () |
|
8
|
|
|
|
|
32
|
|
129
|
2
|
|
|
|
|
24
|
}; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub delete : method { |
133
|
0
|
|
|
8
|
1
|
0
|
my ($attr, $reader, $writer) = @_; |
134
|
|
|
|
|
|
|
return sub { |
135
|
0
|
|
|
0
|
|
0
|
CORE::splice @{$reader->($_[0])}, $_[1], 1; |
|
0
|
|
|
|
|
0
|
|
136
|
|
|
|
|
|
|
} |
137
|
0
|
|
|
|
|
0
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub insert : method { |
140
|
0
|
|
|
0
|
1
|
0
|
my ($attr, $reader, $writer) = @_; |
141
|
0
|
0
|
0
|
|
|
0
|
if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) { |
142
|
0
|
|
|
|
|
0
|
my $container_type_constraint = $attr->type_constraint->type_parameter; |
143
|
|
|
|
|
|
|
return sub { |
144
|
0
|
0
|
0
|
0
|
|
0
|
($container_type_constraint->check($_[2])) |
145
|
|
|
|
|
|
|
|| confess "Value " . ($_[2]||'undef') . " did not pass container type constraint '$container_type_constraint'"; |
146
|
0
|
|
|
|
|
0
|
CORE::splice @{$reader->($_[0])}, $_[1], 0, $_[2]; |
|
0
|
|
|
|
|
0
|
|
147
|
0
|
|
|
|
|
0
|
}; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
else { |
150
|
|
|
|
|
|
|
return sub { |
151
|
0
|
|
|
0
|
|
0
|
CORE::splice @{$reader->($_[0])}, $_[1], 0, $_[2]; |
|
0
|
|
|
|
|
0
|
|
152
|
0
|
|
|
|
|
0
|
}; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub splice : method { |
157
|
2
|
|
|
2
|
1
|
11
|
my ($attr, $reader, $writer) = @_; |
158
|
2
|
50
|
33
|
|
|
67
|
if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) { |
159
|
2
|
|
|
|
|
120
|
my $container_type_constraint = $attr->type_constraint->type_parameter; |
160
|
|
|
|
|
|
|
return sub { |
161
|
2
|
|
|
2
|
|
73
|
my ( $self, $i, $j, @elems ) = @_; |
162
|
|
|
|
|
|
|
($container_type_constraint->check($_)) |
163
|
2
|
0
|
33
|
|
|
10
|
|| confess "Value " . (defined($_) ? $_ : 'undef') . " did not pass container type constraint '$container_type_constraint'" for @elems; |
164
|
2
|
|
|
|
|
102
|
CORE::splice @{$reader->($self)}, $i, $j, @elems; |
|
2
|
|
|
|
|
7
|
|
165
|
2
|
|
|
|
|
78
|
}; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
else { |
168
|
|
|
|
|
|
|
return sub { |
169
|
0
|
|
|
2
|
|
0
|
my ( $self, $i, $j, @elems ) = @_; |
170
|
0
|
|
|
|
|
0
|
CORE::splice @{$reader->($self)}, $i, $j, @elems; |
|
0
|
|
|
|
|
0
|
|
171
|
0
|
|
|
|
|
0
|
}; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub sort_in_place : method { |
176
|
4
|
|
|
4
|
1
|
17
|
my ($attr, $reader, $writer) = @_; |
177
|
|
|
|
|
|
|
return sub { |
178
|
8
|
|
|
8
|
|
3975
|
my ($instance, $predicate) = @_; |
179
|
|
|
|
|
|
|
|
180
|
8
|
100
|
100
|
|
|
58
|
die "Argument must be a code reference" |
181
|
|
|
|
|
|
|
if $predicate && ref $predicate ne 'CODE'; |
182
|
|
|
|
|
|
|
|
183
|
6
|
|
|
|
|
6
|
my @sorted; |
184
|
6
|
100
|
|
|
|
15
|
if ($predicate) { |
185
|
4
|
|
|
|
|
5
|
@sorted = CORE::sort { $predicate->($a, $b) } @{$reader->($instance)}; |
|
18
|
|
|
|
|
123
|
|
|
4
|
|
|
|
|
13
|
|
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
else { |
188
|
2
|
|
|
|
|
2
|
@sorted = CORE::sort @{$reader->($instance)}; |
|
2
|
|
|
|
|
7
|
|
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
6
|
|
|
|
|
66
|
$writer->($instance, \@sorted); |
192
|
4
|
|
|
|
|
25
|
}; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
__END__ |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=pod |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=encoding UTF-8 |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 NAME |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
MooseX::AttributeHelpers::MethodProvider::Array |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 VERSION |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
version 0.25 |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 DESCRIPTION |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
This is a role which provides the method generators for |
214
|
|
|
|
|
|
|
L<MooseX::AttributeHelpers::Collection::Array>. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 METHODS |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=over 4 |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item B<meta> |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=back |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 PROVIDED METHODS |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
This module also consumes the B<List> method providers, to |
227
|
|
|
|
|
|
|
see those provied methods, refer to that documentation. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=over 4 |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item B<get> |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item B<pop> |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item B<push> |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item B<set> |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=item B<shift> |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=item B<unshift> |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=item B<clear> |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=item B<delete> |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=item B<insert> |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=item B<splice> |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=item B<sort_in_place> |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Sorts the array I<in place>, modifying the value of the attribute. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
You can provide an optional subroutine reference to sort with (as you |
256
|
|
|
|
|
|
|
can with the core C<sort> function). However, instead of using C<$a> |
257
|
|
|
|
|
|
|
and C<$b>, you will need to use C<$_[0]> and C<$_[1]> instead. |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=item B<accessor> |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
If passed one argument, returns the value of the requested element. |
262
|
|
|
|
|
|
|
If passed two arguments, sets the value of the requested element. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=back |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=head1 SUPPORT |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-AttributeHelpers> |
269
|
|
|
|
|
|
|
(or L<bug-MooseX-AttributeHelpers@rt.cpan.org|mailto:bug-MooseX-AttributeHelpers@rt.cpan.org>). |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
272
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
275
|
|
|
|
|
|
|
L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>. |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=head1 AUTHOR |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
Stevan Little <stevan@iinteractive.com> |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
This software is copyright (c) 2007 by Stevan Little and Infinity Interactive, Inc. |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
286
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=cut |