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   25518 use strict;
  3         5  
  3         72  
4 3     3   12 use warnings;
  3         6  
  3         78  
5              
6 3     3   14 use Carp qw(croak);
  3         5  
  3         176  
7 3     3   15 use Exporter qw(import);
  3         7  
  3         98  
8 3     3   15 use Scalar::Util qw(reftype);
  3         6  
  3         1148  
9              
10             our @EXPORT_OK = qw(product);
11              
12             sub product (&@) {
13 6     6 1 2601 my ($sub, @in) = @_;
14              
15 6 50 50     35 croak 'Not a subroutine reference'
16             unless 'CODE' eq (reftype($sub) || '');
17             croak 'Not an array reference'
18 6 100 100     11 if grep { 'ARRAY' ne (reftype($_) || '') } @in;
  14         218  
19 5 100 100     16 return if ! @in or grep { ! @$_ } @in;
  11         30  
20              
21 3         7 my @out = map { $in[$_]->[0] } 0 .. $#in;
  8         14  
22 3         6 my @idx = (0) x @in;
23              
24 3         11 for (my $i = 0; $i >= 0; ) {
25 10         20 $sub->(@out);
26 10         48 for ($i=$#in; $i >= 0; $i--) {
27 16         19 $idx[$i]++;
28 16 100       16 if ($idx[$i] > $#{$in[$i]}) {
  16         34  
29 9         8 $idx[$i] = 0;
30 9         29 $out[$i] = $in[$i]->[0];
31             }
32             else {
33 7         11 $out[$i] = $in[$i]->[$idx[$i]];
34 7         14 last;
35             }
36             }
37             }
38             }
39              
40              
41             1;
42              
43             __END__