line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
725
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
41
|
|
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
46
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Permute::Named; |
6
|
|
|
|
|
|
|
BEGIN { |
7
|
1
|
|
|
1
|
|
18
|
$Permute::Named::VERSION = '1.100980'; |
8
|
|
|
|
|
|
|
} |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: permute multiple-valued key-value pairs |
11
|
1
|
|
|
1
|
|
1343
|
use Storable 'dclone'; |
|
1
|
|
|
|
|
9854
|
|
|
1
|
|
|
|
|
87
|
|
12
|
1
|
|
|
1
|
|
9
|
use Exporter qw(import); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
323
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw(permute_named); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub permute_named { |
16
|
15
|
|
|
15
|
1
|
2875
|
my $args; |
17
|
15
|
100
|
|
|
|
36
|
if (@_ == 1) { |
18
|
9
|
|
|
|
|
14
|
$args = shift; |
19
|
|
|
|
|
|
|
} else { |
20
|
6
|
|
|
|
|
13
|
$args = \@_; |
21
|
|
|
|
|
|
|
} |
22
|
15
|
50
|
|
|
|
42
|
if (ref $args eq 'HASH') { |
23
|
0
|
|
|
|
|
0
|
$args = [%$args]; |
24
|
|
|
|
|
|
|
} |
25
|
15
|
50
|
|
|
|
43
|
if (ref $args ne 'ARRAY') { |
26
|
0
|
|
|
|
|
0
|
die "permute_named expects an array ref or a hash ref\n"; |
27
|
|
|
|
|
|
|
} |
28
|
15
|
50
|
|
|
|
38
|
if (@$args % 2 == 1) { |
29
|
0
|
|
|
|
|
0
|
die "permute_named got an uneven-sized list of arguments\n"; |
30
|
|
|
|
|
|
|
} |
31
|
15
|
|
|
|
|
19
|
my @permutations; |
32
|
|
|
|
|
|
|
my $permute; |
33
|
|
|
|
|
|
|
$permute = sub { |
34
|
75
|
|
|
75
|
|
104
|
my ($args, $done) = @_; |
35
|
75
|
|
|
|
|
1077
|
my $done_clone = dclone $done; |
36
|
75
|
100
|
|
|
|
168
|
if (@$args == 0) { |
37
|
45
|
|
|
|
|
61
|
push @permutations => $done_clone; |
38
|
45
|
|
|
|
|
154
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
30
|
|
|
|
|
384
|
my $args_clone = dclone $args; |
41
|
30
|
|
|
|
|
61
|
my ($key, $value) = splice @$args_clone, 0, 2; |
42
|
30
|
100
|
|
|
|
612
|
$value = [$value] unless ref $value eq 'ARRAY'; |
43
|
30
|
|
|
|
|
50
|
for my $element (@$value) { |
44
|
60
|
|
|
|
|
94
|
$done_clone->{$key} = $element; |
45
|
60
|
|
|
|
|
141
|
$permute->($args_clone, $done_clone); |
46
|
|
|
|
|
|
|
} |
47
|
15
|
|
|
|
|
106
|
}; |
48
|
15
|
|
|
|
|
36
|
$permute->($args, {}); |
49
|
15
|
100
|
|
|
|
96
|
wantarray ? @permutations : \@permutations; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |