| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
@next and $next[-1] > $tail[-1]
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]
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||