blib/lib/Game/Fanorona/Error.pm

filter: Statementstmt 100% 41 / 41 Branchbran 91.6% 11 / 12 Conditioncond 69.2% 9 / 13 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 12 / 12 Podpod 83.3% 5 / 6 totaltotal 89.1% 82 / 92 CC 12 SCAR 11.2
CC
12
Cov
92%
of
6.1
known
3.0
is
3.0
CRAP 3.1
« blib/lib/Game/Fanorona/Engine.pm ↑ Summary blib/arch/Game/Fanorona/Install/Files.pm »
1 package Game::Fanorona::Error;
2  
3 25 ▶use 5.014;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 25 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
5 25 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
6  
7 25 ▶use Carp ();
Subroutine __ANON__: called CC=1 SCAR=0.0
8 25 ▶use Object::Proto::Sugar;
Subroutine __ANON__: called CC=1 SCAR=0.0
9  
10 25 our $VERSION = '0.02';
11  
12 25 our @CODES;
13 25 our %MESSAGE;
14 25 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
15 25 @CODES = qw(
16 game_over
17 not_a_side
18 offer_standing
19 no_offer
20 own_offer
21 chain_open
22 nothing_to_stop
23 bad_move
24 off_board
25 no_stone
26 not_your_stone
27 not_the_stone
28 not_adjacent
29 no_line
30 point_taken
31 same_direction
32 point_revisited
33 paika_in_chain
34 takes_nothing
35 choose_capture
36 must_capture
37 );
38 25 %MESSAGE = (
39 game_over => 'the game is already over',
40 not_a_side => 'that is not one of the two sides',
41 offer_standing => 'a draw has already been offered',
42 no_offer => 'no draw has been offered',
43 own_offer => 'you cannot answer your own offer',
44 chain_open => 'a move is in progress: finish it or stop',
45 nothing_to_stop => 'no move is in progress',
46 bad_move => 'that is not a move',
47 off_board => 'that point is not on the board',
48 no_stone => 'there is no stone there',
49 not_your_stone => 'that stone is not yours',
50 not_the_stone => 'the stone that is taking must go on, or stop',
51 not_adjacent => 'a stone steps to the next point along a line',
52 no_line => 'no line runs that way from there',
53 point_taken => 'a stone is standing there',
54 same_direction => 'a stone may not step twice running in the same direction',
55 point_revisited => 'a stone may not come back to a point in the same move',
56 paika_in_chain => 'a stone that has taken may stop, and may not then move on without taking',
57 takes_nothing => 'that step takes nothing that way',
58 choose_capture => 'that step can take two ways: say which, A or W',
59 must_capture => 'a stone can be taken, so one must be',
60 );
61 }
62  
63 25 has code => (is => 'ro');
64  
65 25 has message => (is => 'ro', default => '');
66  
67 25 has move => (is => 'ro');
68  
69 25 my $MAKING = 0;
70  
71 88 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
72 88 my ($self) = @_;
73 88 ▶ Carp::croak('Game::Fanorona::Error: a refusal is made by Game::Fanorona::Error->of')
Branch: 1 branch
BranchTrueFalseTotal
unless $MAKING 1 87 88
74 unless $MAKING;
75 87 return;
76 }
77  
78 88 ▶sub of {
Subroutine of: called CC=6 SCAR=18.1
Pod documented
79 88 my ($class, $code, %extra) = @_;
80 Carp::croak("Game::Fanorona::Error: no such refusal as '" . ($code // 'undef') . "'")
81 88 ▶ unless defined $code && exists $MESSAGE{$code};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code and exists $Game::Fanorona::Error::MESSAGE{$code} 1 87 88
Condition60%3/5
defined $code and exists $Game::Fanorona::Error::MESSAGE{$code}
!ll&&!rl&&r
0187
$code // "undef"
l!l
10
MC/DC50%1/2
defined $code and exists $Game::Fanorona::Error::MESSAGE{$code}
defined $code exists $Game::Fanorona::Error::MESSAGE{$code}
MC/DC0%0/1
$code // "undef"
$code
Truth table66%2/3
A and B
A= defined $codeB= exists $Game::Fanorona::Error::MESSAGE{$code}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $code
Aresult
11
00
82 87 $MAKING = 1;
83 87 my $made = eval {
84 $class->new(
85 code => $code,
86 message => $MESSAGE{$code},
87 87 ▶ (defined $extra{move} ? (move => "$extra{move}") : ()),
Branch: 1 branch
BranchTrueFalseTotal
defined $extra{'move'} ? : 52 35 87
88 );
89 };
90 87 my $died = $@;
91 87 $MAKING = 0;
92 87 ▶ Carp::croak($died) unless $made;
Branch: 1 branch
BranchTrueFalseTotal
unless $made 0 87 87
93 87 return $made;
94 }
95  
96 3 ▶sub is {
Subroutine is: called CC=3 SCAR=11.0
Pod documented
97 3 my ($self, $code) = @_;
98 3 ▶ return defined $code && $self->code eq $code ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $code && $self->code eq $code ? : 1 2 3
Condition100%3/3
defined $code and $self->code eq $code
!ll&&!rl&&r
111
MC/DC100%2/2
defined $code and $self->code eq $code
defined $code $self->code eq $code
Truth table100%3/3
A and B
A= defined $codeB= $self->code eq $code
ABresult
0X0
100
111
99 }
100  
101 2 ▶sub codes { @CODES }
Subroutine codes: called CC=1 SCAR=0.0
Pod documented
102  
103 43 ▶sub message_for { $MESSAGE{ $_[1] // '' } }
Subroutine message_for: called CC=2 SCAR=7.6
Pod documented
Condition50%1/2
$_[1] // ""
l!l
430
MC/DC0%0/1
$_[1] // ""
$_[1]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
104  
105 22 ▶sub known { defined $_[1] && exists $MESSAGE{ $_[1] } ? 1 : 0 }
Subroutine known: called CC=3 SCAR=11.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] && exists $Game::Fanorona::Error::MESSAGE{$_[1]} ? : 21 1 22
Condition66%2/3
defined $_[1] and exists $Game::Fanorona::Error::MESSAGE{$_[1]}
!ll&&!rl&&r
0121
MC/DC50%1/2
defined $_[1] and exists $Game::Fanorona::Error::MESSAGE{$_[1]}
defined $_[1] exists $Game::Fanorona::Error::MESSAGE{$_[1]}
Truth table66%2/3
A and B
A= defined $_[1]B= exists $Game::Fanorona::Error::MESSAGE{$_[1]}
ABresult
0X0
100
111
106  
107 25 1;
108  
109 __END__
« blib/lib/Game/Fanorona/Engine.pm ↑ Summary blib/arch/Game/Fanorona/Install/Files.pm »