| 1 | package List::Rotation; | ||||||||||
| 2 | 5 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 5 | our $VERSION = '1.010'; | |||||||||
| 4 | |||||||||||
| 5 | package List::Rotation::Cycle; | ||||||||||
| 6 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 5 | ▶ | use Memoize; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 5 | memoize('new'); | |||||||||
| 11 | |||||||||||
| 12 | 3 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
| |||||||||||
| 13 | 3 | my $class = shift; | |||||||||
| 14 | |||||||||||
| 15 | 3 | ▶ | do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 0 | require Carp; | |||||||||
| 17 | 0 | Carp::croak ("Incorrect number of arguments; must be >= 1."); | |||||||||
| 18 | } unless 1 <= @_; | ||||||||||
| 19 | 3 | my $r_values = [ @_ ]; | |||||||||
| 20 | 3 | my $position = undef; | |||||||||
| 21 | 3 | my $length = @$r_values; | |||||||||
| 22 | |||||||||||
| 23 | my $method = { | ||||||||||
| 24 | 48 | ▶ | _next => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 25 | 48 | ▶ | $position = defined $position ? ++$position : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 48 | my $i = $position % $length; | |||||||||
| 27 | 48 | return $r_values->[$i]; | |||||||||
| 28 | }, | ||||||||||
| 29 | 8 | ▶ | _prev => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||
| 30 | 8 | ▶ | $position = defined $position ? --$position : -1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 8 | my $i = $position % $length; | |||||||||
| 32 | 8 | return $r_values->[$i]; | |||||||||
| 33 | }, | ||||||||||
| 34 | 8 | ▶ | _curr => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 35 | 8 | ▶ | return unless defined $position; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 7 | my $i = $position % $length; | |||||||||
| 37 | 7 | return $r_values->[$i]; | |||||||||
| 38 | }, | ||||||||||
| 39 | 4 | ▶ | _reset => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 40 | 4 | $position = undef; | |||||||||
| 41 | }, | ||||||||||
| 42 | 3 | }; | |||||||||
| 43 | |||||||||||
| 44 | 68 | ▶ | my $closure = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 45 | 68 | my $call = shift; | |||||||||
| 46 | 68 | &{ $method->{$call} }; | |||||||||
| 47 | 3 | }; | |||||||||
| 48 | |||||||||||
| 49 | 3 | bless $closure, $class; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 48 | ▶ | sub next { my $self = shift; &{ $self }( '_next' ); } | ||||||||
|
Subroutine
next: called CC=1 SCAR=0.0
| |||||||||||
| 53 | 8 | ▶ | sub prev { my $self = shift; &{ $self }( '_prev' ); } | ||||||||
|
Subroutine
prev: called CC=1 SCAR=0.0
| |||||||||||
| 54 | 8 | ▶ | sub curr { my $self = shift; &{ $self }( '_curr' ); } | ||||||||
|
Subroutine
curr: called CC=1 SCAR=0.0
| |||||||||||
| 55 | 4 | ▶ | sub reset { my $self = shift; &{ $self }( '_reset' ); } | ||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
| |||||||||||
| 56 | |||||||||||
| 57 | #------------------------------------------------------------------------------- | ||||||||||
| 58 | |||||||||||
| 59 | package List::Rotation::Alternate; | ||||||||||
| 60 | |||||||||||
| 61 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 62 | |||||||||||
| 63 | 5 | ▶ | use vars qw( @ISA ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 64 | 5 | @ISA = qw(List::Rotation::Cycle); | |||||||||
| 65 | |||||||||||
| 66 | 8 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=8.4
| |||||||||||
| 67 | 8 | my $class = shift; | |||||||||
| 68 | |||||||||||
| 69 | 8 | ▶ | do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | require Carp; | |||||||||
| 71 | 0 | Carp::croak ("Incorrect number of arguments; must be <2>."); | |||||||||
| 72 | } unless 2 == @_; | ||||||||||
| 73 | |||||||||||
| 74 | 8 | $class->SUPER::new(@_); | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | #------------------------------------------------------------------------------- | ||||||||||
| 78 | |||||||||||
| 79 | package List::Rotation::Toggle; | ||||||||||
| 80 | |||||||||||
| 81 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 82 | |||||||||||
| 83 | 5 | ▶ | use vars qw( @ISA ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 84 | 5 | @ISA = qw(List::Rotation::Alternate); | |||||||||
| 85 | |||||||||||
| 86 | 4 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=8.4
| |||||||||||
| 87 | 4 | my $class = shift; | |||||||||
| 88 | |||||||||||
| 89 | 4 | ▶ | do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 0 | require Carp; | |||||||||
| 91 | 0 | Carp::croak ("No arguments accepted."); | |||||||||
| 92 | } unless 0 == @_; | ||||||||||
| 93 | |||||||||||
| 94 | 4 | $class->SUPER::new( 1 == 1, 0 == 1 ); | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | #------------------------------------------------------------------------------- | ||||||||||
| 98 | |||||||||||
| 99 | 5 | 1; | |||||||||
| 100 | |||||||||||
| 101 | |||||||||||
| 102 | __END__ | ||||||||||