blib/lib/Game/Xiangqi/Error.pm

filter: Statementstmt 90.6% 29 / 32 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 10 / 12 Podpod 100% 6 / 6 totaltotal 89.2% 50 / 56 CC 5 SCAR 5.7
CC
5
Cov
89%
code
3.0
throw
2.0
stringify
2.0
CRAP 1.8
« blib/arch/Game/Xiangqi/Install/Files.pm ↑ Summary xq_engine.c »
1 package Game::Xiangqi::Error;
2  
3 9 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
6  
7 9 ▶use Object::Proto::Sugar -types;
Subroutine __ANON__: called CC=1 SCAR=0.0
8  
9 9 our $VERSION = '0.03';
10  
11 9 our @FLAGS;
12 9 ▶BEGIN {
Subroutine __ANON__: called CC=1 SCAR=0.0
13 9 @FLAGS = qw(
14 bad_move
15 game_over
16 not_your_turn
17 no_piece
18 own_piece
19 not_legal
20  
21 in_check
22 generals_face
23  
24 general_leaves_palace
25 advisor_leaves_palace
26 elephant_crosses_river
27 elephant_eye_blocked
28 horse_leg_blocked
29 cannon_needs_one_screen
30 soldier_no_retreat
31 soldier_no_sideways
32 );
33 }
34  
35 9 our %MESSAGE;
36 9 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
37 9 %MESSAGE = (
38 bad_move => 'that is not a move',
39 game_over => 'the game is already over',
40 not_your_turn => 'it is not your turn',
41 no_piece => 'there is no piece there',
42 own_piece => 'one of your own pieces is already there',
43 not_legal => 'that piece cannot move there',
44  
45 in_check => 'that would leave your general in check',
46 generals_face => 'that would leave the two generals facing each other',
47  
48 general_leaves_palace => 'the general never leaves its palace',
49 advisor_leaves_palace => 'the advisor never leaves its palace',
50 elephant_crosses_river => 'the elephant never crosses the river',
51 elephant_eye_blocked => 'the elephant is blocked at its eye',
52 horse_leg_blocked => 'the horse is hobbled at its leg',
53 cannon_needs_one_screen => 'a cannon captures only by jumping exactly one piece',
54 soldier_no_retreat => 'a soldier never moves backward',
55 soldier_no_sideways => 'a soldier moves sideways only once it has crossed the river',
56 );
57 }
58  
59 9 has [@FLAGS] => (is => 'ro');
60  
61 9 has error => (is => 'ro', default => 1);
62  
63 9 has message => (is => 'ro', isa => Str, default => '');
64  
65 9 has legal => (is => 'ro', isa => ArrayRef, default => []);
66  
67 43 ▶sub throw {
Subroutine throw: called CC=2 SCAR=7.1
Pod documented
68 43 my ($class, $flag, %extra) = @_;
69 43 ▶ die "Game::Xiangqi::Error: no such flag '$flag'" unless exists $MESSAGE{$flag};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Game::Xiangqi::Error::MESSAGE{$flag} 0 43 43
70 return $class->new(
71 $flag => 1,
72 error => 1,
73 43 message => $MESSAGE{$flag},
74 %extra,
75 );
76 }
77  
78 19 ▶sub code {
Subroutine code: called CC=3 SCAR=11.1
Pod documented
79 19 my ($self) = @_;
80 19 for my $flag (@FLAGS) {
81 149 ▶ return $flag if $self->$flag;
Branch: 1 branch
BranchTrueFalseTotal
if $self->$flag 19 130 149
82 }
83 0 return undef;
84 }
85  
86 0 ▶sub stringify { $_[0]->message }
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
87  
88 0 ▶sub flags { @FLAGS }
Subroutine flags: not called CC=1 SCAR=6.9
Pod documented
89  
90 1 ▶sub message_for { $MESSAGE{ $_[1] } }
Subroutine message_for: called CC=1 SCAR=0.0
Pod documented
91  
92 17 ▶sub known { exists $MESSAGE{ $_[1] } ? 1 : 0 }
Subroutine known: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
exists $Game::Xiangqi::Error::MESSAGE{$_[1]} ? : 16 1 17
93  
94 9 1;
95  
96 __END__
« blib/arch/Game/Xiangqi/Install/Files.pm ↑ Summary xq_engine.c »