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