blib/lib/Games/Solitaire/Verify/Solution.pm

filter: Statementstmt 91.2% 73 / 80 Branchbran 71.4% 20 / 28 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 14 / 14 Podpod 100% 1 / 1 totaltotal 85.7% 114 / 133 CC 17 SCAR 16.3
CC
17
Cov
85%
_read_state
10.1
verify
6.7
_read_move
3.0
CRAP 5.1
« blib/lib/Games/Solitaire/Verify/KlondikeTalon.pm ↑ Summary blib/lib/Games/Solitaire/Verify/App/CmdLine/From_Patsolve.pm »
1 package Games::Solitaire::Verify::Solution;
2 5 $Games::Solitaire::Verify::Solution::VERSION = '0.2301';
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 5 ▶use parent 'Games::Solitaire::Verify::Solution::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 ▶use Games::Solitaire::Verify::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Games::Solitaire::Verify::Card ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Games::Solitaire::Verify::Column ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Games::Solitaire::Verify::Move ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use Games::Solitaire::Verify::State ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 sub _init
19 {
20 16 ▶ my ( $self, $args ) = @_;
Subroutine _init: called CC=1 SCAR=0.0
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 {
32 1343 ▶ my $self = shift;
Subroutine _read_state: called CC=9 SCAR=23.1
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 {
81 1343 ▶ my $self = shift;
Subroutine _read_move: called CC=3 SCAR=11.1
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 {
115 1333 ▶ my $self = shift;
Subroutine _apply_move: called CC=2 SCAR=6.9
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 {
131 16 ▶ my $self = shift;
Subroutine verify: called CC=6 SCAR=19.0
Pod documented
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: 2 branches
BranchTrueFalseTotal
if (not $@) { } 10 6 16
elsif ($err = 'Exception::Class'->caught('Games::Solitaire::Verify::Exception::VerifyMove')) { } 6 0 6
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 else
165 {
166 0 $err = Exception::Class->caught();
167 0 ▶ ref $err ? $err->rethrow : die $err;
Branch: 1 branch
BranchTrueFalseTotal
ref $err ? : 0 0 0
168 }
169  
170 10 return;
171 }
172  
173 5 1; # End of Games::Solitaire::Verify::Solution
174  
175 __END__
« blib/lib/Games/Solitaire/Verify/KlondikeTalon.pm ↑ Summary blib/lib/Games/Solitaire/Verify/App/CmdLine/From_Patsolve.pm »