blib/lib/Permute/Named.pm

filter: Statementstmt 92.8% 39 / 42 Branchbran 78.5% 11 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 90.7% 59 / 65 CC 9 SCAR 13.0
CC
9
Cov
89%
permute_named
6.1
__ANON__
4.0
BEGIN
1.0
CRAP 3.7
↑ Summary
1 2 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Permute::Named;
6 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 $Permute::Named::VERSION = '1.100980';
8 }
9  
10 # ABSTRACT: permute multiple-valued key-value pairs
11 2 ▶use Storable 'dclone';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 our @EXPORT = qw(permute_named);
14  
15 15 ▶sub permute_named {
Subroutine permute_named: called CC=6 SCAR=18.1
Pod documented
16 15 my $args;
17 15 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 9 6 15
18 9 $args = shift;
19 } else {
20 6 $args = \@_;
21 }
22 15 ▶ if (ref $args eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args eq "HASH") 0 15 15
23 0 $args = [%$args];
24 }
25 15 ▶ if (ref $args ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args ne "ARRAY") 0 15 15
26 0 die "permute_named expects an array ref or a hash ref\n";
27 }
28 15 ▶ if (@$args % 2 == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$args % 2 == 1) 0 15 15
29 0 die "permute_named got an uneven-sized list of arguments\n";
30 }
31 15 my @permutations;
32 my $permute;
33 75 ▶ $permute = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
34 75 my ($args, $done) = @_;
35 75 my $done_clone = dclone $done;
36 75 ▶ if (@$args == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$args == 0) 45 30 75
37 45 push @permutations => $done_clone;
38 45 return;
39 }
40 30 my $args_clone = dclone $args;
41 30 my ($key, $value) = splice @$args_clone, 0, 2;
42 30 ▶ $value = [$value] unless ref $value eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "ARRAY" 10 20 30
43 30 for my $element (@$value) {
44 60 $done_clone->{$key} = $element;
45 60 $permute->($args_clone, $done_clone);
46 }
47 15 };
48 15 $permute->($args, {});
49 15 ▶ wantarray ? @permutations : \@permutations;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 9 6 15
50 }
51 2 1;
52  
53  
54 __END__
↑ Summary