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