File Coverage

blib/lib/Set/Product/PP.pm
Criterion Covered Total %
statement 34 34 100.0
branch 7 8 87.5
condition 6 7 85.7
subroutine 6 6 100.0
pod 1 1 100.0
total 54 56 96.4


line stmt bran cond sub pod time code
1             package Set::Product::PP;
2              
3 3     3   26801 use strict;
  3         6  
  3         86  
4 3     3   16 use warnings;
  3         7  
  3         89  
5              
6 3     3   15 use Carp qw(croak);
  3         7  
  3         207  
7 3     3   16 use Exporter qw(import);
  3         5  
  3         105  
8 3     3   14 use Scalar::Util qw(reftype);
  3         11  
  3         1152  
9              
10             our @EXPORT_OK = qw(product);
11              
12             sub product (&@) {
13 8     8 1 7226 my ($sub, @in) = @_;
14              
15 8 50 50     75 croak 'Not a subroutine reference'
16             unless 'CODE' eq (reftype($sub) || '');
17             croak 'Not an array reference'
18 8 100 100     26 if grep { 'ARRAY' ne (reftype($_) || '') } @in;
  18         845  
19 7 100 100     30 return if ! @in or grep { ! @$_ } @in;
  15         58  
20              
21 5         17 my @out = map { $in[$_]->[0] } 0 .. $#in;
  12         31  
22 5         20 my @idx = (0) x @in;
23              
24 5         19 for (my $i = 0; $i >= 0; ) {
25 22         68 $sub->(@out);
26 22         167 for ($i=$#in; $i >= 0; $i--) {
27 32         48 $idx[$i]++;
28 32 100       41 if ($idx[$i] > $#{$in[$i]}) {
  32         95  
29 15         22 $idx[$i] = 0;
30 15         63 $out[$i] = $in[$i]->[0];
31             }
32             else {
33 17         31 $out[$i] = $in[$i]->[$idx[$i]];
34 17         50 last;
35             }
36             }
37             }
38             }
39              
40              
41             1;
42              
43             __END__