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   65728 use strict;
  1         11  
  1         28  
5 1     1   5 use warnings;
  1         2  
  1         23  
6              
7 1     1   415 use Array::Iterator;
  1         3  
  1         390  
8              
9             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
10             our $DATE = '2021-09-26'; # DATE
11             our $DIST = 'Array-Iterator'; # DIST
12             our $VERSION = '0.131'; # VERSION
13              
14             our @ISA = qw(Array::Iterator);
15              
16             sub _init {
17 1     1   16 my ($self, @args) = @_;
18 1         6 $self->{loop_counter} = 0;
19 1         7 $self->SUPER::_init(@args);
20             }
21              
22             # always return true, since
23             # we just keep looping
24 5     5 1 14 sub has_next { 1 }
25              
26             sub next {
27 26     26 1 41 my ($self) = @_;
28 26 100       75 unless ($self->_current_index < $self->getLength()) {
29 5         11 $self->_current_index = 0;
30 5         9 $self->{loop_counter}++;
31             }
32 26         54 $self->_iterated = 1;
33 26         53 return $self->_getItem($self->_iteratee(), $self->_current_index++);
34             }
35              
36             # since neither of them will
37             # ever stop dispensing items
38             # they can just be aliases of
39             # one another.
40             *get_next = \&next;
41              
42             sub is_start {
43 1     1 1 3 my ($self) = @_;
44 1         6 return ($self->_current_index() == 0);
45             }
46              
47 1     1 0 3269 sub isStart { my $self = shift; $self->is_start(@_) }
  1         7  
48              
49             sub is_end {
50 5     5 1 14 my ($self) = @_;
51 5         11 return ($self->_current_index() == $self->getLength());
52             }
53              
54 5     5 0 25 sub isEnd { my $self = shift; $self->is_end(@_) }
  5         10  
55              
56             sub get_loop_count {
57 28     28 1 41 my ($self) = @_;
58 28         56 return $self->{loop_counter};
59             }
60              
61 28     28 0 90 sub getLoopCount { my $self = shift; $self->get_loop_count(@_) }
  28         51  
62              
63             1;
64             # ABSTRACT: A subclass of Array::Iterator to allow circular iteration
65              
66             __END__