line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# This file was autogenerated. |
2
|
3
|
|
|
3
|
|
229068
|
use 5.008001; |
|
3
|
|
|
|
|
15
|
|
3
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
64
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
90
|
|
5
|
3
|
|
|
3
|
|
16
|
no warnings qw( void once ); |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
81
|
|
6
|
3
|
|
|
3
|
|
385
|
use Hydrogen (); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
288
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Hydrogen::ArrayRef; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
11
|
|
|
|
|
|
|
our $VERSION = '0.018'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Hydrogen::ArrayRef - a standard library for arrayrefs |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
This documentation is for Hydrogen::ArrayRef 0.018, |
20
|
|
|
|
|
|
|
which is based on Sub::HandlesVia::HandlerLibrary::Array 0.046. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 FUNCTIONS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Each function expects a reference to an array as its first argument. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
3
|
|
|
|
|
35
|
use Exporter::Shiny qw( |
31
|
|
|
|
|
|
|
accessor |
32
|
|
|
|
|
|
|
all |
33
|
|
|
|
|
|
|
all_true |
34
|
|
|
|
|
|
|
any |
35
|
|
|
|
|
|
|
apply |
36
|
|
|
|
|
|
|
clear |
37
|
|
|
|
|
|
|
count |
38
|
|
|
|
|
|
|
delete |
39
|
|
|
|
|
|
|
elements |
40
|
|
|
|
|
|
|
first |
41
|
|
|
|
|
|
|
first_index |
42
|
|
|
|
|
|
|
flatten |
43
|
|
|
|
|
|
|
flatten_deep |
44
|
|
|
|
|
|
|
for_each |
45
|
|
|
|
|
|
|
for_each_pair |
46
|
|
|
|
|
|
|
get |
47
|
|
|
|
|
|
|
grep |
48
|
|
|
|
|
|
|
head |
49
|
|
|
|
|
|
|
insert |
50
|
|
|
|
|
|
|
is_empty |
51
|
|
|
|
|
|
|
join |
52
|
|
|
|
|
|
|
map |
53
|
|
|
|
|
|
|
max |
54
|
|
|
|
|
|
|
maxstr |
55
|
|
|
|
|
|
|
min |
56
|
|
|
|
|
|
|
minstr |
57
|
|
|
|
|
|
|
natatime |
58
|
|
|
|
|
|
|
not_all_true |
59
|
|
|
|
|
|
|
pairfirst |
60
|
|
|
|
|
|
|
pairgrep |
61
|
|
|
|
|
|
|
pairkeys |
62
|
|
|
|
|
|
|
pairmap |
63
|
|
|
|
|
|
|
pairs |
64
|
|
|
|
|
|
|
pairvalues |
65
|
|
|
|
|
|
|
pick_random |
66
|
|
|
|
|
|
|
pop |
67
|
|
|
|
|
|
|
print |
68
|
|
|
|
|
|
|
product |
69
|
|
|
|
|
|
|
push |
70
|
|
|
|
|
|
|
reduce |
71
|
|
|
|
|
|
|
reductions |
72
|
|
|
|
|
|
|
reset |
73
|
|
|
|
|
|
|
reverse |
74
|
|
|
|
|
|
|
sample |
75
|
|
|
|
|
|
|
set |
76
|
|
|
|
|
|
|
shallow_clone |
77
|
|
|
|
|
|
|
shift |
78
|
|
|
|
|
|
|
shuffle |
79
|
|
|
|
|
|
|
shuffle_in_place |
80
|
|
|
|
|
|
|
sort |
81
|
|
|
|
|
|
|
sort_in_place |
82
|
|
|
|
|
|
|
splice |
83
|
|
|
|
|
|
|
sum |
84
|
|
|
|
|
|
|
tail |
85
|
|
|
|
|
|
|
uniq |
86
|
|
|
|
|
|
|
uniq_in_place |
87
|
|
|
|
|
|
|
uniqnum |
88
|
|
|
|
|
|
|
uniqnum_in_place |
89
|
|
|
|
|
|
|
uniqstr |
90
|
|
|
|
|
|
|
uniqstr_in_place |
91
|
|
|
|
|
|
|
unshift |
92
|
3
|
|
|
3
|
|
19
|
); |
|
3
|
|
|
|
|
8
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 C<< accessor( $arrayref, $index, $value? ) >> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Additional arguments: B<< Int >>, B<< Optional[Any] >>. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Acts like C if given just an index, or C if given an index and value. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
{ |
103
|
|
|
|
|
|
|
my $__signature; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub accessor { |
106
|
2
|
|
|
2
|
1
|
9085
|
my $__REF__ = \$_[0]; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
109
|
|
|
|
|
|
|
$__signature ||= sub { |
110
|
2
|
|
|
2
|
|
8
|
my ( %tmp, $tmp ); |
111
|
|
|
|
|
|
|
|
112
|
2
|
50
|
33
|
|
|
12
|
@_ >= 2 && @_ <= 3 |
113
|
|
|
|
|
|
|
or Hydrogen::croak( |
114
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
115
|
|
|
|
|
|
|
"accessor", scalar(@_), "expected exactly 2 parameters" ); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
118
|
2
|
50
|
|
|
|
17
|
( ref( $_[0] ) eq 'ARRAY' ) |
119
|
|
|
|
|
|
|
or Hydrogen::croak( |
120
|
|
|
|
|
|
|
"Type check failed in signature for accessor: %s should be %s", |
121
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" |
122
|
|
|
|
|
|
|
); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Parameter $_[1] (type: Int) |
125
|
|
|
|
|
|
|
( |
126
|
2
|
50
|
|
|
|
7
|
do { |
127
|
2
|
|
|
|
|
4
|
my $tmp = $_[1]; |
128
|
2
|
50
|
33
|
|
|
38
|
defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
) |
131
|
|
|
|
|
|
|
or Hydrogen::croak( |
132
|
|
|
|
|
|
|
"Type check failed in signature for accessor: %s should be %s", |
133
|
|
|
|
|
|
|
"\$_[1]", "Int" |
134
|
|
|
|
|
|
|
); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# Parameter $_[2] (type: Optional[Any]) |
137
|
2
|
100
|
|
|
|
12
|
$#_ >= 2 |
138
|
|
|
|
|
|
|
or return (@_); |
139
|
1
|
|
|
|
|
2
|
( !!1 ) |
140
|
|
|
|
|
|
|
or Hydrogen::croak( |
141
|
|
|
|
|
|
|
"Type check failed in signature for accessor: %s should be %s", |
142
|
|
|
|
|
|
|
"\$_[2]", "Optional[Any]" |
143
|
|
|
|
|
|
|
); |
144
|
|
|
|
|
|
|
|
145
|
1
|
|
|
|
|
4
|
(@_); |
146
|
2
|
|
100
|
|
|
15
|
}; |
147
|
2
|
|
|
|
|
49
|
@_ = &$__signature; |
148
|
2
|
|
|
|
|
3
|
1; |
149
|
2
|
100
|
|
|
|
19
|
( ( @_ - 1 ) == 1 ) |
150
|
|
|
|
|
|
|
? ($$__REF__)->[ $_[1] ] |
151
|
|
|
|
|
|
|
: ( ($$__REF__)->[ $_[1] ] = $_[2] ); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 C<< all( $arrayref ) >> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
All elements in the array, in list context. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub all { |
162
|
1
|
|
|
1
|
1
|
4249
|
my $__REF__ = \$_[0]; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
165
|
1
|
50
|
|
|
|
5
|
@_ == 1 |
166
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for all; usage: " |
167
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::all( \$arrayref )" ); |
168
|
1
|
|
|
|
|
2
|
@{$$__REF__}; |
|
1
|
|
|
|
|
4
|
|
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 C<< all_true( $arrayref, $coderef ) >> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Additional arguments: B<< CodeRef >>. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Like C<< List::Util::all() >>. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub all_true { |
180
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
183
|
0
|
|
|
|
|
0
|
@_ = do { |
184
|
0
|
|
|
|
|
0
|
my ( %tmp, $tmp ); |
185
|
|
|
|
|
|
|
|
186
|
0
|
0
|
|
|
|
0
|
@_ == 2 |
187
|
|
|
|
|
|
|
or Hydrogen::croak( |
188
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
189
|
|
|
|
|
|
|
"all_true", scalar(@_), "expected exactly 2 parameters" ); |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
192
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
193
|
|
|
|
|
|
|
or Hydrogen::croak( |
194
|
|
|
|
|
|
|
"Type check failed in signature for all_true: %s should be %s", |
195
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# Parameter $_[1] (type: CodeRef) |
198
|
0
|
0
|
|
|
|
0
|
( ref( $_[1] ) eq 'CODE' ) |
199
|
|
|
|
|
|
|
or Hydrogen::croak( |
200
|
|
|
|
|
|
|
"Type check failed in signature for all_true: %s should be %s", |
201
|
|
|
|
|
|
|
"\$_[1]", "CodeRef" ); |
202
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
0
|
(@_); |
204
|
|
|
|
|
|
|
}; |
205
|
0
|
|
|
|
|
0
|
&List::Util::all( $_[1], @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 C<< any( $arrayref, $coderef ) >> |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Additional arguments: B<< CodeRef >>. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Like C<< List::Util::any() >>. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub any { |
217
|
1
|
|
|
1
|
1
|
6085
|
my $__REF__ = \$_[0]; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
220
|
1
|
|
|
|
|
4
|
@_ = do { |
221
|
1
|
|
|
|
|
3
|
my ( %tmp, $tmp ); |
222
|
|
|
|
|
|
|
|
223
|
1
|
50
|
|
|
|
4
|
@_ == 2 |
224
|
|
|
|
|
|
|
or Hydrogen::croak( |
225
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
226
|
|
|
|
|
|
|
"any", scalar(@_), "expected exactly 2 parameters" ); |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
229
|
1
|
50
|
|
|
|
4
|
( ref( $_[0] ) eq 'ARRAY' ) |
230
|
|
|
|
|
|
|
or Hydrogen::croak( |
231
|
|
|
|
|
|
|
"Type check failed in signature for any: %s should be %s", |
232
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
# Parameter $_[1] (type: CodeRef) |
235
|
1
|
50
|
|
|
|
4
|
( ref( $_[1] ) eq 'CODE' ) |
236
|
|
|
|
|
|
|
or Hydrogen::croak( |
237
|
|
|
|
|
|
|
"Type check failed in signature for any: %s should be %s", |
238
|
|
|
|
|
|
|
"\$_[1]", "CodeRef" ); |
239
|
|
|
|
|
|
|
|
240
|
1
|
|
|
|
|
3
|
(@_); |
241
|
|
|
|
|
|
|
}; |
242
|
1
|
|
|
|
|
2
|
&List::Util::any( $_[1], @{$$__REF__} ); |
|
1
|
|
|
|
|
5
|
|
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head2 C<< apply( $arrayref, $coderef ) >> |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Additional arguments: B<< CodeRef >>. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Executes the coderef (which should modify C<< $_ >>) against each element of the array; returns the resulting array in list context. |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=cut |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
sub apply { |
254
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
257
|
0
|
|
|
|
|
0
|
@_ = do { |
258
|
0
|
|
|
|
|
0
|
my ( %tmp, $tmp ); |
259
|
|
|
|
|
|
|
|
260
|
0
|
0
|
|
|
|
0
|
@_ == 2 |
261
|
|
|
|
|
|
|
or Hydrogen::croak( |
262
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
263
|
|
|
|
|
|
|
"apply", scalar(@_), "expected exactly 2 parameters" ); |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
266
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
267
|
|
|
|
|
|
|
or Hydrogen::croak( |
268
|
|
|
|
|
|
|
"Type check failed in signature for apply: %s should be %s", |
269
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
# Parameter $_[1] (type: CodeRef) |
272
|
0
|
0
|
|
|
|
0
|
( ref( $_[1] ) eq 'CODE' ) |
273
|
|
|
|
|
|
|
or Hydrogen::croak( |
274
|
|
|
|
|
|
|
"Type check failed in signature for apply: %s should be %s", |
275
|
|
|
|
|
|
|
"\$_[1]", "CodeRef" ); |
276
|
|
|
|
|
|
|
|
277
|
0
|
|
|
|
|
0
|
(@_); |
278
|
|
|
|
|
|
|
}; |
279
|
0
|
|
|
|
|
0
|
my @shv_tmp = @{$$__REF__}; |
|
0
|
|
|
|
|
0
|
|
280
|
0
|
|
|
|
|
0
|
&{ $_[1] } foreach @shv_tmp; |
|
0
|
|
|
|
|
0
|
|
281
|
0
|
0
|
|
|
|
0
|
wantarray ? @shv_tmp : $shv_tmp[-1]; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head2 C<< clear( $arrayref ) >> |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
Empties the array. |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=cut |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
sub clear { |
291
|
1
|
|
|
1
|
1
|
5754
|
my $__REF__ = \$_[0]; |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
294
|
1
|
50
|
|
|
|
5
|
@_ == 1 |
295
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for clear; usage: " |
296
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::clear( \$arrayref )" ); |
297
|
1
|
|
|
|
|
2
|
1; |
298
|
1
|
|
|
|
|
2
|
@{$$__REF__} = (); |
|
1
|
|
|
|
|
3
|
|
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=head2 C<< count( $arrayref ) >> |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
The number of elements in the referenced array. |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=cut |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
sub count { |
308
|
1
|
|
|
1
|
1
|
3466
|
my $__REF__ = \$_[0]; |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
311
|
1
|
50
|
|
|
|
5
|
@_ == 1 |
312
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for count; usage: " |
313
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::count( \$arrayref )" ); |
314
|
1
|
|
|
|
|
2
|
scalar( @{$$__REF__} ); |
|
1
|
|
|
|
|
4
|
|
315
|
|
|
|
|
|
|
} |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=head2 C<< delete( $arrayref, $index ) >> |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
Additional arguments: B<< Int >>. |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
Removes the indexed element from the array and returns it. Elements after it will be "moved up". |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=cut |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
sub delete { |
326
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
329
|
0
|
|
|
|
|
0
|
@_ = do { |
330
|
0
|
|
|
|
|
0
|
my ( %tmp, $tmp ); |
331
|
|
|
|
|
|
|
|
332
|
0
|
0
|
|
|
|
0
|
@_ == 2 |
333
|
|
|
|
|
|
|
or Hydrogen::croak( |
334
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
335
|
|
|
|
|
|
|
"delete", scalar(@_), "expected exactly 2 parameters" ); |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
338
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
339
|
|
|
|
|
|
|
or Hydrogen::croak( |
340
|
|
|
|
|
|
|
"Type check failed in signature for delete: %s should be %s", |
341
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
# Parameter $_[1] (type: Int) |
344
|
|
|
|
|
|
|
( |
345
|
0
|
0
|
|
|
|
0
|
do { |
346
|
0
|
|
|
|
|
0
|
my $tmp = $_[1]; |
347
|
0
|
0
|
0
|
|
|
0
|
defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/; |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
) |
350
|
|
|
|
|
|
|
or Hydrogen::croak( |
351
|
|
|
|
|
|
|
"Type check failed in signature for delete: %s should be %s", |
352
|
|
|
|
|
|
|
"\$_[1]", "Int" ); |
353
|
|
|
|
|
|
|
|
354
|
0
|
|
|
|
|
0
|
(@_); |
355
|
|
|
|
|
|
|
}; |
356
|
0
|
|
|
|
|
0
|
1; |
357
|
0
|
|
|
|
|
0
|
splice( @{$$__REF__}, $_[1], 1 ); |
|
0
|
|
|
|
|
0
|
|
358
|
|
|
|
|
|
|
} |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
=head2 C<< elements( $arrayref ) >> |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
All elements in the array, in list context. (Essentially the same as C.) |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
=cut |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
sub elements { |
367
|
1
|
|
|
1
|
1
|
5820
|
my $__REF__ = \$_[0]; |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
370
|
1
|
50
|
|
|
|
5
|
@_ == 1 |
371
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for elements; usage: " |
372
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::elements( \$arrayref )" ); |
373
|
1
|
|
|
|
|
2
|
@{$$__REF__}; |
|
1
|
|
|
|
|
3
|
|
374
|
|
|
|
|
|
|
} |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
=head2 C<< first( $arrayref, $coderef ) >> |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
Additional arguments: B<< CodeRef >>. |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
Like C<< List::Util::first() >>. |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
=cut |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
sub first { |
385
|
1
|
|
|
1
|
1
|
3830
|
my $__REF__ = \$_[0]; |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
388
|
1
|
|
|
|
|
3
|
@_ = do { |
389
|
1
|
|
|
|
|
3
|
my ( %tmp, $tmp ); |
390
|
|
|
|
|
|
|
|
391
|
1
|
50
|
|
|
|
5
|
@_ == 2 |
392
|
|
|
|
|
|
|
or Hydrogen::croak( |
393
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
394
|
|
|
|
|
|
|
"first", scalar(@_), "expected exactly 2 parameters" ); |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
397
|
1
|
50
|
|
|
|
5
|
( ref( $_[0] ) eq 'ARRAY' ) |
398
|
|
|
|
|
|
|
or Hydrogen::croak( |
399
|
|
|
|
|
|
|
"Type check failed in signature for first: %s should be %s", |
400
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
# Parameter $_[1] (type: CodeRef) |
403
|
1
|
50
|
|
|
|
4
|
( ref( $_[1] ) eq 'CODE' ) |
404
|
|
|
|
|
|
|
or Hydrogen::croak( |
405
|
|
|
|
|
|
|
"Type check failed in signature for first: %s should be %s", |
406
|
|
|
|
|
|
|
"\$_[1]", "CodeRef" ); |
407
|
|
|
|
|
|
|
|
408
|
1
|
|
|
|
|
5
|
(@_); |
409
|
|
|
|
|
|
|
}; |
410
|
1
|
|
|
|
|
3
|
&List::Util::first( $_[1], @{$$__REF__} ); |
|
1
|
|
|
|
|
5
|
|
411
|
|
|
|
|
|
|
} |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
=head2 C<< first_index( $arrayref, $coderef ) >> |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
Additional arguments: B<< CodeRef >>. |
416
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
Like C<< List::MoreUtils::first_index() >>. |
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
=cut |
420
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
sub first_index { |
422
|
1
|
|
|
1
|
1
|
3514
|
my $__REF__ = \$_[0]; |
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
425
|
1
|
|
|
|
|
3
|
@_ = do { |
426
|
1
|
|
|
|
|
2
|
my ( %tmp, $tmp ); |
427
|
|
|
|
|
|
|
|
428
|
1
|
50
|
|
|
|
5
|
@_ == 2 |
429
|
|
|
|
|
|
|
or Hydrogen::croak( |
430
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
431
|
|
|
|
|
|
|
"first_index", scalar(@_), "expected exactly 2 parameters" ); |
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
434
|
1
|
50
|
|
|
|
3
|
( ref( $_[0] ) eq 'ARRAY' ) |
435
|
|
|
|
|
|
|
or Hydrogen::croak( |
436
|
|
|
|
|
|
|
"Type check failed in signature for first_index: %s should be %s", |
437
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
# Parameter $_[1] (type: CodeRef) |
440
|
1
|
50
|
|
|
|
4
|
( ref( $_[1] ) eq 'CODE' ) |
441
|
|
|
|
|
|
|
or Hydrogen::croak( |
442
|
|
|
|
|
|
|
"Type check failed in signature for first_index: %s should be %s", |
443
|
|
|
|
|
|
|
"\$_[1]", "CodeRef" ); |
444
|
|
|
|
|
|
|
|
445
|
1
|
|
|
|
|
4
|
(@_); |
446
|
|
|
|
|
|
|
}; |
447
|
1
|
|
|
|
|
3
|
for my $i ( 0 .. $#{$$__REF__} ) { |
|
1
|
|
|
|
|
4
|
|
448
|
3
|
|
|
|
|
17
|
local *_ = \$$__REF__->[$i]; |
449
|
3
|
100
|
|
|
|
8
|
return $i if $_[1]->($_); |
450
|
|
|
|
|
|
|
}; |
451
|
0
|
|
|
|
|
0
|
return -1; |
452
|
|
|
|
|
|
|
} |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
=head2 C<< flatten( $arrayref ) >> |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
All elements in the array, in list context. (Essentially the same as C.) |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
=cut |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
sub flatten { |
461
|
1
|
|
|
1
|
1
|
3527
|
my $__REF__ = \$_[0]; |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
464
|
1
|
50
|
|
|
|
5
|
@_ == 1 |
465
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for flatten; usage: " |
466
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::flatten( \$arrayref )" ); |
467
|
1
|
|
|
|
|
2
|
@{$$__REF__}; |
|
1
|
|
|
|
|
4
|
|
468
|
|
|
|
|
|
|
} |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
=head2 C<< flatten_deep( $arrayref, $depth? ) >> |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
Additional arguments: B<< Optional[Int] >>. |
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
Flattens the arrayref into a list, including any nested arrayrefs. (Has the potential to loop infinitely.) |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
=cut |
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
{ |
479
|
|
|
|
|
|
|
my $__signature; |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
sub flatten_deep { |
482
|
2
|
|
|
2
|
1
|
3817
|
my $__REF__ = \$_[0]; |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
485
|
|
|
|
|
|
|
$__signature ||= sub { |
486
|
2
|
|
|
2
|
|
3
|
my ( %tmp, $tmp ); |
487
|
|
|
|
|
|
|
|
488
|
2
|
50
|
33
|
|
|
10
|
@_ >= 1 && @_ <= 2 |
489
|
|
|
|
|
|
|
or Hydrogen::croak( |
490
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
491
|
|
|
|
|
|
|
"flatten_deep", scalar(@_), "expected exactly 1 parameters" ); |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
494
|
2
|
50
|
|
|
|
8
|
( ref( $_[0] ) eq 'ARRAY' ) |
495
|
|
|
|
|
|
|
or Hydrogen::croak( |
496
|
|
|
|
|
|
|
"Type check failed in signature for flatten_deep: %s should be %s", |
497
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" |
498
|
|
|
|
|
|
|
); |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
# Parameter $_[1] (type: Optional[Int]) |
501
|
2
|
100
|
|
|
|
8
|
$#_ >= 1 |
502
|
|
|
|
|
|
|
or return (@_); |
503
|
|
|
|
|
|
|
( |
504
|
1
|
50
|
|
|
|
3
|
do { |
505
|
1
|
|
|
|
|
3
|
my $tmp = $_[1]; |
506
|
1
|
50
|
33
|
|
|
27
|
defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/; |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
) |
509
|
|
|
|
|
|
|
or Hydrogen::croak( |
510
|
|
|
|
|
|
|
"Type check failed in signature for flatten_deep: %s should be %s", |
511
|
|
|
|
|
|
|
"\$_[1]", "Optional[Int]" |
512
|
|
|
|
|
|
|
); |
513
|
|
|
|
|
|
|
|
514
|
1
|
|
|
|
|
6
|
(@_); |
515
|
2
|
|
100
|
|
|
11
|
}; |
516
|
2
|
|
|
|
|
5
|
@_ = &$__signature; |
517
|
2
|
|
|
|
|
4
|
my $shv_fd; |
518
|
|
|
|
|
|
|
$shv_fd = sub { |
519
|
5
|
|
|
5
|
|
10
|
my $d = pop; |
520
|
5
|
100
|
|
|
|
12
|
--$d if defined $d; |
521
|
5
|
100
|
100
|
|
|
54
|
map ref() eq "ARRAY" |
|
|
100
|
|
|
|
|
|
522
|
|
|
|
|
|
|
? ( defined $d && $d < 0 ) |
523
|
|
|
|
|
|
|
? $_ |
524
|
|
|
|
|
|
|
: $shv_fd->( @$_, $d ) |
525
|
|
|
|
|
|
|
: $_, @_; |
526
|
2
|
|
|
|
|
11
|
}; |
527
|
2
|
|
|
|
|
5
|
$shv_fd->( @{$$__REF__}, $_[1] ); |
|
2
|
|
|
|
|
7
|
|
528
|
|
|
|
|
|
|
} |
529
|
|
|
|
|
|
|
} |
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
=head2 C<< for_each( $arrayref, $coderef ) >> |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
Additional arguments: B<< CodeRef >>. |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
Function which executes the coderef on each element of the array. The coderef will be passed two values: the element and its index. |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
=cut |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
sub for_each { |
540
|
1
|
|
|
1
|
1
|
5613
|
my $__REF__ = \$_[0]; |
541
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
543
|
1
|
|
|
|
|
3
|
@_ = do { |
544
|
1
|
|
|
|
|
3
|
my ( %tmp, $tmp ); |
545
|
|
|
|
|
|
|
|
546
|
1
|
50
|
|
|
|
6
|
@_ == 2 |
547
|
|
|
|
|
|
|
or Hydrogen::croak( |
548
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
549
|
|
|
|
|
|
|
"for_each", scalar(@_), "expected exactly 2 parameters" ); |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
552
|
1
|
50
|
|
|
|
9
|
( ref( $_[0] ) eq 'ARRAY' ) |
553
|
|
|
|
|
|
|
or Hydrogen::croak( |
554
|
|
|
|
|
|
|
"Type check failed in signature for for_each: %s should be %s", |
555
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
# Parameter $_[1] (type: CodeRef) |
558
|
1
|
50
|
|
|
|
7
|
( ref( $_[1] ) eq 'CODE' ) |
559
|
|
|
|
|
|
|
or Hydrogen::croak( |
560
|
|
|
|
|
|
|
"Type check failed in signature for for_each: %s should be %s", |
561
|
|
|
|
|
|
|
"\$_[1]", "CodeRef" ); |
562
|
|
|
|
|
|
|
|
563
|
1
|
|
|
|
|
5
|
(@_); |
564
|
|
|
|
|
|
|
}; |
565
|
1
|
|
|
|
|
3
|
foreach my $shv_index ( 0 .. $#{$$__REF__} ) { |
|
1
|
|
|
|
|
7
|
|
566
|
3
|
|
|
|
|
1234
|
&{ $_[1] }( ($$__REF__)->[$shv_index], $shv_index ); |
|
3
|
|
|
|
|
17
|
|
567
|
|
|
|
|
|
|
}; |
568
|
1
|
|
|
|
|
593
|
$__REF__; |
569
|
|
|
|
|
|
|
} |
570
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
=head2 C<< for_each_pair( $arrayref, $coderef ) >> |
572
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
Additional arguments: B<< CodeRef >>. |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
Function which executes the coderef on each pair of elements in the array. The coderef will be passed the two elements. |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
=cut |
578
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
sub for_each_pair { |
580
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
583
|
0
|
|
|
|
|
0
|
@_ = do { |
584
|
0
|
|
|
|
|
0
|
my ( %tmp, $tmp ); |
585
|
|
|
|
|
|
|
|
586
|
0
|
0
|
|
|
|
0
|
@_ == 2 |
587
|
|
|
|
|
|
|
or Hydrogen::croak( |
588
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
589
|
|
|
|
|
|
|
"for_each_pair", scalar(@_), "expected exactly 2 parameters" ); |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
592
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
593
|
|
|
|
|
|
|
or Hydrogen::croak( |
594
|
|
|
|
|
|
|
"Type check failed in signature for for_each_pair: %s should be %s", |
595
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" |
596
|
|
|
|
|
|
|
); |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
# Parameter $_[1] (type: CodeRef) |
599
|
0
|
0
|
|
|
|
0
|
( ref( $_[1] ) eq 'CODE' ) |
600
|
|
|
|
|
|
|
or Hydrogen::croak( |
601
|
|
|
|
|
|
|
"Type check failed in signature for for_each_pair: %s should be %s", |
602
|
|
|
|
|
|
|
"\$_[1]", "CodeRef" |
603
|
|
|
|
|
|
|
); |
604
|
|
|
|
|
|
|
|
605
|
0
|
|
|
|
|
0
|
(@_); |
606
|
|
|
|
|
|
|
}; |
607
|
0
|
|
|
|
|
0
|
for ( my $shv_index = 0 ; $shv_index < @{$$__REF__} ; $shv_index += 2 ) { |
|
0
|
|
|
|
|
0
|
|
608
|
0
|
|
|
|
|
0
|
&{ $_[1] }( ($$__REF__)->[$shv_index], ($$__REF__)->[ $shv_index + 1 ] ); |
|
0
|
|
|
|
|
0
|
|
609
|
|
|
|
|
|
|
}; |
610
|
0
|
|
|
|
|
0
|
$__REF__; |
611
|
|
|
|
|
|
|
} |
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
=head2 C<< get( $arrayref, $index ) >> |
614
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
Additional arguments: B<< Int >>. |
616
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
Returns a single element from the array by index. |
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
=cut |
620
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
sub get { |
622
|
3
|
|
|
3
|
1
|
7502
|
my $__REF__ = \$_[0]; |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
625
|
3
|
|
|
|
|
44
|
@_ = do { |
626
|
3
|
|
|
|
|
8
|
my ( %tmp, $tmp ); |
627
|
|
|
|
|
|
|
|
628
|
3
|
50
|
|
|
|
29
|
@_ == 2 |
629
|
|
|
|
|
|
|
or Hydrogen::croak( |
630
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
631
|
|
|
|
|
|
|
"get", scalar(@_), "expected exactly 2 parameters" ); |
632
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
634
|
3
|
50
|
|
|
|
16
|
( ref( $_[0] ) eq 'ARRAY' ) |
635
|
|
|
|
|
|
|
or Hydrogen::croak( |
636
|
|
|
|
|
|
|
"Type check failed in signature for get: %s should be %s", |
637
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
638
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
# Parameter $_[1] (type: Int) |
640
|
|
|
|
|
|
|
( |
641
|
3
|
50
|
|
|
|
6
|
do { |
642
|
3
|
|
|
|
|
5
|
my $tmp = $_[1]; |
643
|
3
|
50
|
33
|
|
|
43
|
defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/; |
644
|
|
|
|
|
|
|
} |
645
|
|
|
|
|
|
|
) |
646
|
|
|
|
|
|
|
or Hydrogen::croak( |
647
|
|
|
|
|
|
|
"Type check failed in signature for get: %s should be %s", |
648
|
|
|
|
|
|
|
"\$_[1]", "Int" ); |
649
|
|
|
|
|
|
|
|
650
|
3
|
|
|
|
|
11
|
(@_); |
651
|
|
|
|
|
|
|
}; |
652
|
3
|
|
|
|
|
21
|
($$__REF__)->[ $_[1] ]; |
653
|
|
|
|
|
|
|
} |
654
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
=head2 C<< grep( $arrayref, $coderef ) >> |
656
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
Additional arguments: B<< CodeRef >>. |
658
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
Like C from L. |
660
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
=cut |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
sub grep { |
664
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
667
|
0
|
|
|
|
|
0
|
@_ = do { |
668
|
0
|
|
|
|
|
0
|
my ( %tmp, $tmp ); |
669
|
|
|
|
|
|
|
|
670
|
0
|
0
|
|
|
|
0
|
@_ == 2 |
671
|
|
|
|
|
|
|
or Hydrogen::croak( |
672
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
673
|
|
|
|
|
|
|
"grep", scalar(@_), "expected exactly 2 parameters" ); |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
676
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
677
|
|
|
|
|
|
|
or Hydrogen::croak( |
678
|
|
|
|
|
|
|
"Type check failed in signature for grep: %s should be %s", |
679
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
680
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
# Parameter $_[1] (type: CodeRef) |
682
|
0
|
0
|
|
|
|
0
|
( ref( $_[1] ) eq 'CODE' ) |
683
|
|
|
|
|
|
|
or Hydrogen::croak( |
684
|
|
|
|
|
|
|
"Type check failed in signature for grep: %s should be %s", |
685
|
|
|
|
|
|
|
"\$_[1]", "CodeRef" ); |
686
|
|
|
|
|
|
|
|
687
|
0
|
|
|
|
|
0
|
(@_); |
688
|
|
|
|
|
|
|
}; |
689
|
0
|
|
|
|
|
0
|
grep( $_[1]->($_), @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
690
|
|
|
|
|
|
|
} |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
=head2 C<< head( $arrayref, $count ) >> |
693
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
Additional arguments: B<< Int >>. |
695
|
|
|
|
|
|
|
|
696
|
|
|
|
|
|
|
Returns the first C<< $count >> elements of the array in list context. |
697
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
=cut |
699
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
sub head { |
701
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
702
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
704
|
0
|
|
|
|
|
0
|
@_ = do { |
705
|
0
|
|
|
|
|
0
|
my ( %tmp, $tmp ); |
706
|
|
|
|
|
|
|
|
707
|
0
|
0
|
|
|
|
0
|
@_ == 2 |
708
|
|
|
|
|
|
|
or Hydrogen::croak( |
709
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
710
|
|
|
|
|
|
|
"head", scalar(@_), "expected exactly 2 parameters" ); |
711
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
713
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
714
|
|
|
|
|
|
|
or Hydrogen::croak( |
715
|
|
|
|
|
|
|
"Type check failed in signature for head: %s should be %s", |
716
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
717
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
# Parameter $_[1] (type: Int) |
719
|
|
|
|
|
|
|
( |
720
|
0
|
0
|
|
|
|
0
|
do { |
721
|
0
|
|
|
|
|
0
|
my $tmp = $_[1]; |
722
|
0
|
0
|
0
|
|
|
0
|
defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/; |
723
|
|
|
|
|
|
|
} |
724
|
|
|
|
|
|
|
) |
725
|
|
|
|
|
|
|
or Hydrogen::croak( |
726
|
|
|
|
|
|
|
"Type check failed in signature for head: %s should be %s", |
727
|
|
|
|
|
|
|
"\$_[1]", "Int" ); |
728
|
|
|
|
|
|
|
|
729
|
0
|
|
|
|
|
0
|
(@_); |
730
|
|
|
|
|
|
|
}; |
731
|
0
|
|
|
|
|
0
|
my $shv_count = $_[1]; |
732
|
0
|
0
|
|
|
|
0
|
$shv_count = @{$$__REF__} if $shv_count > @{$$__REF__}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
733
|
0
|
0
|
|
|
|
0
|
$shv_count = @{$$__REF__} + $shv_count if $shv_count < 0; |
|
0
|
|
|
|
|
0
|
|
734
|
0
|
|
|
|
|
0
|
( @{$$__REF__} )[ 0 .. ( $shv_count - 1 ) ]; |
|
0
|
|
|
|
|
0
|
|
735
|
|
|
|
|
|
|
} |
736
|
|
|
|
|
|
|
|
737
|
|
|
|
|
|
|
=head2 C<< insert( $arrayref, $index, $value ) >> |
738
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
Additional arguments: B<< Int >>, B<< Any >>. |
740
|
|
|
|
|
|
|
|
741
|
|
|
|
|
|
|
Inserts a value into the array with the given index. Elements after it will be "moved down". |
742
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
=cut |
744
|
|
|
|
|
|
|
|
745
|
|
|
|
|
|
|
sub insert { |
746
|
1
|
|
|
1
|
1
|
9540
|
my $__REF__ = \$_[0]; |
747
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
749
|
1
|
|
|
|
|
3
|
@_ = do { |
750
|
1
|
|
|
|
|
3
|
my ( %tmp, $tmp ); |
751
|
|
|
|
|
|
|
|
752
|
1
|
50
|
|
|
|
7
|
@_ == 3 |
753
|
|
|
|
|
|
|
or Hydrogen::croak( |
754
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
755
|
|
|
|
|
|
|
"insert", scalar(@_), "expected exactly 3 parameters" ); |
756
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
758
|
1
|
50
|
|
|
|
7
|
( ref( $_[0] ) eq 'ARRAY' ) |
759
|
|
|
|
|
|
|
or Hydrogen::croak( |
760
|
|
|
|
|
|
|
"Type check failed in signature for insert: %s should be %s", |
761
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
762
|
|
|
|
|
|
|
|
763
|
|
|
|
|
|
|
# Parameter $_[1] (type: Int) |
764
|
|
|
|
|
|
|
( |
765
|
1
|
50
|
|
|
|
2
|
do { |
766
|
1
|
|
|
|
|
2
|
my $tmp = $_[1]; |
767
|
1
|
50
|
33
|
|
|
19
|
defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/; |
768
|
|
|
|
|
|
|
} |
769
|
|
|
|
|
|
|
) |
770
|
|
|
|
|
|
|
or Hydrogen::croak( |
771
|
|
|
|
|
|
|
"Type check failed in signature for insert: %s should be %s", |
772
|
|
|
|
|
|
|
"\$_[1]", "Int" ); |
773
|
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
# Parameter $_[2] (type: Any) |
775
|
1
|
|
|
|
|
3
|
1; # ... nothing to do |
776
|
|
|
|
|
|
|
|
777
|
1
|
|
|
|
|
4
|
(@_); |
778
|
|
|
|
|
|
|
}; |
779
|
1
|
|
|
|
|
2
|
1; |
780
|
1
|
|
|
|
|
5
|
splice( @{$$__REF__}, $_[1], 0, $_[2] ); |
|
1
|
|
|
|
|
5
|
|
781
|
|
|
|
|
|
|
} |
782
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
=head2 C<< is_empty( $arrayref ) >> |
784
|
|
|
|
|
|
|
|
785
|
|
|
|
|
|
|
Boolean indicating if the referenced array is empty. |
786
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
=cut |
788
|
|
|
|
|
|
|
|
789
|
|
|
|
|
|
|
sub is_empty { |
790
|
2
|
|
|
2
|
1
|
4137
|
my $__REF__ = \$_[0]; |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
793
|
2
|
50
|
|
|
|
7
|
@_ == 1 |
794
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for is_empty; usage: " |
795
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::is_empty( \$arrayref )" ); |
796
|
2
|
|
|
|
|
3
|
!scalar( @{$$__REF__} ); |
|
2
|
|
|
|
|
10
|
|
797
|
|
|
|
|
|
|
} |
798
|
|
|
|
|
|
|
|
799
|
|
|
|
|
|
|
=head2 C<< join( $arrayref, $with? ) >> |
800
|
|
|
|
|
|
|
|
801
|
|
|
|
|
|
|
Additional arguments: B<< Optional[Str] >>. |
802
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
Returns a string joining all the elements in the array; if C<< $with >> is omitted, defaults to a comma. |
804
|
|
|
|
|
|
|
|
805
|
|
|
|
|
|
|
=cut |
806
|
|
|
|
|
|
|
|
807
|
|
|
|
|
|
|
{ |
808
|
|
|
|
|
|
|
my $__signature; |
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
sub join { |
811
|
2
|
|
|
2
|
1
|
3598
|
my $__REF__ = \$_[0]; |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
814
|
|
|
|
|
|
|
$__signature ||= sub { |
815
|
2
|
|
|
2
|
|
4
|
my ( %tmp, $tmp ); |
816
|
|
|
|
|
|
|
|
817
|
2
|
50
|
33
|
|
|
11
|
@_ >= 1 && @_ <= 2 |
818
|
|
|
|
|
|
|
or Hydrogen::croak( |
819
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
820
|
|
|
|
|
|
|
"join", scalar(@_), "expected exactly 1 parameters" ); |
821
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
823
|
2
|
50
|
|
|
|
9
|
( ref( $_[0] ) eq 'ARRAY' ) |
824
|
|
|
|
|
|
|
or Hydrogen::croak( |
825
|
|
|
|
|
|
|
"Type check failed in signature for join: %s should be %s", |
826
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
827
|
|
|
|
|
|
|
|
828
|
|
|
|
|
|
|
# Parameter $_[1] (type: Optional[Str]) |
829
|
2
|
100
|
|
|
|
9
|
$#_ >= 1 |
830
|
|
|
|
|
|
|
or return (@_); |
831
|
1
|
50
|
|
|
|
2
|
do { |
832
|
|
|
|
|
|
|
|
833
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
834
|
1
|
50
|
|
|
|
11
|
defined( $_[1] ) and do { |
835
|
1
|
50
|
|
|
|
15
|
ref( \$_[1] ) eq 'SCALAR' |
836
|
|
|
|
|
|
|
or ref( \( my $val = $_[1] ) ) eq 'SCALAR'; |
837
|
|
|
|
|
|
|
} |
838
|
|
|
|
|
|
|
} |
839
|
|
|
|
|
|
|
or Hydrogen::croak( |
840
|
|
|
|
|
|
|
"Type check failed in signature for join: %s should be %s", |
841
|
|
|
|
|
|
|
"\$_[1]", "Optional[Str]" ); |
842
|
|
|
|
|
|
|
|
843
|
1
|
|
|
|
|
4
|
(@_); |
844
|
2
|
|
100
|
|
|
13
|
}; |
845
|
2
|
|
|
|
|
6
|
@_ = &$__signature; |
846
|
2
|
100
|
|
|
|
8
|
my $shv_param_with = ( @_ - 1 ) ? $_[1] : q[,]; |
847
|
2
|
|
|
|
|
3
|
join( $shv_param_with, @{$$__REF__} ); |
|
2
|
|
|
|
|
13
|
|
848
|
|
|
|
|
|
|
} |
849
|
|
|
|
|
|
|
} |
850
|
|
|
|
|
|
|
|
851
|
|
|
|
|
|
|
=head2 C<< map( $arrayref, $coderef ) >> |
852
|
|
|
|
|
|
|
|
853
|
|
|
|
|
|
|
Additional arguments: B<< CodeRef >>. |
854
|
|
|
|
|
|
|
|
855
|
|
|
|
|
|
|
Like C |
856
|
|
|
|
|
|
|
|
857
|
|
|
|
|
|
|
=cut |
858
|
|
|
|
|
|
|
|
859
|
|
|
|
|
|
|
sub map { |
860
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
861
|
|
|
|
|
|
|
|
862
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
863
|
0
|
|
|
|
|
0
|
@_ = do { |
864
|
0
|
|
|
|
|
0
|
my ( %tmp, $tmp ); |
865
|
|
|
|
|
|
|
|
866
|
0
|
0
|
|
|
|
0
|
@_ == 2 |
867
|
|
|
|
|
|
|
or Hydrogen::croak( |
868
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
869
|
|
|
|
|
|
|
"map", scalar(@_), "expected exactly 2 parameters" ); |
870
|
|
|
|
|
|
|
|
871
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
872
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
873
|
|
|
|
|
|
|
or Hydrogen::croak( |
874
|
|
|
|
|
|
|
"Type check failed in signature for map: %s should be %s", |
875
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
876
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
# Parameter $_[1] (type: CodeRef) |
878
|
0
|
0
|
|
|
|
0
|
( ref( $_[1] ) eq 'CODE' ) |
879
|
|
|
|
|
|
|
or Hydrogen::croak( |
880
|
|
|
|
|
|
|
"Type check failed in signature for map: %s should be %s", |
881
|
|
|
|
|
|
|
"\$_[1]", "CodeRef" ); |
882
|
|
|
|
|
|
|
|
883
|
0
|
|
|
|
|
0
|
(@_); |
884
|
|
|
|
|
|
|
}; |
885
|
0
|
|
|
|
|
0
|
map( $_[1]->($_), @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
886
|
|
|
|
|
|
|
} |
887
|
|
|
|
|
|
|
|
888
|
|
|
|
|
|
|
=head2 C<< max( $arrayref ) >> |
889
|
|
|
|
|
|
|
|
890
|
|
|
|
|
|
|
Like C<< List::Util::max() >>. |
891
|
|
|
|
|
|
|
|
892
|
|
|
|
|
|
|
=cut |
893
|
|
|
|
|
|
|
|
894
|
|
|
|
|
|
|
sub max { |
895
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
896
|
|
|
|
|
|
|
|
897
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
898
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
899
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for max; usage: " |
900
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::max( \$arrayref )" ); |
901
|
0
|
|
|
|
|
0
|
&List::Util::max( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
902
|
|
|
|
|
|
|
} |
903
|
|
|
|
|
|
|
|
904
|
|
|
|
|
|
|
=head2 C<< maxstr( $arrayref ) >> |
905
|
|
|
|
|
|
|
|
906
|
|
|
|
|
|
|
Like C<< List::Util::maxstr() >>. |
907
|
|
|
|
|
|
|
|
908
|
|
|
|
|
|
|
=cut |
909
|
|
|
|
|
|
|
|
910
|
|
|
|
|
|
|
sub maxstr { |
911
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
912
|
|
|
|
|
|
|
|
913
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
914
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
915
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for maxstr; usage: " |
916
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::maxstr( \$arrayref )" ); |
917
|
0
|
|
|
|
|
0
|
&List::Util::maxstr( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
918
|
|
|
|
|
|
|
} |
919
|
|
|
|
|
|
|
|
920
|
|
|
|
|
|
|
=head2 C<< min( $arrayref ) >> |
921
|
|
|
|
|
|
|
|
922
|
|
|
|
|
|
|
Like C<< List::Util::min() >>. |
923
|
|
|
|
|
|
|
|
924
|
|
|
|
|
|
|
=cut |
925
|
|
|
|
|
|
|
|
926
|
|
|
|
|
|
|
sub min { |
927
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
928
|
|
|
|
|
|
|
|
929
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
930
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
931
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for min; usage: " |
932
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::min( \$arrayref )" ); |
933
|
0
|
|
|
|
|
0
|
&List::Util::min( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
934
|
|
|
|
|
|
|
} |
935
|
|
|
|
|
|
|
|
936
|
|
|
|
|
|
|
=head2 C<< minstr( $arrayref ) >> |
937
|
|
|
|
|
|
|
|
938
|
|
|
|
|
|
|
Like C<< List::Util::minstr() >>. |
939
|
|
|
|
|
|
|
|
940
|
|
|
|
|
|
|
=cut |
941
|
|
|
|
|
|
|
|
942
|
|
|
|
|
|
|
sub minstr { |
943
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
944
|
|
|
|
|
|
|
|
945
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
946
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
947
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for minstr; usage: " |
948
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::minstr( \$arrayref )" ); |
949
|
0
|
|
|
|
|
0
|
&List::Util::minstr( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
950
|
|
|
|
|
|
|
} |
951
|
|
|
|
|
|
|
|
952
|
|
|
|
|
|
|
=head2 C<< natatime( $arrayref, $n, $callback? ) >> |
953
|
|
|
|
|
|
|
|
954
|
|
|
|
|
|
|
Additional arguments: B<< Int >>, B<< Optional[CodeRef] >>. |
955
|
|
|
|
|
|
|
|
956
|
|
|
|
|
|
|
Given just a number, returns an iterator which reads that many elements from the array at a time. If also given a callback, calls the callback repeatedly with those values. |
957
|
|
|
|
|
|
|
|
958
|
|
|
|
|
|
|
=cut |
959
|
|
|
|
|
|
|
|
960
|
|
|
|
|
|
|
{ |
961
|
|
|
|
|
|
|
my $__signature; |
962
|
|
|
|
|
|
|
|
963
|
|
|
|
|
|
|
sub natatime { |
964
|
1
|
|
|
1
|
1
|
15644
|
my $__REF__ = \$_[0]; |
965
|
|
|
|
|
|
|
|
966
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
967
|
|
|
|
|
|
|
$__signature ||= sub { |
968
|
1
|
|
|
1
|
|
3
|
my ( %tmp, $tmp ); |
969
|
|
|
|
|
|
|
|
970
|
1
|
50
|
33
|
|
|
6
|
@_ >= 2 && @_ <= 3 |
971
|
|
|
|
|
|
|
or Hydrogen::croak( |
972
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
973
|
|
|
|
|
|
|
"natatime", scalar(@_), "expected exactly 2 parameters" ); |
974
|
|
|
|
|
|
|
|
975
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
976
|
1
|
50
|
|
|
|
6
|
( ref( $_[0] ) eq 'ARRAY' ) |
977
|
|
|
|
|
|
|
or Hydrogen::croak( |
978
|
|
|
|
|
|
|
"Type check failed in signature for natatime: %s should be %s", |
979
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" |
980
|
|
|
|
|
|
|
); |
981
|
|
|
|
|
|
|
|
982
|
|
|
|
|
|
|
# Parameter $_[1] (type: Int) |
983
|
|
|
|
|
|
|
( |
984
|
1
|
50
|
|
|
|
3
|
do { |
985
|
1
|
|
|
|
|
3
|
my $tmp = $_[1]; |
986
|
1
|
50
|
33
|
|
|
13
|
defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/; |
987
|
|
|
|
|
|
|
} |
988
|
|
|
|
|
|
|
) |
989
|
|
|
|
|
|
|
or Hydrogen::croak( |
990
|
|
|
|
|
|
|
"Type check failed in signature for natatime: %s should be %s", |
991
|
|
|
|
|
|
|
"\$_[1]", "Int" |
992
|
|
|
|
|
|
|
); |
993
|
|
|
|
|
|
|
|
994
|
|
|
|
|
|
|
# Parameter $_[2] (type: Optional[CodeRef]) |
995
|
1
|
50
|
|
|
|
6
|
$#_ >= 2 |
996
|
|
|
|
|
|
|
or return (@_); |
997
|
0
|
0
|
|
|
|
0
|
( ref( $_[2] ) eq 'CODE' ) |
998
|
|
|
|
|
|
|
or Hydrogen::croak( |
999
|
|
|
|
|
|
|
"Type check failed in signature for natatime: %s should be %s", |
1000
|
|
|
|
|
|
|
"\$_[2]", "Optional[CodeRef]" |
1001
|
|
|
|
|
|
|
); |
1002
|
|
|
|
|
|
|
|
1003
|
0
|
|
|
|
|
0
|
(@_); |
1004
|
1
|
|
50
|
|
|
11
|
}; |
1005
|
1
|
|
|
|
|
4
|
@_ = &$__signature; |
1006
|
1
|
|
|
|
|
4
|
my @shv_remaining = @{$$__REF__}; |
|
1
|
|
|
|
|
3
|
|
1007
|
1
|
|
|
|
|
2
|
my $shv_n = $_[1]; |
1008
|
1
|
|
|
2
|
|
5
|
my $shv_iterator = sub { CORE::splice @shv_remaining, 0, $shv_n }; |
|
2
|
|
|
|
|
17
|
|
1009
|
1
|
50
|
|
|
|
5
|
if ( $_[2] ) { |
1010
|
0
|
|
|
|
|
0
|
while ( my @shv_values = $shv_iterator->() ) { |
1011
|
0
|
|
|
|
|
0
|
$_[2]->(@shv_values); |
1012
|
|
|
|
|
|
|
} |
1013
|
|
|
|
|
|
|
} |
1014
|
1
|
|
|
|
|
4
|
else { $shv_iterator } |
1015
|
|
|
|
|
|
|
} |
1016
|
|
|
|
|
|
|
} |
1017
|
|
|
|
|
|
|
|
1018
|
|
|
|
|
|
|
=head2 C<< not_all_true( $arrayref, $coderef ) >> |
1019
|
|
|
|
|
|
|
|
1020
|
|
|
|
|
|
|
Additional arguments: B<< CodeRef >>. |
1021
|
|
|
|
|
|
|
|
1022
|
|
|
|
|
|
|
Like C<< List::Util::notall() >>. |
1023
|
|
|
|
|
|
|
|
1024
|
|
|
|
|
|
|
=cut |
1025
|
|
|
|
|
|
|
|
1026
|
|
|
|
|
|
|
sub not_all_true { |
1027
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1028
|
|
|
|
|
|
|
|
1029
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1030
|
0
|
|
|
|
|
0
|
@_ = do { |
1031
|
0
|
|
|
|
|
0
|
my ( %tmp, $tmp ); |
1032
|
|
|
|
|
|
|
|
1033
|
0
|
0
|
|
|
|
0
|
@_ == 2 |
1034
|
|
|
|
|
|
|
or Hydrogen::croak( |
1035
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
1036
|
|
|
|
|
|
|
"not_all_true", scalar(@_), "expected exactly 2 parameters" ); |
1037
|
|
|
|
|
|
|
|
1038
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
1039
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
1040
|
|
|
|
|
|
|
or Hydrogen::croak( |
1041
|
|
|
|
|
|
|
"Type check failed in signature for not_all_true: %s should be %s", |
1042
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" |
1043
|
|
|
|
|
|
|
); |
1044
|
|
|
|
|
|
|
|
1045
|
|
|
|
|
|
|
# Parameter $_[1] (type: CodeRef) |
1046
|
0
|
0
|
|
|
|
0
|
( ref( $_[1] ) eq 'CODE' ) |
1047
|
|
|
|
|
|
|
or Hydrogen::croak( |
1048
|
|
|
|
|
|
|
"Type check failed in signature for not_all_true: %s should be %s", |
1049
|
|
|
|
|
|
|
"\$_[1]", "CodeRef" |
1050
|
|
|
|
|
|
|
); |
1051
|
|
|
|
|
|
|
|
1052
|
0
|
|
|
|
|
0
|
(@_); |
1053
|
|
|
|
|
|
|
}; |
1054
|
0
|
|
|
|
|
0
|
&List::Util::notall( $_[1], @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1055
|
|
|
|
|
|
|
} |
1056
|
|
|
|
|
|
|
|
1057
|
|
|
|
|
|
|
=head2 C<< pairfirst( $arrayref, $coderef ) >> |
1058
|
|
|
|
|
|
|
|
1059
|
|
|
|
|
|
|
Additional arguments: B<< CodeRef >>. |
1060
|
|
|
|
|
|
|
|
1061
|
|
|
|
|
|
|
Like C<< List::Util::pairfirst() >>. |
1062
|
|
|
|
|
|
|
|
1063
|
|
|
|
|
|
|
=cut |
1064
|
|
|
|
|
|
|
|
1065
|
|
|
|
|
|
|
sub pairfirst { |
1066
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1067
|
|
|
|
|
|
|
|
1068
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1069
|
0
|
|
|
|
|
0
|
@_ = do { |
1070
|
0
|
|
|
|
|
0
|
my ( %tmp, $tmp ); |
1071
|
|
|
|
|
|
|
|
1072
|
0
|
0
|
|
|
|
0
|
@_ == 2 |
1073
|
|
|
|
|
|
|
or Hydrogen::croak( |
1074
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
1075
|
|
|
|
|
|
|
"pairfirst", scalar(@_), "expected exactly 2 parameters" ); |
1076
|
|
|
|
|
|
|
|
1077
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
1078
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
1079
|
|
|
|
|
|
|
or Hydrogen::croak( |
1080
|
|
|
|
|
|
|
"Type check failed in signature for pairfirst: %s should be %s", |
1081
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
1082
|
|
|
|
|
|
|
|
1083
|
|
|
|
|
|
|
# Parameter $_[1] (type: CodeRef) |
1084
|
0
|
0
|
|
|
|
0
|
( ref( $_[1] ) eq 'CODE' ) |
1085
|
|
|
|
|
|
|
or Hydrogen::croak( |
1086
|
|
|
|
|
|
|
"Type check failed in signature for pairfirst: %s should be %s", |
1087
|
|
|
|
|
|
|
"\$_[1]", "CodeRef" ); |
1088
|
|
|
|
|
|
|
|
1089
|
0
|
|
|
|
|
0
|
(@_); |
1090
|
|
|
|
|
|
|
}; |
1091
|
0
|
|
|
0
|
|
0
|
List::Util::pairfirst { $_[1]->($_) } @{$$__REF__}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1092
|
|
|
|
|
|
|
} |
1093
|
|
|
|
|
|
|
|
1094
|
|
|
|
|
|
|
=head2 C<< pairgrep( $arrayref, $coderef ) >> |
1095
|
|
|
|
|
|
|
|
1096
|
|
|
|
|
|
|
Additional arguments: B<< CodeRef >>. |
1097
|
|
|
|
|
|
|
|
1098
|
|
|
|
|
|
|
Like C<< List::Util::pairgrep() >>. |
1099
|
|
|
|
|
|
|
|
1100
|
|
|
|
|
|
|
=cut |
1101
|
|
|
|
|
|
|
|
1102
|
|
|
|
|
|
|
sub pairgrep { |
1103
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1104
|
|
|
|
|
|
|
|
1105
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1106
|
0
|
|
|
|
|
0
|
@_ = do { |
1107
|
0
|
|
|
|
|
0
|
my ( %tmp, $tmp ); |
1108
|
|
|
|
|
|
|
|
1109
|
0
|
0
|
|
|
|
0
|
@_ == 2 |
1110
|
|
|
|
|
|
|
or Hydrogen::croak( |
1111
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
1112
|
|
|
|
|
|
|
"pairgrep", scalar(@_), "expected exactly 2 parameters" ); |
1113
|
|
|
|
|
|
|
|
1114
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
1115
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
1116
|
|
|
|
|
|
|
or Hydrogen::croak( |
1117
|
|
|
|
|
|
|
"Type check failed in signature for pairgrep: %s should be %s", |
1118
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
1119
|
|
|
|
|
|
|
|
1120
|
|
|
|
|
|
|
# Parameter $_[1] (type: CodeRef) |
1121
|
0
|
0
|
|
|
|
0
|
( ref( $_[1] ) eq 'CODE' ) |
1122
|
|
|
|
|
|
|
or Hydrogen::croak( |
1123
|
|
|
|
|
|
|
"Type check failed in signature for pairgrep: %s should be %s", |
1124
|
|
|
|
|
|
|
"\$_[1]", "CodeRef" ); |
1125
|
|
|
|
|
|
|
|
1126
|
0
|
|
|
|
|
0
|
(@_); |
1127
|
|
|
|
|
|
|
}; |
1128
|
0
|
|
|
0
|
|
0
|
List::Util::pairgrep { $_[1]->($_) } @{$$__REF__}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1129
|
|
|
|
|
|
|
} |
1130
|
|
|
|
|
|
|
|
1131
|
|
|
|
|
|
|
=head2 C<< pairkeys( $arrayref ) >> |
1132
|
|
|
|
|
|
|
|
1133
|
|
|
|
|
|
|
Like C<< List::Util::pairkeys() >>. |
1134
|
|
|
|
|
|
|
|
1135
|
|
|
|
|
|
|
=cut |
1136
|
|
|
|
|
|
|
|
1137
|
|
|
|
|
|
|
sub pairkeys { |
1138
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1139
|
|
|
|
|
|
|
|
1140
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1141
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
1142
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for pairkeys; usage: " |
1143
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::pairkeys( \$arrayref )" ); |
1144
|
0
|
|
|
|
|
0
|
&List::Util::pairkeys( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1145
|
|
|
|
|
|
|
} |
1146
|
|
|
|
|
|
|
|
1147
|
|
|
|
|
|
|
=head2 C<< pairmap( $arrayref, $coderef ) >> |
1148
|
|
|
|
|
|
|
|
1149
|
|
|
|
|
|
|
Additional arguments: B<< CodeRef >>. |
1150
|
|
|
|
|
|
|
|
1151
|
|
|
|
|
|
|
Like C<< List::Util::pairmap() >>. |
1152
|
|
|
|
|
|
|
|
1153
|
|
|
|
|
|
|
=cut |
1154
|
|
|
|
|
|
|
|
1155
|
|
|
|
|
|
|
sub pairmap { |
1156
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1157
|
|
|
|
|
|
|
|
1158
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1159
|
0
|
|
|
|
|
0
|
@_ = do { |
1160
|
0
|
|
|
|
|
0
|
my ( %tmp, $tmp ); |
1161
|
|
|
|
|
|
|
|
1162
|
0
|
0
|
|
|
|
0
|
@_ == 2 |
1163
|
|
|
|
|
|
|
or Hydrogen::croak( |
1164
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
1165
|
|
|
|
|
|
|
"pairmap", scalar(@_), "expected exactly 2 parameters" ); |
1166
|
|
|
|
|
|
|
|
1167
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
1168
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
1169
|
|
|
|
|
|
|
or Hydrogen::croak( |
1170
|
|
|
|
|
|
|
"Type check failed in signature for pairmap: %s should be %s", |
1171
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
1172
|
|
|
|
|
|
|
|
1173
|
|
|
|
|
|
|
# Parameter $_[1] (type: CodeRef) |
1174
|
0
|
0
|
|
|
|
0
|
( ref( $_[1] ) eq 'CODE' ) |
1175
|
|
|
|
|
|
|
or Hydrogen::croak( |
1176
|
|
|
|
|
|
|
"Type check failed in signature for pairmap: %s should be %s", |
1177
|
|
|
|
|
|
|
"\$_[1]", "CodeRef" ); |
1178
|
|
|
|
|
|
|
|
1179
|
0
|
|
|
|
|
0
|
(@_); |
1180
|
|
|
|
|
|
|
}; |
1181
|
0
|
|
|
0
|
|
0
|
List::Util::pairmap { $_[1]->($_) } @{$$__REF__}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1182
|
|
|
|
|
|
|
} |
1183
|
|
|
|
|
|
|
|
1184
|
|
|
|
|
|
|
=head2 C<< pairs( $arrayref ) >> |
1185
|
|
|
|
|
|
|
|
1186
|
|
|
|
|
|
|
Like C<< List::Util::pairs() >>. |
1187
|
|
|
|
|
|
|
|
1188
|
|
|
|
|
|
|
=cut |
1189
|
|
|
|
|
|
|
|
1190
|
|
|
|
|
|
|
sub pairs { |
1191
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1192
|
|
|
|
|
|
|
|
1193
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1194
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
1195
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for pairs; usage: " |
1196
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::pairs( \$arrayref )" ); |
1197
|
0
|
|
|
|
|
0
|
&List::Util::pairs( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1198
|
|
|
|
|
|
|
} |
1199
|
|
|
|
|
|
|
|
1200
|
|
|
|
|
|
|
=head2 C<< pairvalues( $arrayref ) >> |
1201
|
|
|
|
|
|
|
|
1202
|
|
|
|
|
|
|
Like C<< List::Util::pairvalues() >>. |
1203
|
|
|
|
|
|
|
|
1204
|
|
|
|
|
|
|
=cut |
1205
|
|
|
|
|
|
|
|
1206
|
|
|
|
|
|
|
sub pairvalues { |
1207
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1208
|
|
|
|
|
|
|
|
1209
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1210
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
1211
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for pairvalues; usage: " |
1212
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::pairvalues( \$arrayref )" ); |
1213
|
0
|
|
|
|
|
0
|
&List::Util::pairvalues( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1214
|
|
|
|
|
|
|
} |
1215
|
|
|
|
|
|
|
|
1216
|
|
|
|
|
|
|
=head2 C<< pick_random( $arrayref, $count ) >> |
1217
|
|
|
|
|
|
|
|
1218
|
|
|
|
|
|
|
Additional arguments: B<< Optional[Int] >>. |
1219
|
|
|
|
|
|
|
|
1220
|
|
|
|
|
|
|
If no C<< $count >> is given, returns one element of the array at random. If C<< $count >> is given, creates a new array with that many random elements from the original array (or fewer if the original array is not long enough) and returns that as an arrayref or list depending on context |
1221
|
|
|
|
|
|
|
|
1222
|
|
|
|
|
|
|
=cut |
1223
|
|
|
|
|
|
|
|
1224
|
|
|
|
|
|
|
{ |
1225
|
|
|
|
|
|
|
my $__signature; |
1226
|
|
|
|
|
|
|
|
1227
|
|
|
|
|
|
|
sub pick_random { |
1228
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1229
|
|
|
|
|
|
|
|
1230
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1231
|
|
|
|
|
|
|
$__signature ||= sub { |
1232
|
0
|
|
|
0
|
|
0
|
my ( %tmp, $tmp ); |
1233
|
|
|
|
|
|
|
|
1234
|
0
|
0
|
0
|
|
|
0
|
@_ >= 1 && @_ <= 2 |
1235
|
|
|
|
|
|
|
or Hydrogen::croak( |
1236
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
1237
|
|
|
|
|
|
|
"pick_random", scalar(@_), "expected exactly 1 parameters" ); |
1238
|
|
|
|
|
|
|
|
1239
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
1240
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
1241
|
|
|
|
|
|
|
or Hydrogen::croak( |
1242
|
|
|
|
|
|
|
"Type check failed in signature for pick_random: %s should be %s", |
1243
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" |
1244
|
|
|
|
|
|
|
); |
1245
|
|
|
|
|
|
|
|
1246
|
|
|
|
|
|
|
# Parameter $_[1] (type: Optional[Int]) |
1247
|
0
|
0
|
|
|
|
0
|
$#_ >= 1 |
1248
|
|
|
|
|
|
|
or return (@_); |
1249
|
|
|
|
|
|
|
( |
1250
|
0
|
0
|
|
|
|
0
|
do { |
1251
|
0
|
|
|
|
|
0
|
my $tmp = $_[1]; |
1252
|
0
|
0
|
0
|
|
|
0
|
defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/; |
1253
|
|
|
|
|
|
|
} |
1254
|
|
|
|
|
|
|
) |
1255
|
|
|
|
|
|
|
or Hydrogen::croak( |
1256
|
|
|
|
|
|
|
"Type check failed in signature for pick_random: %s should be %s", |
1257
|
|
|
|
|
|
|
"\$_[1]", "Optional[Int]" |
1258
|
|
|
|
|
|
|
); |
1259
|
|
|
|
|
|
|
|
1260
|
0
|
|
|
|
|
0
|
(@_); |
1261
|
0
|
|
0
|
|
|
0
|
}; |
1262
|
0
|
|
|
|
|
0
|
@_ = &$__signature; |
1263
|
0
|
|
|
|
|
0
|
my @shv_tmp = List::Util::shuffle( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1264
|
0
|
|
|
|
|
0
|
my $shv_count = $_[1]; |
1265
|
0
|
0
|
|
|
|
0
|
$shv_count = @{$$__REF__} if $shv_count > @{$$__REF__}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1266
|
0
|
0
|
|
|
|
0
|
$shv_count = @{$$__REF__} + $shv_count if $shv_count < 0; |
|
0
|
|
|
|
|
0
|
|
1267
|
0
|
0
|
0
|
|
|
0
|
if ( wantarray and ( @_ - 1 ) ) { @shv_tmp[ 0 .. $shv_count - 1 ] } |
|
0
|
0
|
|
|
|
0
|
|
1268
|
0
|
|
|
|
|
0
|
elsif ( ( @_ - 1 ) ) { [ @shv_tmp[ 0 .. $shv_count - 1 ] ] } |
1269
|
0
|
|
|
|
|
0
|
else { $shv_tmp[0] } |
1270
|
|
|
|
|
|
|
} |
1271
|
|
|
|
|
|
|
} |
1272
|
|
|
|
|
|
|
|
1273
|
|
|
|
|
|
|
=head2 C<< pop( $arrayref ) >> |
1274
|
|
|
|
|
|
|
|
1275
|
|
|
|
|
|
|
Removes the last element from the array and returns it. |
1276
|
|
|
|
|
|
|
|
1277
|
|
|
|
|
|
|
=cut |
1278
|
|
|
|
|
|
|
|
1279
|
|
|
|
|
|
|
sub pop { |
1280
|
2
|
|
|
2
|
1
|
23272
|
my $__REF__ = \$_[0]; |
1281
|
|
|
|
|
|
|
|
1282
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1283
|
2
|
50
|
|
|
|
8
|
@_ == 1 |
1284
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for pop; usage: " |
1285
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::pop( \$arrayref )" ); |
1286
|
2
|
|
|
|
|
3
|
1; |
1287
|
2
|
|
|
|
|
4
|
pop( @{$$__REF__} ); |
|
2
|
|
|
|
|
9
|
|
1288
|
|
|
|
|
|
|
} |
1289
|
|
|
|
|
|
|
|
1290
|
|
|
|
|
|
|
=head2 C<< print( $arrayref, $fh?, $with? ) >> |
1291
|
|
|
|
|
|
|
|
1292
|
|
|
|
|
|
|
Additional arguments: B<< Optional[FileHandle] >>, B<< Optional[Str] >>. |
1293
|
|
|
|
|
|
|
|
1294
|
|
|
|
|
|
|
Prints a string joining all the elements in the array; if C<< $fh >> is omitted, defaults to STDOUT; if C<< $with >> is omitted, defaults to a comma. |
1295
|
|
|
|
|
|
|
|
1296
|
|
|
|
|
|
|
=cut |
1297
|
|
|
|
|
|
|
|
1298
|
|
|
|
|
|
|
{ |
1299
|
|
|
|
|
|
|
my $__signature; |
1300
|
|
|
|
|
|
|
|
1301
|
|
|
|
|
|
|
sub print { |
1302
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1303
|
|
|
|
|
|
|
|
1304
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1305
|
|
|
|
|
|
|
$__signature ||= sub { |
1306
|
0
|
|
|
0
|
|
0
|
my ( %tmp, $tmp ); |
1307
|
|
|
|
|
|
|
|
1308
|
0
|
0
|
0
|
|
|
0
|
@_ >= 1 && @_ <= 3 |
1309
|
|
|
|
|
|
|
or Hydrogen::croak( |
1310
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
1311
|
|
|
|
|
|
|
"print", scalar(@_), "expected exactly 1 parameters" ); |
1312
|
|
|
|
|
|
|
|
1313
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
1314
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
1315
|
|
|
|
|
|
|
or Hydrogen::croak( |
1316
|
|
|
|
|
|
|
"Type check failed in signature for print: %s should be %s", |
1317
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
1318
|
|
|
|
|
|
|
|
1319
|
|
|
|
|
|
|
# Parameter $_[1] (type: Optional[FileHandle]) |
1320
|
0
|
0
|
|
|
|
0
|
$#_ >= 1 |
1321
|
|
|
|
|
|
|
or return (@_); |
1322
|
|
|
|
|
|
|
( |
1323
|
0
|
0
|
|
|
|
0
|
do { |
1324
|
|
|
|
|
|
|
|
1325
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1326
|
3
|
|
|
3
|
|
16791
|
use Scalar::Util (); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
9926
|
|
1327
|
0
|
0
|
0
|
|
|
0
|
( ref( $_[1] ) && Scalar::Util::openhandle( $_[1] ) ) |
|
|
|
0
|
|
|
|
|
1328
|
|
|
|
|
|
|
or ( Scalar::Util::blessed( $_[1] ) |
1329
|
|
|
|
|
|
|
&& $_[1]->isa("IO::Handle") ); |
1330
|
|
|
|
|
|
|
} |
1331
|
|
|
|
|
|
|
) |
1332
|
|
|
|
|
|
|
or Hydrogen::croak( |
1333
|
|
|
|
|
|
|
"Type check failed in signature for print: %s should be %s", |
1334
|
|
|
|
|
|
|
"\$_[1]", "Optional[FileHandle]" ); |
1335
|
|
|
|
|
|
|
|
1336
|
|
|
|
|
|
|
# Parameter $_[2] (type: Optional[Str]) |
1337
|
0
|
0
|
|
|
|
0
|
$#_ >= 2 |
1338
|
|
|
|
|
|
|
or return (@_); |
1339
|
0
|
0
|
|
|
|
0
|
do { |
1340
|
|
|
|
|
|
|
|
1341
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1342
|
0
|
0
|
|
|
|
0
|
defined( $_[2] ) and do { |
1343
|
0
|
0
|
|
|
|
0
|
ref( \$_[2] ) eq 'SCALAR' |
1344
|
|
|
|
|
|
|
or ref( \( my $val = $_[2] ) ) eq 'SCALAR'; |
1345
|
|
|
|
|
|
|
} |
1346
|
|
|
|
|
|
|
} |
1347
|
|
|
|
|
|
|
or Hydrogen::croak( |
1348
|
|
|
|
|
|
|
"Type check failed in signature for print: %s should be %s", |
1349
|
|
|
|
|
|
|
"\$_[2]", "Optional[Str]" ); |
1350
|
|
|
|
|
|
|
|
1351
|
0
|
|
|
|
|
0
|
(@_); |
1352
|
0
|
|
0
|
|
|
0
|
}; |
1353
|
0
|
|
|
|
|
0
|
@_ = &$__signature; |
1354
|
0
|
0
|
|
|
|
0
|
my $shv_param_with = ( ( @_ - 1 ) > 1 ) ? $_[2] : q[,]; |
1355
|
0
|
0
|
|
|
|
0
|
print { $_[1] || *STDOUT } join( $shv_param_with, @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1356
|
|
|
|
|
|
|
} |
1357
|
|
|
|
|
|
|
} |
1358
|
|
|
|
|
|
|
|
1359
|
|
|
|
|
|
|
=head2 C<< product( $arrayref ) >> |
1360
|
|
|
|
|
|
|
|
1361
|
|
|
|
|
|
|
Like C<< List::Util::product() >>. |
1362
|
|
|
|
|
|
|
|
1363
|
|
|
|
|
|
|
=cut |
1364
|
|
|
|
|
|
|
|
1365
|
|
|
|
|
|
|
sub product { |
1366
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1367
|
|
|
|
|
|
|
|
1368
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1369
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
1370
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for product; usage: " |
1371
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::product( \$arrayref )" ); |
1372
|
0
|
|
|
|
|
0
|
&List::Util::product( 1, @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1373
|
|
|
|
|
|
|
} |
1374
|
|
|
|
|
|
|
|
1375
|
|
|
|
|
|
|
=head2 C<< push( $arrayref, @values ) >> |
1376
|
|
|
|
|
|
|
|
1377
|
|
|
|
|
|
|
Adds elements to the end of the array. |
1378
|
|
|
|
|
|
|
|
1379
|
|
|
|
|
|
|
=cut |
1380
|
|
|
|
|
|
|
|
1381
|
|
|
|
|
|
|
sub push { |
1382
|
1
|
|
|
1
|
1
|
8830
|
my $__REF__ = \$_[0]; |
1383
|
|
|
|
|
|
|
|
1384
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1385
|
1
|
|
|
|
|
2
|
1; |
1386
|
1
|
|
|
|
|
3
|
push( @{$$__REF__}, @_[ 1 .. $#_ ] ); |
|
1
|
|
|
|
|
6
|
|
1387
|
|
|
|
|
|
|
} |
1388
|
|
|
|
|
|
|
|
1389
|
|
|
|
|
|
|
=head2 C<< reduce( $arrayref, $coderef ) >> |
1390
|
|
|
|
|
|
|
|
1391
|
|
|
|
|
|
|
Additional arguments: B<< CodeRef >>. |
1392
|
|
|
|
|
|
|
|
1393
|
|
|
|
|
|
|
Like C<< List::Util::reduce() >>. |
1394
|
|
|
|
|
|
|
|
1395
|
|
|
|
|
|
|
=cut |
1396
|
|
|
|
|
|
|
|
1397
|
|
|
|
|
|
|
sub reduce { |
1398
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1399
|
|
|
|
|
|
|
|
1400
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1401
|
0
|
|
|
|
|
0
|
@_ = do { |
1402
|
0
|
|
|
|
|
0
|
my ( %tmp, $tmp ); |
1403
|
|
|
|
|
|
|
|
1404
|
0
|
0
|
|
|
|
0
|
@_ == 2 |
1405
|
|
|
|
|
|
|
or Hydrogen::croak( |
1406
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
1407
|
|
|
|
|
|
|
"reduce", scalar(@_), "expected exactly 2 parameters" ); |
1408
|
|
|
|
|
|
|
|
1409
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
1410
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
1411
|
|
|
|
|
|
|
or Hydrogen::croak( |
1412
|
|
|
|
|
|
|
"Type check failed in signature for reduce: %s should be %s", |
1413
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
1414
|
|
|
|
|
|
|
|
1415
|
|
|
|
|
|
|
# Parameter $_[1] (type: CodeRef) |
1416
|
0
|
0
|
|
|
|
0
|
( ref( $_[1] ) eq 'CODE' ) |
1417
|
|
|
|
|
|
|
or Hydrogen::croak( |
1418
|
|
|
|
|
|
|
"Type check failed in signature for reduce: %s should be %s", |
1419
|
|
|
|
|
|
|
"\$_[1]", "CodeRef" ); |
1420
|
|
|
|
|
|
|
|
1421
|
0
|
|
|
|
|
0
|
(@_); |
1422
|
|
|
|
|
|
|
}; |
1423
|
0
|
|
|
|
|
0
|
my $shv_callback = $_[1]; |
1424
|
0
|
|
|
0
|
|
0
|
List::Util::reduce { $shv_callback->( $a, $b ) } @{$$__REF__}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1425
|
|
|
|
|
|
|
} |
1426
|
|
|
|
|
|
|
|
1427
|
|
|
|
|
|
|
=head2 C<< reductions( $arrayref, $coderef ) >> |
1428
|
|
|
|
|
|
|
|
1429
|
|
|
|
|
|
|
Additional arguments: B<< CodeRef >>. |
1430
|
|
|
|
|
|
|
|
1431
|
|
|
|
|
|
|
Like C<< List::Util::reductions() >>. |
1432
|
|
|
|
|
|
|
|
1433
|
|
|
|
|
|
|
=cut |
1434
|
|
|
|
|
|
|
|
1435
|
|
|
|
|
|
|
sub reductions { |
1436
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1437
|
|
|
|
|
|
|
|
1438
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1439
|
0
|
|
|
|
|
0
|
@_ = do { |
1440
|
0
|
|
|
|
|
0
|
my ( %tmp, $tmp ); |
1441
|
|
|
|
|
|
|
|
1442
|
0
|
0
|
|
|
|
0
|
@_ == 2 |
1443
|
|
|
|
|
|
|
or Hydrogen::croak( |
1444
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
1445
|
|
|
|
|
|
|
"reductions", scalar(@_), "expected exactly 2 parameters" ); |
1446
|
|
|
|
|
|
|
|
1447
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
1448
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
1449
|
|
|
|
|
|
|
or Hydrogen::croak( |
1450
|
|
|
|
|
|
|
"Type check failed in signature for reductions: %s should be %s", |
1451
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
1452
|
|
|
|
|
|
|
|
1453
|
|
|
|
|
|
|
# Parameter $_[1] (type: CodeRef) |
1454
|
0
|
0
|
|
|
|
0
|
( ref( $_[1] ) eq 'CODE' ) |
1455
|
|
|
|
|
|
|
or Hydrogen::croak( |
1456
|
|
|
|
|
|
|
"Type check failed in signature for reductions: %s should be %s", |
1457
|
|
|
|
|
|
|
"\$_[1]", "CodeRef" ); |
1458
|
|
|
|
|
|
|
|
1459
|
0
|
|
|
|
|
0
|
(@_); |
1460
|
|
|
|
|
|
|
}; |
1461
|
0
|
|
|
|
|
0
|
my $shv_callback = $_[1]; |
1462
|
0
|
|
|
0
|
|
0
|
List::Util::reductions { $shv_callback->( $a, $b ) } @{$$__REF__}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1463
|
|
|
|
|
|
|
} |
1464
|
|
|
|
|
|
|
|
1465
|
|
|
|
|
|
|
=head2 C<< reset( $arrayref ) >> |
1466
|
|
|
|
|
|
|
|
1467
|
|
|
|
|
|
|
Resets the original value to its default value, or an empty arrayref if it has no default. |
1468
|
|
|
|
|
|
|
|
1469
|
|
|
|
|
|
|
=cut |
1470
|
|
|
|
|
|
|
|
1471
|
|
|
|
|
|
|
sub reset { |
1472
|
1
|
|
|
1
|
1
|
8561
|
my $__REF__ = \$_[0]; |
1473
|
|
|
|
|
|
|
|
1474
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1475
|
1
|
50
|
|
|
|
6
|
@_ == 1 |
1476
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for reset; usage: " |
1477
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::reset( \$arrayref )" ); |
1478
|
|
|
|
|
|
|
( |
1479
|
1
|
|
|
|
|
5
|
@{ $_[0] } = @{ |
1480
|
1
|
|
|
|
|
4
|
+do { |
|
1
|
|
|
|
|
3
|
|
1481
|
1
|
|
|
|
|
4
|
my $shv_final_unchecked = []; |
1482
|
1
|
|
|
|
|
2
|
do { |
1483
|
1
|
50
|
|
|
|
4
|
( ref($shv_final_unchecked) eq 'ARRAY' ) |
1484
|
|
|
|
|
|
|
or Hydrogen::croak( |
1485
|
|
|
|
|
|
|
"Type check failed for reset: expected %s, got value %s", |
1486
|
|
|
|
|
|
|
"ArrayRef", $shv_final_unchecked |
1487
|
|
|
|
|
|
|
); |
1488
|
1
|
|
|
|
|
4
|
$shv_final_unchecked; |
1489
|
|
|
|
|
|
|
}; |
1490
|
|
|
|
|
|
|
} |
1491
|
|
|
|
|
|
|
} |
1492
|
|
|
|
|
|
|
); |
1493
|
|
|
|
|
|
|
} |
1494
|
|
|
|
|
|
|
|
1495
|
|
|
|
|
|
|
=head2 C<< reverse( $arrayref ) >> |
1496
|
|
|
|
|
|
|
|
1497
|
|
|
|
|
|
|
Returns the reversed array in list context. |
1498
|
|
|
|
|
|
|
|
1499
|
|
|
|
|
|
|
=cut |
1500
|
|
|
|
|
|
|
|
1501
|
|
|
|
|
|
|
sub reverse { |
1502
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1503
|
|
|
|
|
|
|
|
1504
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1505
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
1506
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for reverse; usage: " |
1507
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::reverse( \$arrayref )" ); |
1508
|
0
|
|
|
|
|
0
|
reverse @{$$__REF__}; |
|
0
|
|
|
|
|
0
|
|
1509
|
|
|
|
|
|
|
} |
1510
|
|
|
|
|
|
|
|
1511
|
|
|
|
|
|
|
=head2 C<< sample( $arrayref, $count ) >> |
1512
|
|
|
|
|
|
|
|
1513
|
|
|
|
|
|
|
Additional arguments: B<< Int >>. |
1514
|
|
|
|
|
|
|
|
1515
|
|
|
|
|
|
|
Like C<< List::Util::sample() >>. |
1516
|
|
|
|
|
|
|
|
1517
|
|
|
|
|
|
|
=cut |
1518
|
|
|
|
|
|
|
|
1519
|
|
|
|
|
|
|
sub sample { |
1520
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1521
|
|
|
|
|
|
|
|
1522
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1523
|
0
|
|
|
|
|
0
|
@_ = do { |
1524
|
0
|
|
|
|
|
0
|
my ( %tmp, $tmp ); |
1525
|
|
|
|
|
|
|
|
1526
|
0
|
0
|
|
|
|
0
|
@_ == 2 |
1527
|
|
|
|
|
|
|
or Hydrogen::croak( |
1528
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
1529
|
|
|
|
|
|
|
"sample", scalar(@_), "expected exactly 2 parameters" ); |
1530
|
|
|
|
|
|
|
|
1531
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
1532
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
1533
|
|
|
|
|
|
|
or Hydrogen::croak( |
1534
|
|
|
|
|
|
|
"Type check failed in signature for sample: %s should be %s", |
1535
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
1536
|
|
|
|
|
|
|
|
1537
|
|
|
|
|
|
|
# Parameter $_[1] (type: Int) |
1538
|
|
|
|
|
|
|
( |
1539
|
0
|
0
|
|
|
|
0
|
do { |
1540
|
0
|
|
|
|
|
0
|
my $tmp = $_[1]; |
1541
|
0
|
0
|
0
|
|
|
0
|
defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/; |
1542
|
|
|
|
|
|
|
} |
1543
|
|
|
|
|
|
|
) |
1544
|
|
|
|
|
|
|
or Hydrogen::croak( |
1545
|
|
|
|
|
|
|
"Type check failed in signature for sample: %s should be %s", |
1546
|
|
|
|
|
|
|
"\$_[1]", "Int" ); |
1547
|
|
|
|
|
|
|
|
1548
|
0
|
|
|
|
|
0
|
(@_); |
1549
|
|
|
|
|
|
|
}; |
1550
|
0
|
|
|
|
|
0
|
&List::Util::sample( $_[1], @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1551
|
|
|
|
|
|
|
} |
1552
|
|
|
|
|
|
|
|
1553
|
|
|
|
|
|
|
=head2 C<< set( $arrayref, $index, $value ) >> |
1554
|
|
|
|
|
|
|
|
1555
|
|
|
|
|
|
|
Additional arguments: B<< Int >>, B<< Any >>. |
1556
|
|
|
|
|
|
|
|
1557
|
|
|
|
|
|
|
Sets the element with the given index to the supplied value. |
1558
|
|
|
|
|
|
|
|
1559
|
|
|
|
|
|
|
=cut |
1560
|
|
|
|
|
|
|
|
1561
|
|
|
|
|
|
|
sub set { |
1562
|
1
|
|
|
1
|
1
|
8339
|
my $__REF__ = \$_[0]; |
1563
|
|
|
|
|
|
|
|
1564
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1565
|
1
|
|
|
|
|
2
|
@_ = do { |
1566
|
1
|
|
|
|
|
2
|
my ( %tmp, $tmp ); |
1567
|
|
|
|
|
|
|
|
1568
|
1
|
50
|
|
|
|
6
|
@_ == 3 |
1569
|
|
|
|
|
|
|
or Hydrogen::croak( |
1570
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
1571
|
|
|
|
|
|
|
"set", scalar(@_), "expected exactly 3 parameters" ); |
1572
|
|
|
|
|
|
|
|
1573
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
1574
|
1
|
50
|
|
|
|
6
|
( ref( $_[0] ) eq 'ARRAY' ) |
1575
|
|
|
|
|
|
|
or Hydrogen::croak( |
1576
|
|
|
|
|
|
|
"Type check failed in signature for set: %s should be %s", |
1577
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
1578
|
|
|
|
|
|
|
|
1579
|
|
|
|
|
|
|
# Parameter $_[1] (type: Int) |
1580
|
|
|
|
|
|
|
( |
1581
|
1
|
50
|
|
|
|
2
|
do { |
1582
|
1
|
|
|
|
|
2
|
my $tmp = $_[1]; |
1583
|
1
|
50
|
33
|
|
|
27
|
defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/; |
1584
|
|
|
|
|
|
|
} |
1585
|
|
|
|
|
|
|
) |
1586
|
|
|
|
|
|
|
or Hydrogen::croak( |
1587
|
|
|
|
|
|
|
"Type check failed in signature for set: %s should be %s", |
1588
|
|
|
|
|
|
|
"\$_[1]", "Int" ); |
1589
|
|
|
|
|
|
|
|
1590
|
|
|
|
|
|
|
# Parameter $_[2] (type: Any) |
1591
|
1
|
|
|
|
|
2
|
1; # ... nothing to do |
1592
|
|
|
|
|
|
|
|
1593
|
1
|
|
|
|
|
4
|
(@_); |
1594
|
|
|
|
|
|
|
}; |
1595
|
1
|
|
|
|
|
3
|
1; |
1596
|
1
|
|
|
|
|
4
|
($$__REF__)->[ $_[1] ] = $_[2]; |
1597
|
|
|
|
|
|
|
} |
1598
|
|
|
|
|
|
|
|
1599
|
|
|
|
|
|
|
=head2 C<< shallow_clone( $arrayref ) >> |
1600
|
|
|
|
|
|
|
|
1601
|
|
|
|
|
|
|
Creates a new arrayref with the same elements as the original. |
1602
|
|
|
|
|
|
|
|
1603
|
|
|
|
|
|
|
=cut |
1604
|
|
|
|
|
|
|
|
1605
|
|
|
|
|
|
|
sub shallow_clone { |
1606
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1607
|
|
|
|
|
|
|
|
1608
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1609
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
1610
|
|
|
|
|
|
|
or |
1611
|
|
|
|
|
|
|
Hydrogen::croak( "Wrong number of parameters for shallow_clone; usage: " |
1612
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::shallow_clone( \$arrayref )" ); |
1613
|
0
|
|
|
|
|
0
|
[ @{$$__REF__} ]; |
|
0
|
|
|
|
|
0
|
|
1614
|
|
|
|
|
|
|
} |
1615
|
|
|
|
|
|
|
|
1616
|
|
|
|
|
|
|
=head2 C<< shift( $arrayref ) >> |
1617
|
|
|
|
|
|
|
|
1618
|
|
|
|
|
|
|
Removes an element from the start of the array and returns it. |
1619
|
|
|
|
|
|
|
|
1620
|
|
|
|
|
|
|
=cut |
1621
|
|
|
|
|
|
|
|
1622
|
|
|
|
|
|
|
sub shift { |
1623
|
2
|
|
|
2
|
1
|
6472
|
my $__REF__ = \$_[0]; |
1624
|
|
|
|
|
|
|
|
1625
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1626
|
2
|
50
|
|
|
|
9
|
@_ == 1 |
1627
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for shift; usage: " |
1628
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::shift( \$arrayref )" ); |
1629
|
2
|
|
|
|
|
3
|
1; |
1630
|
2
|
|
|
|
|
4
|
shift( @{$$__REF__} ); |
|
2
|
|
|
|
|
11
|
|
1631
|
|
|
|
|
|
|
} |
1632
|
|
|
|
|
|
|
|
1633
|
|
|
|
|
|
|
=head2 C<< shuffle( $arrayref ) >> |
1634
|
|
|
|
|
|
|
|
1635
|
|
|
|
|
|
|
Returns the array in a random order; can be called in list context or scalar context and will return an arrayref in the latter case. |
1636
|
|
|
|
|
|
|
|
1637
|
|
|
|
|
|
|
=cut |
1638
|
|
|
|
|
|
|
|
1639
|
|
|
|
|
|
|
sub shuffle { |
1640
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1641
|
|
|
|
|
|
|
|
1642
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1643
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
1644
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for shuffle; usage: " |
1645
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::shuffle( \$arrayref )" ); |
1646
|
0
|
|
|
|
|
0
|
my @shv_return = List::Util::shuffle( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1647
|
0
|
0
|
|
|
|
0
|
wantarray ? @shv_return : \@shv_return; |
1648
|
|
|
|
|
|
|
} |
1649
|
|
|
|
|
|
|
|
1650
|
|
|
|
|
|
|
=head2 C<< shuffle_in_place( $arrayref ) >> |
1651
|
|
|
|
|
|
|
|
1652
|
|
|
|
|
|
|
Rearranges the array in a random order, and changes the original value to point to the new order. |
1653
|
|
|
|
|
|
|
|
1654
|
|
|
|
|
|
|
=cut |
1655
|
|
|
|
|
|
|
|
1656
|
|
|
|
|
|
|
sub shuffle_in_place { |
1657
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1658
|
|
|
|
|
|
|
|
1659
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1660
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
1661
|
|
|
|
|
|
|
or Hydrogen::croak( |
1662
|
|
|
|
|
|
|
"Wrong number of parameters for shuffle_in_place; usage: " |
1663
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::shuffle_in_place( \$arrayref )" ); |
1664
|
0
|
|
|
|
|
0
|
1; |
1665
|
0
|
|
|
|
|
0
|
my @shv_return = List::Util::shuffle( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1666
|
0
|
|
|
|
|
0
|
( @{ $_[0] } = @{ +\@shv_return } ); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1667
|
|
|
|
|
|
|
} |
1668
|
|
|
|
|
|
|
|
1669
|
|
|
|
|
|
|
=head2 C<< sort( $arrayref, $coderef? ) >> |
1670
|
|
|
|
|
|
|
|
1671
|
|
|
|
|
|
|
Additional arguments: B<< Optional[CodeRef] >>. |
1672
|
|
|
|
|
|
|
|
1673
|
|
|
|
|
|
|
Like C from L. |
1674
|
|
|
|
|
|
|
|
1675
|
|
|
|
|
|
|
=cut |
1676
|
|
|
|
|
|
|
|
1677
|
|
|
|
|
|
|
{ |
1678
|
|
|
|
|
|
|
my $__signature; |
1679
|
|
|
|
|
|
|
|
1680
|
|
|
|
|
|
|
sub sort { |
1681
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1682
|
|
|
|
|
|
|
|
1683
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1684
|
|
|
|
|
|
|
$__signature ||= sub { |
1685
|
0
|
|
|
0
|
|
0
|
my ( %tmp, $tmp ); |
1686
|
|
|
|
|
|
|
|
1687
|
0
|
0
|
0
|
|
|
0
|
@_ >= 1 && @_ <= 2 |
1688
|
|
|
|
|
|
|
or Hydrogen::croak( |
1689
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
1690
|
|
|
|
|
|
|
"sort", scalar(@_), "expected exactly 1 parameters" ); |
1691
|
|
|
|
|
|
|
|
1692
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
1693
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
1694
|
|
|
|
|
|
|
or Hydrogen::croak( |
1695
|
|
|
|
|
|
|
"Type check failed in signature for sort: %s should be %s", |
1696
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
1697
|
|
|
|
|
|
|
|
1698
|
|
|
|
|
|
|
# Parameter $_[1] (type: Optional[CodeRef]) |
1699
|
0
|
0
|
|
|
|
0
|
$#_ >= 1 |
1700
|
|
|
|
|
|
|
or return (@_); |
1701
|
0
|
0
|
|
|
|
0
|
( ref( $_[1] ) eq 'CODE' ) |
1702
|
|
|
|
|
|
|
or Hydrogen::croak( |
1703
|
|
|
|
|
|
|
"Type check failed in signature for sort: %s should be %s", |
1704
|
|
|
|
|
|
|
"\$_[1]", "Optional[CodeRef]" ); |
1705
|
|
|
|
|
|
|
|
1706
|
0
|
|
|
|
|
0
|
(@_); |
1707
|
0
|
|
0
|
|
|
0
|
}; |
1708
|
0
|
|
|
|
|
0
|
@_ = &$__signature; |
1709
|
|
|
|
|
|
|
my @shv_return = |
1710
|
|
|
|
|
|
|
$_[1] |
1711
|
0
|
|
|
|
|
0
|
? ( sort { $_[1]->( $a, $b ) } @{$$__REF__} ) |
|
0
|
|
|
|
|
0
|
|
1712
|
0
|
0
|
|
|
|
0
|
: ( sort @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1713
|
|
|
|
|
|
|
} |
1714
|
|
|
|
|
|
|
} |
1715
|
|
|
|
|
|
|
|
1716
|
|
|
|
|
|
|
=head2 C<< sort_in_place( $arrayref, $coderef? ) >> |
1717
|
|
|
|
|
|
|
|
1718
|
|
|
|
|
|
|
Additional arguments: B<< Optional[CodeRef] >>. |
1719
|
|
|
|
|
|
|
|
1720
|
|
|
|
|
|
|
Like C from L, but changes the original value to point to the newly sorted array. |
1721
|
|
|
|
|
|
|
|
1722
|
|
|
|
|
|
|
=cut |
1723
|
|
|
|
|
|
|
|
1724
|
|
|
|
|
|
|
{ |
1725
|
|
|
|
|
|
|
my $__signature; |
1726
|
|
|
|
|
|
|
|
1727
|
|
|
|
|
|
|
sub sort_in_place { |
1728
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1729
|
|
|
|
|
|
|
|
1730
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1731
|
|
|
|
|
|
|
$__signature ||= sub { |
1732
|
0
|
|
|
0
|
|
0
|
my ( %tmp, $tmp ); |
1733
|
|
|
|
|
|
|
|
1734
|
0
|
0
|
0
|
|
|
0
|
@_ >= 1 && @_ <= 2 |
1735
|
|
|
|
|
|
|
or Hydrogen::croak( |
1736
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
1737
|
|
|
|
|
|
|
"sort_in_place", scalar(@_), "expected exactly 1 parameters" ); |
1738
|
|
|
|
|
|
|
|
1739
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
1740
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
1741
|
|
|
|
|
|
|
or Hydrogen::croak( |
1742
|
|
|
|
|
|
|
"Type check failed in signature for sort_in_place: %s should be %s", |
1743
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" |
1744
|
|
|
|
|
|
|
); |
1745
|
|
|
|
|
|
|
|
1746
|
|
|
|
|
|
|
# Parameter $_[1] (type: Optional[CodeRef]) |
1747
|
0
|
0
|
|
|
|
0
|
$#_ >= 1 |
1748
|
|
|
|
|
|
|
or return (@_); |
1749
|
0
|
0
|
|
|
|
0
|
( ref( $_[1] ) eq 'CODE' ) |
1750
|
|
|
|
|
|
|
or Hydrogen::croak( |
1751
|
|
|
|
|
|
|
"Type check failed in signature for sort_in_place: %s should be %s", |
1752
|
|
|
|
|
|
|
"\$_[1]", "Optional[CodeRef]" |
1753
|
|
|
|
|
|
|
); |
1754
|
|
|
|
|
|
|
|
1755
|
0
|
|
|
|
|
0
|
(@_); |
1756
|
0
|
|
0
|
|
|
0
|
}; |
1757
|
0
|
|
|
|
|
0
|
@_ = &$__signature; |
1758
|
0
|
|
|
|
|
0
|
1; |
1759
|
|
|
|
|
|
|
my @shv_return = |
1760
|
|
|
|
|
|
|
$_[1] |
1761
|
0
|
|
|
|
|
0
|
? ( sort { $_[1]->( $a, $b ) } @{$$__REF__} ) |
|
0
|
|
|
|
|
0
|
|
1762
|
0
|
0
|
|
|
|
0
|
: ( sort @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1763
|
0
|
|
|
|
|
0
|
( @{ $_[0] } = @{ +\@shv_return } ); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1764
|
|
|
|
|
|
|
} |
1765
|
|
|
|
|
|
|
} |
1766
|
|
|
|
|
|
|
|
1767
|
|
|
|
|
|
|
=head2 C<< splice( $arrayref, $index, $length, @values ) >> |
1768
|
|
|
|
|
|
|
|
1769
|
|
|
|
|
|
|
Like C from L. |
1770
|
|
|
|
|
|
|
|
1771
|
|
|
|
|
|
|
=cut |
1772
|
|
|
|
|
|
|
|
1773
|
|
|
|
|
|
|
sub splice { |
1774
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1775
|
|
|
|
|
|
|
|
1776
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1777
|
0
|
0
|
|
|
|
0
|
@_ >= 2 |
1778
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for splice; usage: " |
1779
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::splice( \$arrayref, \$index, \$length, \@values )" |
1780
|
|
|
|
|
|
|
); |
1781
|
0
|
0
|
|
|
|
0
|
if ( ( @_ - 1 ) >= 1 ) { |
1782
|
0
|
|
|
|
|
0
|
do { |
1783
|
|
|
|
|
|
|
( |
1784
|
0
|
0
|
|
|
|
0
|
do { |
1785
|
0
|
|
|
|
|
0
|
my $tmp = $_[1]; |
1786
|
0
|
0
|
0
|
|
|
0
|
defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/; |
1787
|
|
|
|
|
|
|
} |
1788
|
|
|
|
|
|
|
) |
1789
|
|
|
|
|
|
|
or Hydrogen::croak( |
1790
|
|
|
|
|
|
|
"Type check failed for splice: expected %s, got value %s", |
1791
|
|
|
|
|
|
|
"Int", $_[1] ); |
1792
|
0
|
|
|
|
|
0
|
$_[1]; |
1793
|
|
|
|
|
|
|
}; |
1794
|
|
|
|
|
|
|
} |
1795
|
|
|
|
|
|
|
; |
1796
|
0
|
0
|
|
|
|
0
|
if ( ( @_ - 1 ) >= 2 ) { |
1797
|
0
|
|
|
|
|
0
|
do { |
1798
|
|
|
|
|
|
|
( |
1799
|
0
|
0
|
|
|
|
0
|
do { |
1800
|
0
|
|
|
|
|
0
|
my $tmp = $_[2]; |
1801
|
0
|
0
|
0
|
|
|
0
|
defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/; |
1802
|
|
|
|
|
|
|
} |
1803
|
|
|
|
|
|
|
) |
1804
|
|
|
|
|
|
|
or Hydrogen::croak( |
1805
|
|
|
|
|
|
|
"Type check failed for splice: expected %s, got value %s", |
1806
|
|
|
|
|
|
|
"Int", $_[2] ); |
1807
|
0
|
|
|
|
|
0
|
$_[2]; |
1808
|
|
|
|
|
|
|
}; |
1809
|
|
|
|
|
|
|
} |
1810
|
0
|
|
|
|
|
0
|
my ( $shv_index, $shv_length, @shv_values ) = @_[ 1 .. $#_ ]; |
1811
|
0
|
|
|
|
|
0
|
splice( @{$$__REF__}, $shv_index, $shv_length, @shv_values ); |
|
0
|
|
|
|
|
0
|
|
1812
|
|
|
|
|
|
|
} |
1813
|
|
|
|
|
|
|
|
1814
|
|
|
|
|
|
|
=head2 C<< sum( $arrayref ) >> |
1815
|
|
|
|
|
|
|
|
1816
|
|
|
|
|
|
|
Like C<< List::Util::sum0() >>. |
1817
|
|
|
|
|
|
|
|
1818
|
|
|
|
|
|
|
=cut |
1819
|
|
|
|
|
|
|
|
1820
|
|
|
|
|
|
|
sub sum { |
1821
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1822
|
|
|
|
|
|
|
|
1823
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1824
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
1825
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for sum; usage: " |
1826
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::sum( \$arrayref )" ); |
1827
|
0
|
|
|
|
|
0
|
&List::Util::sum( 0, @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1828
|
|
|
|
|
|
|
} |
1829
|
|
|
|
|
|
|
|
1830
|
|
|
|
|
|
|
=head2 C<< tail( $arrayref, $count ) >> |
1831
|
|
|
|
|
|
|
|
1832
|
|
|
|
|
|
|
Additional arguments: B<< Int >>. |
1833
|
|
|
|
|
|
|
|
1834
|
|
|
|
|
|
|
Returns the last C<< $count >> elements of the array in list context. |
1835
|
|
|
|
|
|
|
|
1836
|
|
|
|
|
|
|
=cut |
1837
|
|
|
|
|
|
|
|
1838
|
|
|
|
|
|
|
sub tail { |
1839
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1840
|
|
|
|
|
|
|
|
1841
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1842
|
0
|
|
|
|
|
0
|
@_ = do { |
1843
|
0
|
|
|
|
|
0
|
my ( %tmp, $tmp ); |
1844
|
|
|
|
|
|
|
|
1845
|
0
|
0
|
|
|
|
0
|
@_ == 2 |
1846
|
|
|
|
|
|
|
or Hydrogen::croak( |
1847
|
|
|
|
|
|
|
"Wrong number of parameters in signature for %s: got %d, %s", |
1848
|
|
|
|
|
|
|
"tail", scalar(@_), "expected exactly 2 parameters" ); |
1849
|
|
|
|
|
|
|
|
1850
|
|
|
|
|
|
|
# Parameter $_[0] (type: ArrayRef) |
1851
|
0
|
0
|
|
|
|
0
|
( ref( $_[0] ) eq 'ARRAY' ) |
1852
|
|
|
|
|
|
|
or Hydrogen::croak( |
1853
|
|
|
|
|
|
|
"Type check failed in signature for tail: %s should be %s", |
1854
|
|
|
|
|
|
|
"\$_[0]", "ArrayRef" ); |
1855
|
|
|
|
|
|
|
|
1856
|
|
|
|
|
|
|
# Parameter $_[1] (type: Int) |
1857
|
|
|
|
|
|
|
( |
1858
|
0
|
0
|
|
|
|
0
|
do { |
1859
|
0
|
|
|
|
|
0
|
my $tmp = $_[1]; |
1860
|
0
|
0
|
0
|
|
|
0
|
defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/; |
1861
|
|
|
|
|
|
|
} |
1862
|
|
|
|
|
|
|
) |
1863
|
|
|
|
|
|
|
or Hydrogen::croak( |
1864
|
|
|
|
|
|
|
"Type check failed in signature for tail: %s should be %s", |
1865
|
|
|
|
|
|
|
"\$_[1]", "Int" ); |
1866
|
|
|
|
|
|
|
|
1867
|
0
|
|
|
|
|
0
|
(@_); |
1868
|
|
|
|
|
|
|
}; |
1869
|
0
|
|
|
|
|
0
|
my $shv_count = $_[1]; |
1870
|
0
|
0
|
|
|
|
0
|
$shv_count = @{$$__REF__} if $shv_count > @{$$__REF__}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1871
|
0
|
0
|
|
|
|
0
|
$shv_count = @{$$__REF__} + $shv_count if $shv_count < 0; |
|
0
|
|
|
|
|
0
|
|
1872
|
0
|
|
|
|
|
0
|
my $shv_start = scalar( @{$$__REF__} ) - $shv_count; |
|
0
|
|
|
|
|
0
|
|
1873
|
0
|
|
|
|
|
0
|
my $shv_end = scalar( @{$$__REF__} ) - 1; |
|
0
|
|
|
|
|
0
|
|
1874
|
0
|
|
|
|
|
0
|
( @{$$__REF__} )[ $shv_start .. $shv_end ]; |
|
0
|
|
|
|
|
0
|
|
1875
|
|
|
|
|
|
|
} |
1876
|
|
|
|
|
|
|
|
1877
|
|
|
|
|
|
|
=head2 C<< uniq( $arrayref ) >> |
1878
|
|
|
|
|
|
|
|
1879
|
|
|
|
|
|
|
Returns the array filtered to remove duplicates; can be called in list context or scalar context and will return an arrayref in the latter case. |
1880
|
|
|
|
|
|
|
|
1881
|
|
|
|
|
|
|
=cut |
1882
|
|
|
|
|
|
|
|
1883
|
|
|
|
|
|
|
sub uniq { |
1884
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1885
|
|
|
|
|
|
|
|
1886
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1887
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
1888
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for uniq; usage: " |
1889
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::uniq( \$arrayref )" ); |
1890
|
0
|
|
|
|
|
0
|
my @shv_return = List::Util::uniq( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1891
|
0
|
0
|
|
|
|
0
|
wantarray ? @shv_return : \@shv_return; |
1892
|
|
|
|
|
|
|
} |
1893
|
|
|
|
|
|
|
|
1894
|
|
|
|
|
|
|
=head2 C<< uniq_in_place( $arrayref ) >> |
1895
|
|
|
|
|
|
|
|
1896
|
|
|
|
|
|
|
Filters the array to remove duplicates, and changes the original value to point to the filtered array. |
1897
|
|
|
|
|
|
|
|
1898
|
|
|
|
|
|
|
=cut |
1899
|
|
|
|
|
|
|
|
1900
|
|
|
|
|
|
|
sub uniq_in_place { |
1901
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1902
|
|
|
|
|
|
|
|
1903
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1904
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
1905
|
|
|
|
|
|
|
or |
1906
|
|
|
|
|
|
|
Hydrogen::croak( "Wrong number of parameters for uniq_in_place; usage: " |
1907
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::uniq_in_place( \$arrayref )" ); |
1908
|
0
|
|
|
|
|
0
|
1; |
1909
|
0
|
|
|
|
|
0
|
my @shv_return = List::Util::uniq( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1910
|
0
|
|
|
|
|
0
|
( @{ $_[0] } = @{ +\@shv_return } ); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1911
|
|
|
|
|
|
|
} |
1912
|
|
|
|
|
|
|
|
1913
|
|
|
|
|
|
|
=head2 C<< uniqnum( $arrayref ) >> |
1914
|
|
|
|
|
|
|
|
1915
|
|
|
|
|
|
|
Returns the array filtered to remove duplicates numerically; can be called in list context or scalar context and will return an arrayref in the latter case. |
1916
|
|
|
|
|
|
|
|
1917
|
|
|
|
|
|
|
=cut |
1918
|
|
|
|
|
|
|
|
1919
|
|
|
|
|
|
|
sub uniqnum { |
1920
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1921
|
|
|
|
|
|
|
|
1922
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1923
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
1924
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for uniqnum; usage: " |
1925
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::uniqnum( \$arrayref )" ); |
1926
|
0
|
|
|
|
|
0
|
my @shv_return = List::Util::uniqnum( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1927
|
0
|
0
|
|
|
|
0
|
wantarray ? @shv_return : \@shv_return; |
1928
|
|
|
|
|
|
|
} |
1929
|
|
|
|
|
|
|
|
1930
|
|
|
|
|
|
|
=head2 C<< uniqnum_in_place( $arrayref ) >> |
1931
|
|
|
|
|
|
|
|
1932
|
|
|
|
|
|
|
Filters the array to remove duplicates numerically, and changes the original value to point to the filtered array. |
1933
|
|
|
|
|
|
|
|
1934
|
|
|
|
|
|
|
=cut |
1935
|
|
|
|
|
|
|
|
1936
|
|
|
|
|
|
|
sub uniqnum_in_place { |
1937
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1938
|
|
|
|
|
|
|
|
1939
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1940
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
1941
|
|
|
|
|
|
|
or Hydrogen::croak( |
1942
|
|
|
|
|
|
|
"Wrong number of parameters for uniqnum_in_place; usage: " |
1943
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::uniqnum_in_place( \$arrayref )" ); |
1944
|
0
|
|
|
|
|
0
|
1; |
1945
|
0
|
|
|
|
|
0
|
my @shv_return = List::Util::uniqnum( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1946
|
0
|
|
|
|
|
0
|
( @{ $_[0] } = @{ +\@shv_return } ); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1947
|
|
|
|
|
|
|
} |
1948
|
|
|
|
|
|
|
|
1949
|
|
|
|
|
|
|
=head2 C<< uniqstr( $arrayref ) >> |
1950
|
|
|
|
|
|
|
|
1951
|
|
|
|
|
|
|
Returns the array filtered to remove duplicates stringwise; can be called in list context or scalar context and will return an arrayref in the latter case. |
1952
|
|
|
|
|
|
|
|
1953
|
|
|
|
|
|
|
=cut |
1954
|
|
|
|
|
|
|
|
1955
|
|
|
|
|
|
|
sub uniqstr { |
1956
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1957
|
|
|
|
|
|
|
|
1958
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1959
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
1960
|
|
|
|
|
|
|
or Hydrogen::croak( "Wrong number of parameters for uniqstr; usage: " |
1961
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::uniqstr( \$arrayref )" ); |
1962
|
0
|
|
|
|
|
0
|
my @shv_return = List::Util::uniqstr( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1963
|
0
|
0
|
|
|
|
0
|
wantarray ? @shv_return : \@shv_return; |
1964
|
|
|
|
|
|
|
} |
1965
|
|
|
|
|
|
|
|
1966
|
|
|
|
|
|
|
=head2 C<< uniqstr_in_place( $arrayref ) >> |
1967
|
|
|
|
|
|
|
|
1968
|
|
|
|
|
|
|
Filters the array to remove duplicates stringwise, and changes the original value to point to the filtered array. |
1969
|
|
|
|
|
|
|
|
1970
|
|
|
|
|
|
|
=cut |
1971
|
|
|
|
|
|
|
|
1972
|
|
|
|
|
|
|
sub uniqstr_in_place { |
1973
|
0
|
|
|
0
|
1
|
0
|
my $__REF__ = \$_[0]; |
1974
|
|
|
|
|
|
|
|
1975
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1976
|
0
|
0
|
|
|
|
0
|
@_ == 1 |
1977
|
|
|
|
|
|
|
or Hydrogen::croak( |
1978
|
|
|
|
|
|
|
"Wrong number of parameters for uniqstr_in_place; usage: " |
1979
|
|
|
|
|
|
|
. "Hydrogen::ArrayRef::uniqstr_in_place( \$arrayref )" ); |
1980
|
0
|
|
|
|
|
0
|
1; |
1981
|
0
|
|
|
|
|
0
|
my @shv_return = List::Util::uniqstr( @{$$__REF__} ); |
|
0
|
|
|
|
|
0
|
|
1982
|
0
|
|
|
|
|
0
|
( @{ $_[0] } = @{ +\@shv_return } ); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1983
|
|
|
|
|
|
|
} |
1984
|
|
|
|
|
|
|
|
1985
|
|
|
|
|
|
|
=head2 C<< unshift( $arrayref, @values ) >> |
1986
|
|
|
|
|
|
|
|
1987
|
|
|
|
|
|
|
Adds an element to the start of the array. |
1988
|
|
|
|
|
|
|
|
1989
|
|
|
|
|
|
|
=cut |
1990
|
|
|
|
|
|
|
|
1991
|
|
|
|
|
|
|
sub unshift { |
1992
|
1
|
|
|
1
|
1
|
38175
|
my $__REF__ = \$_[0]; |
1993
|
|
|
|
|
|
|
|
1994
|
|
|
|
|
|
|
package Hydrogen::ArrayRef::__SANDBOX__; |
1995
|
1
|
|
|
|
|
3
|
1; |
1996
|
1
|
|
|
|
|
4
|
unshift( @{$$__REF__}, @_[ 1 .. $#_ ] ); |
|
1
|
|
|
|
|
7
|
|
1997
|
|
|
|
|
|
|
} |
1998
|
|
|
|
|
|
|
|
1999
|
|
|
|
|
|
|
1; |
2000
|
|
|
|
|
|
|
|
2001
|
|
|
|
|
|
|
=head1 EXPORT |
2002
|
|
|
|
|
|
|
|
2003
|
|
|
|
|
|
|
No functions are exported by this module by default. To import them all (this is usually a bad idea), use: |
2004
|
|
|
|
|
|
|
|
2005
|
|
|
|
|
|
|
use Hydrogen::ArrayRef -all; |
2006
|
|
|
|
|
|
|
|
2007
|
|
|
|
|
|
|
To import a particular function, use: |
2008
|
|
|
|
|
|
|
|
2009
|
|
|
|
|
|
|
use Hydrogen::ArrayRef 'all_true'; |
2010
|
|
|
|
|
|
|
|
2011
|
|
|
|
|
|
|
To rename functions: |
2012
|
|
|
|
|
|
|
|
2013
|
|
|
|
|
|
|
use Hydrogen::ArrayRef 'all_true' => { -as => 'myfunc' }; |
2014
|
|
|
|
|
|
|
|
2015
|
|
|
|
|
|
|
On Perl 5.37.2+, you can import lexically: |
2016
|
|
|
|
|
|
|
|
2017
|
|
|
|
|
|
|
use Hydrogen::ArrayRef -lexical, 'all_true'; |
2018
|
|
|
|
|
|
|
|
2019
|
|
|
|
|
|
|
See L for more hints on importing. |
2020
|
|
|
|
|
|
|
|
2021
|
|
|
|
|
|
|
=head1 BUGS |
2022
|
|
|
|
|
|
|
|
2023
|
|
|
|
|
|
|
Please report any bugs to |
2024
|
|
|
|
|
|
|
L. |
2025
|
|
|
|
|
|
|
|
2026
|
|
|
|
|
|
|
=head1 SEE ALSO |
2027
|
|
|
|
|
|
|
|
2028
|
|
|
|
|
|
|
L, |
2029
|
|
|
|
|
|
|
L, |
2030
|
|
|
|
|
|
|
L, |
2031
|
|
|
|
|
|
|
L, |
2032
|
|
|
|
|
|
|
L, |
2033
|
|
|
|
|
|
|
L, |
2034
|
|
|
|
|
|
|
L. |
2035
|
|
|
|
|
|
|
|
2036
|
|
|
|
|
|
|
=head1 AUTHOR |
2037
|
|
|
|
|
|
|
|
2038
|
|
|
|
|
|
|
Toby Inkster Etobyink@cpan.orgE. |
2039
|
|
|
|
|
|
|
|
2040
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
2041
|
|
|
|
|
|
|
|
2042
|
|
|
|
|
|
|
This software is copyright (c) 2022 by Toby Inkster. |
2043
|
|
|
|
|
|
|
|
2044
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
2045
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
2046
|
|
|
|
|
|
|
|
2047
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTIES |
2048
|
|
|
|
|
|
|
|
2049
|
|
|
|
|
|
|
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
2050
|
|
|
|
|
|
|
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
2051
|
|
|
|
|
|
|
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
2052
|
|
|
|
|
|
|
|