lib/Games/Checkers/Iterators.pm

filter: Statementstmt 30.1% 16 / 53 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 35.7% 5 / 14 Podpod n/a totaltotal 24.1% 21 / 87 CC 9 SCAR 23.3
CC
9
Cov
23%
increment
30.0
increment
12.0
new
6.0
CRAP 10.2
« lib/Games/Checkers/Move.pm ↑ Summary lib/Games/Checkers/Constants.pm »
1 # Games::Checkers, Copyright (C) 1996-2012 Mikhael Goikhman, migo@cpan.org
2 #
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15  
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # ----------------------------------------------------------------------------
20  
21 package Games::Checkers::LocationIterator;
22  
23 1 ▶use Games::Checkers::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 0 ▶sub new ($$%) {
Subroutine new: not called CC=2 SCAR=17.9
26 0 my $class = shift;
27 0 ▶ my $board = shift || die "No board in constructor";
Condition0%0/2
shift() || die('No board in constructor')
l!l
00
MC/DC0%0/1
shift() || die('No board in constructor')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
28  
29 0 my $self = { board => $board, loc => undef, @_ };
30  
31 0 bless $self, $class;
32 0 $self->restart;
33  
34 0 return $self;
35 }
36  
37 0 ▶sub last ($) {
Subroutine last: not called CC=1 SCAR=6.9
38 0 my $self = shift;
39 0 return $self->{loc};
40 }
41  
42 0 ▶sub next ($) {
Subroutine next: not called CC=1 SCAR=6.9
43 0 my $self = shift;
44 0 my $old = $self->{loc};
45 0 $self->increment;
46 0 return $old;
47 }
48  
49 0 ▶sub left ($) {
Subroutine left: not called CC=1 SCAR=6.9
50 0 my $self = shift;
51 0 return $self->{loc} != NL;
52 }
53  
54 0 ▶sub increment ($) {
Subroutine increment: not called CC=3 SCAR=24.8
55 0 my $self = shift;
56 0 ▶ return NL if $self->{loc} == NL;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"loc"} == &NL() 0 0 0
57 $self->{loc} = NL
58 0 ▶ unless ++$self->{loc} < $self->{board}->locs;
Branch: 1 branch
BranchTrueFalseTotal
unless ++$self->{"loc"} < $self->{"board"}->locs 0 0 0
59 0 return $self->{loc};
60 }
61  
62 0 ▶sub restart ($) {
Subroutine restart: not called CC=1 SCAR=6.9
63 0 my $self = shift;
64 0 $self->{loc} = -1;
65 0 $self->increment;
66 }
67  
68 0 ▶sub all ($) {
Subroutine all: not called CC=2 SCAR=17.9
69 0 my $self = shift;
70 0 my @locations = ();
71 0 ▶ push @locations, $self->next while $self->left;
Branch: 1 branch
BranchTrueFalseTotal
$self->left and do { push @locations, $self->next } 0 0 0
72 0 return @locations;
73 }
74  
75 # ----------------------------------------------------------------------------
76  
77 package Games::Checkers::FigureIterator;
78  
79 1 ▶use base 'Games::Checkers::LocationIterator';
Subroutine BEGIN: called CC=1 SCAR=0.0
80 1 ▶use Games::Checkers::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82 0 ▶sub new ($$$) {
Subroutine new: not called CC=1 SCAR=6.9
83 0 my $class = shift;
84 0 my $board = shift;
85 0 my $color = shift;
86  
87 0 return $class->SUPER::new($board, color => $color);
88 }
89  
90 0 ▶sub increment ($) {
Subroutine increment: not called CC=5 SCAR=34.0
91 0 my $self = shift;
92 0 my $loc = $self->{loc};
93  
94 0 ▶ return NL if $loc == NL;
Branch: 1 branch
BranchTrueFalseTotal
if $loc == &NL() 0 0 0
95  
96 0 my $board = $self->{board};
97  
98 0 ▶ while (++$loc < $board->locs) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$loc < $board->locs) 0 0 0
99 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($board->occup($loc) and $board->color($loc) == $self->{"color"}) 0 0 0
Condition0%0/3
$board->occup($loc) and $board->color($loc) == $self->{"color"}
!ll&&!rl&&r
000
MC/DC0%0/2
$board->occup($loc) and $board->color($loc) == $self->{"color"}
$board->occup($loc) $board->color($loc) == $self->{"color"}
Truth table0%0/3
A and B
A= $board->occup($loc)B= $board->color($loc) == $self->{"color"}
ABresult
0X0
100
111
100 $board->occup($loc) &&
101 $board->color($loc) == $self->{color}
102 ) {
103 0 return $self->{loc} = $loc;
104 }
105 }
106  
107 0 return $self->{loc} = NL;
108 }
109  
110 1 1;
« lib/Games/Checkers/Move.pm ↑ Summary lib/Games/Checkers/Constants.pm »