Verify/Solution.pm

filter: Statementstmt 90.1% 73 / 81 Branchbran 66.6% 20 / 30 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 14 / 14 Podpod 100% 1 / 1 totaltotal 83.8% 114 / 136 CC 18 SCAR 17.4
CC
18
Cov
83%
_read_state
10.1
verify
9.0
_read_move
3.0
CRAP 5.7
« Verify/Solution/ExpandMultiCardMoves.pm ↑ Summary Verify/KlondikeTalon.pm »
1 package Games::Solitaire::Verify::Solution;
2 8 $Games::Solitaire::Verify::Solution::VERSION = '0.2601';
3 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 8 ▶use parent 'Games::Solitaire::Verify::Solution::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 ▶use Games::Solitaire::Verify::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use Games::Solitaire::Verify::Card ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use Games::Solitaire::Verify::Column ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use Games::Solitaire::Verify::Move ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use Games::Solitaire::Verify::State ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 sub _init
19 16 ▶{
Subroutine _init: called CC=1 SCAR=0.0
20 16 my ( $self, $args ) = @_;
21  
22 16 $self->SUPER::_init($args);
23  
24 16 $self->_st(undef);
25 16 $self->_reached_end(0);
26  
27 16 return 0;
28 }
29  
30 sub _read_state
31 1343 ▶{
Subroutine _read_state: called CC=9 SCAR=23.1
32 1343 my $self = shift;
33  
34 1343 my $line = $self->_l();
35  
36 1343 ▶ if ( $line ne "\n" )
Branch: 1 branch
BranchTrueFalseTotal
if ($line ne "\n") 0 1343 1343
37 {
38 0 die "Non empty line before state";
39 }
40  
41 1343 my $str = "";
42  
43 1343 ▶ while ( ( $line = $self->_l() ) && ( $line ne "\n" ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($line = $self->_l and $line ne "\n") 13774 1343 15117
Condition66%2/3
$line = $self->_l and $line ne "\n"
!ll&&!rl&&r
0134313774
MC/DC50%1/2
$line = $self->_l and $line ne "\n"
$line = $self->_l $line ne "\n"
Truth table66%2/3
A and B
A= $line = $self->_lB= $line ne "\n"
ABresult
0X0
100
111
44 {
45 13774 $str .= $line;
46 }
47  
48 1343 ▶ if ( !defined( $self->_st() ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->_st) { } 16 1327 1343
49 {
50 $self->_st(
51 Games::Solitaire::Verify::State->new(
52 {
53 string => $str,
54 16 @{ $self->_V },
55 }
56 )
57 );
58 }
59 else
60 {
61 1327 ▶ if ( $self->_st()->to_string() ne $str )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_st->to_string ne $str) 0 1327 1327
62 {
63 0 die "States don't match";
64 }
65 }
66  
67 1343 ▶ while ( defined( $line = $self->_l() ) && ( $line eq "\n" ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_l) and $line eq "\n") 1343 1343 2686
Condition66%2/3
defined($line = $self->_l) and $line eq "\n"
!ll&&!rl&&r
013431343
MC/DC50%1/2
defined($line = $self->_l) and $line eq "\n"
defined($line = $self->_l) $line eq "\n"
Truth table66%2/3
A and B
A= defined($line = $self->_l)B= $line eq "\n"
ABresult
0X0
100
111
68 {
69 }
70  
71 1343 ▶ if ( $line !~ m{\A={3,}\n\z} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /\A={3,}\n\z/) 0 1343 1343
72 {
73 0 die "No ======== separator";
74 }
75  
76 1343 return ();
77 }
78  
79 sub _read_move
80 1343 ▶{
Subroutine _read_move: called CC=3 SCAR=11.1
81 1343 my $self = shift;
82  
83 1343 my $line = $self->_l();
84  
85 1343 ▶ if ( $line ne "\n" )
Branch: 1 branch
BranchTrueFalseTotal
if ($line ne "\n") 0 1343 1343
86 {
87 0 die "No empty line before move";
88 }
89  
90 1343 $line = $self->_l();
91  
92 1343 ▶ if ( $line eq "This game is solveable.\n" )
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "This game is solveable.\n") 10 1333 1343
93 {
94 10 $self->_reached_end(1);
95  
96 10 return "END";
97 }
98  
99 1333 chomp($line);
100  
101 1333 $self->_move(
102 Games::Solitaire::Verify::Move->new(
103 {
104 fcs_string => $line,
105 game => $self->_variant(),
106 }
107 )
108 );
109  
110 1333 return ();
111 }
112  
113 sub _apply_move
114 1333 ▶{
Subroutine _apply_move: called CC=2 SCAR=6.9
115 1333 my $self = shift;
116  
117 1333 ▶ if ( my $verdict = $self->_st()->verify_and_perform_move( $self->_move() ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $verdict = $self->_st->verify_and_perform_move($self->_move)) 6 1327 1333
118 {
119 6 Games::Solitaire::Verify::Exception::VerifyMove->throw(
120 error => "Wrong Move",
121 problem => $verdict,
122 );
123 }
124  
125 1327 return ();
126 }
127  
128  
129 sub verify
130 16 ▶{
Subroutine verify: called CC=7 SCAR=22.0
Pod documented
131 16 my $self = shift;
132  
133 16 eval {
134  
135 16 my $line = $self->_l();
136  
137 16 ▶ if ( $line !~ m{\A(-=)+-\n\z} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /\A(-=)+-\n\z/) 0 16 16
138 {
139 0 die "Incorrect start";
140 }
141  
142 16 $self->_read_state();
143 16 $self->_st->verify_contents( { max_rank => $self->_max_rank } );
144  
145 16 ▶ while ( !defined( scalar( $self->_read_move() ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined scalar $self->_read_move) 1333 10 1343
146 {
147 1333 $self->_apply_move();
148 1327 $self->_read_state();
149 }
150 };
151  
152 16 my $err;
153 16 ▶ if ( !$@ )
Branch: 3 branches
BranchTrueFalseTotal
if (not $@) { } 10 6 16
elsif ($err = 'Exception::Class'->caught('Games::Solitaire::Verify::Exception::VerifyMove')) { } 6 0 6
elsif ($err = 'Exception::Class'->caught('Games::Solitaire::Verify::Exception::State::MissingCards')) { } 0 0 0
154 {
155 # Do nothing - no exception was thrown.
156 }
157 elsif (
158 $err = Exception::Class->caught(
159 'Games::Solitaire::Verify::Exception::VerifyMove')
160 )
161 {
162 6 return { error => $err, line_num => $self->_ln(), };
163 }
164 elsif (
165 $err = Exception::Class->caught(
166 'Games::Solitaire::Verify::Exception::State::MissingCards')
167 )
168 {
169 0 return { error => $err, line_num => $self->_ln(), };
170 }
171 elsif (1)
172 {
173 0 $err = Exception::Class->caught();
174 0 ▶ ref $err ? $err->rethrow : die $err;
Branch: 1 branch
BranchTrueFalseTotal
ref $err ? : 0 0 0
175 }
176  
177 10 return ();
178 }
179  
180 8 1; # End of Games::Solitaire::Verify::Solution
181  
182 __END__
« Verify/Solution/ExpandMultiCardMoves.pm ↑ Summary Verify/KlondikeTalon.pm »