blib/lib/Game/Shogi/Error.pm

filter: Statementstmt 94.5% 35 / 37 Branchbran 58.3% 7 / 12 Conditioncond 36.0% 9 / 25 MC/DCmcdc 14.2% 2 / 14 Subroutinesub 83.3% 10 / 12 Podpod 85.7% 6 / 7 totaltotal 64.4% 69 / 107 CC 16 SCAR 17.0
CC
16
Cov
69%
known
12.0
of_fault
8.1
throw
6.2
CRAP 5.5
« blib/lib/Game/Shogi/Bot.pm ↑ Summary blib/lib/Game/Shogi/Engine.pm »
1 package Game::Shogi::Error;
2  
3 9 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Object::Proto::Sugar;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 9 our $VERSION = '0.01';
11  
12 9 my @CODES = qw(
13 bad_move not_your_piece not_in_hand cannot_reach occupied
14 promote_not_allowed promote_required dead_piece two_pawns in_check pawn_drop_mate
15 game_over not_your_turn cannot_declare nothing_to_undo
16 );
17  
18 9 my %MESSAGE = (
19 bad_move => 'that is not a move',
20 not_your_piece => 'there is no piece of yours there',
21 not_in_hand => 'you have none of that piece in hand',
22 cannot_reach => 'that piece cannot move there',
23 occupied => 'a piece cannot be dropped onto another',
24 promote_not_allowed => 'that piece may not promote on that move',
25 promote_required => 'that piece must promote on that move',
26 dead_piece => 'a piece cannot be dropped where it could never move',
27 two_pawns => 'you already have an unpromoted pawn on that file',
28 in_check => 'that would leave your king in check',
29 pawn_drop_mate => 'a pawn may not be dropped to give mate',
30 game_over => 'the game is already over',
31 not_your_turn => 'it is not your turn',
32 cannot_declare => 'the impasse may not be declared',
33 nothing_to_undo => 'there is no move to take back',
34 );
35  
36 9 my @FAULT = (undef, @CODES[ 0 .. 10 ]);
37  
38 9 has code => (is => 'ro');
39  
40 9 has message => (is => 'ro');
41  
42 29 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=17.1
Pod undocumented
43 29 my ($self) = @_;
44 29 my $code = $self->code;
45 Carp::croak("Game::Shogi::Error: no such refusal '" . ($code // 'undef') . "'")
46 29 ▶ unless defined $code && exists $MESSAGE{$code};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code and exists $MESSAGE{$code} 0 29 29
Condition20%1/5
defined $code and exists $MESSAGE{$code}
!ll&&!rl&&r
0029
$code // "undef"
l!l
00
MC/DC0%0/2
defined $code and exists $MESSAGE{$code}
defined $code exists $MESSAGE{$code}
MC/DC0%0/1
$code // "undef"
$code
Truth table33%1/3
A and B
A= defined $codeB= exists $MESSAGE{$code}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $code
Aresult
11
00
47 29 return;
48 }
49  
50 30 ▶sub throw {
Subroutine throw: called CC=6 SCAR=18.2
Pod documented
51 30 my ($class, $code, $detail) = @_;
52 Carp::croak("Game::Shogi::Error: no such refusal '" . ($code // 'undef') . "'")
53 30 ▶ unless defined $code && exists $MESSAGE{$code};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code and exists $MESSAGE{$code} 1 29 30
Condition60%3/5
defined $code and exists $MESSAGE{$code}
!ll&&!rl&&r
0129
$code // "undef"
l!l
10
MC/DC50%1/2
defined $code and exists $MESSAGE{$code}
defined $code exists $MESSAGE{$code}
MC/DC0%0/1
$code // "undef"
$code
Truth table66%2/3
A and B
A= defined $codeB= exists $MESSAGE{$code}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $code
Aresult
11
00
54 29 my $message = $MESSAGE{$code};
55 29 ▶ $message .= ": $detail" if defined $detail && length $detail;
Branch: 1 branch
BranchTrueFalseTotal
if defined $detail and length $detail 3 26 29
Condition66%2/3
defined $detail and length $detail
!ll&&!rl&&r
2603
MC/DC50%1/2
defined $detail and length $detail
defined $detail length $detail
Truth table66%2/3
A and B
A= defined $detailB= length $detail
ABresult
0X0
100
111
56 29 return $class->new(code => $code, message => $message);
57 }
58  
59 19 ▶sub of_fault {
Subroutine of_fault: called CC=5 SCAR=20.9
Pod documented
60 19 my ($class, $fault) = @_;
61 19 ▶ return undef unless defined $fault && $fault =~ /\A[0-9]+\z/ && $fault >= 1 && $FAULT[$fault];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fault and $fault =~ /\A[0-9]+\z/u and $fault >= 1 and $FAULT[$fault] 0 19 19
Condition33%3/9
defined $fault and $fault =~ /\A[0-9]+\z/u and $fault >= 1 and $FAULT[$fault]
!ll&&!rl&&r
0019
defined $fault and $fault =~ /\A[0-9]+\z/u and $fault >= 1
!ll&&!rl&&r
0019
defined $fault and $fault =~ /\A[0-9]+\z/u
!ll&&!rl&&r
0019
MC/DC0%0/4
defined $fault and $fault =~ /\A[0-9]+\z/u and $fault >= 1 and $FAULT[$fault]
defined $fault $fault =~ /\A[0-9]+\z/u $fault >= 1 $FAULT[$fault]
Truth table20%1/5
A and B and C and D
A= defined $faultB= $fault =~ /\A[0-9]+\z/uC= $fault >= 1D= $FAULT[$fault]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
62 19 return $class->throw($FAULT[$fault]);
63 }
64  
65 1 ▶sub codes { @CODES }
Subroutine codes: called CC=1 SCAR=0.0
Pod documented
66 0 ▶sub known { defined $_[1] && exists $MESSAGE{ $_[1] } ? 1 : 0 }
Subroutine known: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] && exists $MESSAGE{$_[1]} ? : 0 0 0
Condition0%0/3
defined $_[1] and exists $MESSAGE{$_[1]}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[1] and exists $MESSAGE{$_[1]}
defined $_[1] exists $MESSAGE{$_[1]}
Truth table0%0/3
A and B
A= defined $_[1]B= exists $MESSAGE{$_[1]}
ABresult
0X0
100
111
67 11 ▶sub message_for { defined $_[1] ? $MESSAGE{ $_[1] } : undef }
Subroutine message_for: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 11 0 11
68 0 ▶sub stringify { $_[0]->message }
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
69  
70 9 1;
71  
72 __END__
« blib/lib/Game/Shogi/Bot.pm ↑ Summary blib/lib/Game/Shogi/Engine.pm »