| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Acme::Chef::Container; |
|
3
|
|
|
|
|
|
|
|
|
4
|
10
|
|
|
10
|
|
46
|
use strict; |
|
|
10
|
|
|
|
|
13
|
|
|
|
10
|
|
|
|
|
310
|
|
|
5
|
10
|
|
|
10
|
|
44
|
use warnings; |
|
|
10
|
|
|
|
|
14
|
|
|
|
10
|
|
|
|
|
280
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
10
|
|
|
10
|
|
51
|
use Carp; |
|
|
10
|
|
|
|
|
16
|
|
|
|
10
|
|
|
|
|
611
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
10
|
|
|
10
|
|
55
|
use Acme::Chef::Ingredient; |
|
|
10
|
|
|
|
|
15
|
|
|
|
10
|
|
|
|
|
256
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
10
|
|
|
10
|
|
52
|
use vars qw/$VERSION/; |
|
|
10
|
|
|
|
|
11
|
|
|
|
10
|
|
|
|
|
11852
|
|
|
12
|
|
|
|
|
|
|
$VERSION = '1.00'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Acme::Chef::Container - Internal module used by Acme::Chef |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Acme::Chef; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Please see L; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 METHODS |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This is a list of methods in this package. |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=over 2 |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=item new |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
This is the Acme::Chef::Container constructor. Creates a new |
|
37
|
|
|
|
|
|
|
Acme::Chef::Container object. All arguments are treated as key/value pairs for |
|
38
|
|
|
|
|
|
|
object attributes. |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new { |
|
43
|
279
|
|
|
279
|
1
|
270
|
my $proto = shift; |
|
44
|
279
|
|
66
|
|
|
630
|
my $class = ref $proto || $proto; |
|
45
|
|
|
|
|
|
|
|
|
46
|
279
|
|
|
|
|
316
|
my $self = {}; |
|
47
|
|
|
|
|
|
|
|
|
48
|
279
|
100
|
|
|
|
540
|
if (ref $proto) { |
|
49
|
244
|
|
|
|
|
545
|
%$self = %$proto; |
|
50
|
244
|
|
|
|
|
253
|
$self->{contents} = [ map { $_->new() } @{$self -> {contents}} ]; |
|
|
303
|
|
|
|
|
518
|
|
|
|
244
|
|
|
|
|
420
|
|
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
279
|
|
|
|
|
922
|
%$self = ( |
|
54
|
|
|
|
|
|
|
contents => [], |
|
55
|
|
|
|
|
|
|
%$self, |
|
56
|
|
|
|
|
|
|
@_, |
|
57
|
|
|
|
|
|
|
); |
|
58
|
|
|
|
|
|
|
|
|
59
|
279
|
|
|
|
|
863
|
return bless $self => $class; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item put |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This method implements the 'put' command. Please refer to L for |
|
66
|
|
|
|
|
|
|
details. |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub put { |
|
71
|
943
|
|
|
943
|
1
|
913
|
my $self = shift; |
|
72
|
|
|
|
|
|
|
|
|
73
|
943
|
|
|
|
|
1204
|
my @ingredients = @_; |
|
74
|
|
|
|
|
|
|
|
|
75
|
943
|
|
|
|
|
1303
|
push @{$self->{contents}}, $_->new() for @ingredients; |
|
|
943
|
|
|
|
|
1865
|
|
|
76
|
|
|
|
|
|
|
|
|
77
|
943
|
|
|
|
|
1794
|
return $self; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item fold |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This method implements the 'fold' command. Please refer to L for |
|
83
|
|
|
|
|
|
|
details. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub fold { |
|
88
|
111
|
|
|
111
|
1
|
95
|
my $self = shift; |
|
89
|
|
|
|
|
|
|
|
|
90
|
111
|
|
|
|
|
107
|
my $ingredient = shift; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
croak "Invalid operation on empty container: fold." |
|
93
|
111
|
50
|
|
|
|
81
|
unless @{$self->{contents}}; |
|
|
111
|
|
|
|
|
212
|
|
|
94
|
|
|
|
|
|
|
|
|
95
|
111
|
|
|
|
|
98
|
my $new_val = pop @{ $self->{contents} }; |
|
|
111
|
|
|
|
|
129
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
111
|
|
|
|
|
172
|
$ingredient->value( $new_val->value() ); |
|
98
|
|
|
|
|
|
|
|
|
99
|
111
|
|
|
|
|
252
|
return $ingredient; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item add |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This method implements the 'add' command. Please refer to L for |
|
105
|
|
|
|
|
|
|
details. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub add { |
|
110
|
3
|
|
|
3
|
1
|
4
|
my $self = shift; |
|
111
|
|
|
|
|
|
|
|
|
112
|
3
|
|
|
|
|
4
|
my $ingredient = shift; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
croak "Invalid operation on empty container: add." |
|
115
|
3
|
50
|
|
|
|
5
|
unless @{$self->{contents}}; |
|
|
3
|
|
|
|
|
11
|
|
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$self->{contents}->[-1]->value( |
|
118
|
3
|
|
|
|
|
10
|
$self->{contents}->[-1]->value() + |
|
119
|
|
|
|
|
|
|
$ingredient->value() |
|
120
|
|
|
|
|
|
|
); |
|
121
|
|
|
|
|
|
|
|
|
122
|
3
|
|
|
|
|
7
|
return $ingredient; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item remove |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This method implements the 'remove' command. Please refer to L for |
|
128
|
|
|
|
|
|
|
details. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub remove { |
|
134
|
168
|
|
|
168
|
1
|
141
|
my $self = shift; |
|
135
|
|
|
|
|
|
|
|
|
136
|
168
|
|
|
|
|
133
|
my $ingredient = shift; |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
croak "Invalid operation on empty container: remove." |
|
139
|
168
|
50
|
|
|
|
151
|
unless @{$self->{contents}}; |
|
|
168
|
|
|
|
|
297
|
|
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$self->{contents}->[-1]->value( |
|
142
|
168
|
|
|
|
|
303
|
$self->{contents}->[-1]->value() - |
|
143
|
|
|
|
|
|
|
$ingredient->value() |
|
144
|
|
|
|
|
|
|
); |
|
145
|
|
|
|
|
|
|
|
|
146
|
168
|
|
|
|
|
211
|
return $ingredient; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item combine |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This method implements the 'combine' command. Please refer to L for |
|
153
|
|
|
|
|
|
|
details. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub combine { |
|
158
|
240
|
|
|
240
|
1
|
192
|
my $self = shift; |
|
159
|
|
|
|
|
|
|
|
|
160
|
240
|
|
|
|
|
177
|
my $ingredient = shift; |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
croak "Invalid operation on empty container: combine." |
|
163
|
240
|
50
|
|
|
|
195
|
unless @{$self->{contents}}; |
|
|
240
|
|
|
|
|
442
|
|
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
$self->{contents}->[-1]->value( |
|
166
|
240
|
|
|
|
|
463
|
$self->{contents}->[-1]->value() * |
|
167
|
|
|
|
|
|
|
$ingredient->value() |
|
168
|
|
|
|
|
|
|
); |
|
169
|
|
|
|
|
|
|
|
|
170
|
240
|
|
|
|
|
392
|
return $ingredient; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item divide |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This method implements the 'divide' command. Please refer to L for |
|
177
|
|
|
|
|
|
|
details. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub divide { |
|
182
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
183
|
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
0
|
my $ingredient = shift; |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
croak "Invalid operation on empty container: divide." |
|
187
|
0
|
0
|
|
|
|
0
|
unless @{$self->{contents}}; |
|
|
0
|
|
|
|
|
0
|
|
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
$self->{contents}->[-1]->value( |
|
190
|
0
|
|
|
|
|
0
|
$self->{contents}->[-1]->value() / |
|
191
|
|
|
|
|
|
|
$ingredient->value() |
|
192
|
|
|
|
|
|
|
); |
|
193
|
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
0
|
return $ingredient; |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=item put_sum |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
This method takes a number of Acme::Chef::Ingredient objects as arguments and |
|
200
|
|
|
|
|
|
|
creates and 'puts' the sum of the ingredients. |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Please refer to L for details. |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub put_sum { |
|
207
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
208
|
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
0
|
my @ingredients = @_; |
|
210
|
|
|
|
|
|
|
|
|
211
|
0
|
|
|
|
|
0
|
my $sum = 0; |
|
212
|
0
|
|
|
|
|
0
|
$sum += $_->value() for @ingredients; |
|
213
|
|
|
|
|
|
|
|
|
214
|
0
|
|
|
|
|
0
|
my $ingredient = Acme::Chef::Ingredient->new( |
|
215
|
|
|
|
|
|
|
name => '', |
|
216
|
|
|
|
|
|
|
value => $sum, |
|
217
|
|
|
|
|
|
|
measure => '', |
|
218
|
|
|
|
|
|
|
type => 'dry', |
|
219
|
|
|
|
|
|
|
); |
|
220
|
|
|
|
|
|
|
|
|
221
|
0
|
|
|
|
|
0
|
$self->put($ingredient); |
|
222
|
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
0
|
return $ingredient; |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=item liquify_contents |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
This method implements the 'liquify' command for all ingredients. |
|
229
|
|
|
|
|
|
|
Please refer to L for details. |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=cut |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub liquify_contents { |
|
234
|
21
|
|
|
21
|
1
|
30
|
my $self = shift; |
|
235
|
|
|
|
|
|
|
|
|
236
|
21
|
|
|
|
|
20
|
foreach my $ingredient (@{$self->{contents}}) { |
|
|
21
|
|
|
|
|
41
|
|
|
237
|
174
|
|
|
|
|
244
|
$ingredient->liquify(); |
|
238
|
|
|
|
|
|
|
} |
|
239
|
|
|
|
|
|
|
|
|
240
|
21
|
|
|
|
|
27
|
return $self; |
|
241
|
|
|
|
|
|
|
} |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=item stir_time |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
This method implements the 'stir' command. |
|
246
|
|
|
|
|
|
|
First argument should be the depth ("time") to stir. |
|
247
|
|
|
|
|
|
|
Please refer to L for details. |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
sub stir_time { |
|
252
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
253
|
|
|
|
|
|
|
|
|
254
|
0
|
|
|
|
|
0
|
my $depth = shift; |
|
255
|
|
|
|
|
|
|
|
|
256
|
0
|
0
|
|
|
|
0
|
return $self unless scalar @{$self->{contents}}; |
|
|
0
|
|
|
|
|
0
|
|
|
257
|
|
|
|
|
|
|
|
|
258
|
0
|
0
|
|
|
|
0
|
$depth = $#{$self->{contents}} if $depth > $#{$self->{contents}}; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
259
|
|
|
|
|
|
|
|
|
260
|
0
|
|
|
|
|
0
|
my $top = pop @{ $self->{contents} }; |
|
|
0
|
|
|
|
|
0
|
|
|
261
|
0
|
|
|
|
|
0
|
splice @{$self->{contents}}, (@{$self->{contents}}-$depth), 0, $top; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
262
|
|
|
|
|
|
|
|
|
263
|
0
|
|
|
|
|
0
|
return $self; |
|
264
|
|
|
|
|
|
|
} |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item stir_ingredient |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
This method implements the 'stir_ingredient' command. Please refer to |
|
270
|
|
|
|
|
|
|
L for details. |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=cut |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
sub stir_ingredient { |
|
276
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
277
|
|
|
|
|
|
|
|
|
278
|
0
|
|
|
|
|
0
|
my $ingredient = shift; |
|
279
|
|
|
|
|
|
|
|
|
280
|
0
|
|
|
|
|
0
|
$self->stir_time($ingredient->value()); |
|
281
|
|
|
|
|
|
|
|
|
282
|
0
|
|
|
|
|
0
|
return $self; |
|
283
|
|
|
|
|
|
|
} |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=item mix |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
This method implements the 'mix' command. Please refer to L for |
|
288
|
|
|
|
|
|
|
details. |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
Shuffles the container's contents. |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=cut |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
sub mix { |
|
295
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
296
|
|
|
|
|
|
|
|
|
297
|
0
|
|
|
|
|
0
|
_fisher_yates_shuffle( $self->{contents} ); |
|
298
|
|
|
|
|
|
|
|
|
299
|
0
|
|
|
|
|
0
|
return $self; |
|
300
|
|
|
|
|
|
|
} |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=item clean |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
This method implements the 'clean' command. Please refer to L for |
|
305
|
|
|
|
|
|
|
details. |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
Empties the container. |
|
308
|
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=cut |
|
310
|
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
sub clean { |
|
312
|
72
|
|
|
72
|
1
|
50
|
my $self = shift; |
|
313
|
|
|
|
|
|
|
|
|
314
|
72
|
|
|
|
|
59
|
@{$self->{contents}} = (); |
|
|
72
|
|
|
|
|
170
|
|
|
315
|
|
|
|
|
|
|
|
|
316
|
72
|
|
|
|
|
90
|
return $self; |
|
317
|
|
|
|
|
|
|
} |
|
318
|
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
=item pour |
|
321
|
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
This method implements the 'pour' command. Please refer to L for |
|
323
|
|
|
|
|
|
|
details. |
|
324
|
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
Returns the contained ingredients. |
|
326
|
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
=cut |
|
328
|
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
sub pour { |
|
330
|
131
|
|
|
131
|
1
|
131
|
my $self = shift; |
|
331
|
|
|
|
|
|
|
|
|
332
|
131
|
|
|
|
|
111
|
return @{ $self->{contents} }; |
|
|
131
|
|
|
|
|
314
|
|
|
333
|
|
|
|
|
|
|
} |
|
334
|
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
=item print |
|
337
|
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
Returns stringification of the object. |
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=cut |
|
341
|
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
sub print { |
|
343
|
35
|
|
|
35
|
1
|
48
|
my $self = shift; |
|
344
|
|
|
|
|
|
|
|
|
345
|
35
|
|
|
|
|
47
|
my $string = ''; |
|
346
|
|
|
|
|
|
|
|
|
347
|
35
|
|
|
|
|
49
|
foreach my $ingr ( reverse @{$self->{contents}} ) { |
|
|
35
|
|
|
|
|
70
|
|
|
348
|
248
|
100
|
|
|
|
383
|
if ($ingr->type() eq 'liquid') { |
|
349
|
174
|
|
|
|
|
248
|
$string .= chr( $ingr->value() ); |
|
350
|
|
|
|
|
|
|
} else { |
|
351
|
74
|
|
|
|
|
153
|
$string .= ' '.$ingr->value(); |
|
352
|
|
|
|
|
|
|
} |
|
353
|
|
|
|
|
|
|
} |
|
354
|
|
|
|
|
|
|
|
|
355
|
35
|
|
|
|
|
84
|
return $string; |
|
356
|
|
|
|
|
|
|
} |
|
357
|
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
# From the Perl FAQ: (NOT a method) |
|
360
|
|
|
|
|
|
|
# fisher_yates_shuffle( \@array ) : |
|
361
|
|
|
|
|
|
|
# generate a random permutation of @array in place |
|
362
|
|
|
|
|
|
|
sub _fisher_yates_shuffle { |
|
363
|
0
|
|
|
0
|
|
|
my $array = shift; |
|
364
|
0
|
|
|
|
|
|
my $i; |
|
365
|
0
|
|
|
|
|
|
for ($i = @$array; --$i; ) { |
|
366
|
0
|
|
|
|
|
|
my $j = int rand ($i+1); |
|
367
|
0
|
|
|
|
|
|
@$array[$i,$j] = @$array[$j,$i]; |
|
368
|
|
|
|
|
|
|
} |
|
369
|
|
|
|
|
|
|
} |
|
370
|
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
__END__ |