File Coverage

blib/lib/Array/Iterator/Circular.pm
Criterion Covered Total %
statement 31 31 100.0
branch 2 2 100.0
condition n/a
subroutine 12 12 100.0
pod 5 8 62.5
total 50 53 94.3


line stmt bran cond sub pod time code
1              
2             package Array::Iterator::Circular;
3              
4 1     1   63395 use strict;
  1         8  
  1         27  
5 1     1   5 use warnings;
  1         2  
  1         35  
6              
7             our $VERSION = '0.12'; # VERSION
8              
9 1     1   376 use Array::Iterator;
  1         3  
  1         303  
10             our @ISA = qw(Array::Iterator);
11              
12             sub _init {
13 1     1   3 my ($self, @args) = @_;
14 1         4 $self->{loop_counter} = 0;
15 1         5 $self->SUPER::_init(@args);
16             }
17              
18             # always return true, since
19             # we just keep looping
20 5     5 1 12 sub has_next { 1 }
21              
22             sub next {
23 26     26 1 32 my ($self) = @_;
24 26 100       40 unless ($self->_current_index < $self->getLength()) {
25 5         11 $self->_current_index = 0;
26 5         7 $self->{loop_counter}++;
27             }
28 26         44 $self->_iterated = 1;
29 26         42 return $self->_getItem($self->_iteratee(), $self->_current_index++);
30             }
31              
32             # since neither of them will
33             # ever stop dispensing items
34             # they can just be aliases of
35             # one another.
36             *get_next = \&next;
37              
38             sub is_start {
39 1     1 1 2 my ($self) = @_;
40 1         6 return ($self->_current_index() == 0);
41             }
42              
43 1     1 0 2676 sub isStart { my $self = shift; $self->is_start(@_) }
  1         6  
44              
45             sub is_end {
46 5     5 1 5 my ($self) = @_;
47 5         9 return ($self->_current_index() == $self->getLength());
48             }
49              
50 5     5 0 20 sub isEnd { my $self = shift; $self->is_end(@_) }
  5         9  
51              
52             sub get_loop_count {
53 28     28 1 34 my ($self) = @_;
54 28         39 return $self->{loop_counter};
55             }
56              
57 28     28 0 68 sub getLoopCount { my $self = shift; $self->get_loop_count(@_) }
  28         43  
58              
59             1;
60             # ABSTRACT: A subclass of Array::Iterator to allow circular iteration
61              
62             __END__