ArrayList/ListIterator.pm

filter: Statementstmt 100% 59 / 59 Branchbran 91.6% 22 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 100% 9 / 9 totaltotal 98.1% 104 / 106 CC 13 SCAR 8.4
CC
13
Cov
98%
set
3.1
next
3.0
previous
3.0
CRAP 2.3
« ArrayList.pm ↑ Summary
1 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Data::ArrayList::ListIterator;
4 5 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 $Data::ArrayList::ListIterator::VERSION = '0.01';
6 }
7 # ABSTRACT: iterator for Data::ArrayList
8  
9 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12  
13  
14 5 has '_parent' => (
15 is => 'rw',
16 isa => 'Object',
17 );
18  
19 5 has '_cursor' => (
20 is => 'rw',
21 isa => 'Int',
22 traits => [qw( Counter )],
23 default => 0,
24 handles => {
25 '_cursor_next' => 'inc',
26 '_cursor_prev' => 'dec',
27 },
28 );
29  
30 5 has '_mod_count' => (
31 is => 'rw',
32 isa => 'Int',
33 required => 1,
34 );
35  
36 5 has '_last_ret' => (
37 is => 'rw',
38 isa => 'Int',
39 default => -1,
40 );
41  
42  
43 150 ▶sub hasNext {
Subroutine hasNext: called CC=1 SCAR=0.0
Pod documented
44 150 my $self = shift;
45  
46 150 return $self->_cursor < $self->_parent->size;
47 }
48  
49  
50 48 ▶sub hasPrevious {
Subroutine hasPrevious: called CC=1 SCAR=0.0
Pod documented
51 48 return $_[0]->_cursor > 0;
52 }
53  
54  
55 36 ▶sub nextIndex {
Subroutine nextIndex: called CC=2 SCAR=6.9
Pod documented
56 36 my $self = shift;
57  
58 36 ▶ return $self->hasNext ?
Branch: 1 branch
BranchTrueFalseTotal
$self->hasNext ? : 34 2 36
59 $self->_cursor
60 :
61 $self->_parent->size;
62 }
63  
64  
65 12 ▶sub previousIndex {
Subroutine previousIndex: called CC=2 SCAR=6.9
Pod documented
66 12 my $self = shift;
67  
68 12 ▶ return $self->_cursor ? $self->_cursor - 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$self->_cursor ? : 10 2 12
69 }
70  
71  
72 55 ▶sub next {
Subroutine next: called CC=3 SCAR=11.0
Pod documented
73 55 my $self = shift;
74  
75 55 ▶ die "NoSuchElement"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->hasNext 2 53 55
76 unless $self->hasNext;
77  
78 53 ▶ die "ConcurrentModification"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_checkCoMod 3 50 53
79 unless $self->_checkCoMod;
80  
81 50 $self->_last_ret( $self->_cursor );
82  
83 50 my $i = $self->_cursor;
84 50 $self->_cursor_next;
85  
86 50 return $self->_parent->get( $i );
87 }
88  
89  
90 25 ▶sub previous {
Subroutine previous: called CC=3 SCAR=11.0
Pod documented
91 25 my $self = shift;
92  
93 25 ▶ die "NoSuchElement"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->hasPrevious 2 23 25
94 unless $self->hasPrevious;
95  
96 23 ▶ die "ConcurrentModification"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_checkCoMod 2 21 23
97 unless $self->_checkCoMod;
98  
99 21 $self->_cursor_prev;
100 21 $self->_last_ret( $self->_cursor );
101  
102 21 return $self->_parent->get( $self->_cursor );
103 }
104  
105  
106 6 ▶sub remove {
Subroutine remove: called CC=3 SCAR=11.0
Pod documented
107 6 my $self = shift;
108  
109 6 ▶ die "ConcurrentModification"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_checkCoMod 1 5 6
110 unless $self->_checkCoMod;
111  
112 5 ▶ die "IllegalState"
Branch: 1 branch
BranchTrueFalseTotal
if $self->_last_ret < 0 2 3 5
113 if $self->_last_ret < 0;
114  
115 3 $self->_parent->remove( $self->_last_ret );
116 3 $self->_cursor( $self->_last_ret );
117  
118 3 $self->_mod_count( $self->_parent->_mod_count );
119  
120 3 $self->_last_ret( -1 );
121  
122 3 return 1;
123 }
124  
125  
126 10 ▶sub set {
Subroutine set: called CC=3 SCAR=11.3
Pod documented
127 10 my $self = shift;
128  
129 10 ▶ die "ConcurrentModification"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_checkCoMod 0 10 10
130 unless $self->_checkCoMod;
131  
132 10 ▶ die "IllegalState"
Branch: 1 branch
BranchTrueFalseTotal
if $self->_last_ret < 0 0 10 10
133 if $self->_last_ret < 0;
134  
135 10 $self->_parent->set( $self->_last_ret, @_ );
136  
137 10 return 1;
138 }
139  
140  
141  
142 8 ▶sub add {
Subroutine add: called CC=3 SCAR=11.0
Pod documented
143 8 my $self = shift;
144  
145 8 ▶ die "IllegalArgument"
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 1 7 8
146 unless scalar @_;
147  
148 7 ▶ die "ConcurrentModification"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_checkCoMod 1 6 7
149 unless $self->_checkCoMod;
150  
151 6 $self->_parent->addAt( $self->_cursor, @_ );
152  
153 6 $self->_cursor_next;
154  
155 6 $self->_mod_count( $self->_parent->_mod_count );
156  
157 6 $self->_last_ret( -1 );
158  
159 6 return;
160 }
161  
162 99 ▶sub _checkCoMod {
Subroutine _checkCoMod: called CC=1 SCAR=0.0
163 99 my $self = shift;
164  
165 99 return $self->_mod_count == $self->_parent->_mod_count;
166 }
167  
168 5 __PACKAGE__->meta->make_immutable;
169  
170 5 1;
171  
172 __END__
« ArrayList.pm ↑ Summary