blib/lib/List/Permutor.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 6 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 4 / 4 totaltotal 100% 57 / 57 CC 5 SCAR 11.0
CC
5
Cov
100%
next
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
↑ Summary
1 package List::Permutor;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 require Exporter;
7  
8 1 @ISA = qw(Exporter);
9 1 @EXPORT = qw();
10 1 $VERSION = '0.022';
11  
12 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
13 5 my $class = shift;
14 5 my $items = [ @_ ];
15 5 bless [ $items, [ 0..$#$items ] ], $class;
16 }
17  
18 2 ▶sub reset {
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
19 2 my $self = shift;
20 2 my $items = $self->[0];
21 2 $self->[1] = [ 0..$#$items ];
22 2 1; # No useful return value
23 }
24  
25 6 ▶sub peek {
Subroutine peek: called CC=1 SCAR=0.0
Pod documented
26 6 my $self = shift;
27 6 my $items = $self->[0];
28 6 my $rv = $self->[1];
29 6 @$items[ @$rv ];
30 }
31  
32 142 ▶sub next {
Subroutine next: called CC=5 SCAR=16.1
Pod documented
33 142 my $self = shift;
34 142 my $items = $self->[0];
35 142 my $rv = $self->[1]; # return value array
36 142 ▶ return unless @$rv;
Branch: 1 branch
BranchTrueFalseTotal
unless @$rv 3 139 142
37 139 my @next = @$rv;
38 # The last N items in @next (for 1 <= N <= @next) are each
39 # smaller than the one before. Move those into @tail.
40 139 my @tail = pop @next;
41 139 ▶ while (@next and $next[-1] > $tail[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@next and $next[-1] > $tail[-1]) 98 139 237
Condition100%3/3
@next and $next[-1] > $tail[-1]
!ll&&!rl&&r
413598
MC/DC100%2/2
@next and $next[-1] > $tail[-1]
@next $next[-1] > $tail[-1]
Truth table100%3/3
A and B
A= @nextB= $next[-1] > $tail[-1]
ABresult
0X0
100
111
42 98 push @tail, pop @next;
43 }
44 # Then there's one more. Right?
45 139 ▶ if (defined(my $extra = pop @next)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $extra = pop @next)) { } 135 4 139
46 # The extra one exchanges with the next larger one in @tail
47 135 my($place) = grep $extra < $tail[$_], 0..$#tail;
48 135 ($extra, $tail[$place]) = ($tail[$place], $extra);
49 # And the next order is what you get by assembling the three
50 135 $self->[1] = [ @next, $extra, @tail ];
51 } else {
52 # Guess that's all....
53 4 $self->[1] = [];
54 }
55 139 return @$items[ @$rv ];
56 }
57  
58 1 1;
59 __END__
↑ Summary