blib/lib/Game/RoyalUr/Error.pm

filter: Statementstmt 100% 28 / 28 Branchbran 100% 2 / 2 Conditioncond 57.1% 4 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 88.6% 47 / 53 CC 5 SCAR 7.5
CC
5
Cov
92%
of
4.1
message_for
2.1
__ANON__
1.0
CRAP 2.1
« blib/lib/Game/RoyalUr/Rules.pm ↑ Summary blib/arch/Game/RoyalUr/Install/Files.pm »
1 package Game::RoyalUr::Error;
2  
3 58 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 58 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
5 58 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
6  
7 58 ▶use Carp ();
Subroutine __ANON__: called CC=1 SCAR=0.0
8 58 ▶use Object::Proto::Sugar;
Subroutine __ANON__: called CC=1 SCAR=0.0
9  
10 58 our $VERSION = '0.02';
11  
12 58 my (@CODES, %MESSAGE);
13 58 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
14 58 @CODES = qw(
15 game_over
16 no_roll
17 bad_move
18 no_piece
19 not_your_piece
20 wrong_distance
21 own_piece
22 safe_rosette
23 overshoot
24 bad_record
25 );
26 58 %MESSAGE = (
27 game_over => 'the game is already over',
28 no_roll => 'there is no roll to play: the record this game was read from ends here',
29 bad_move => 'that is not a move',
30 no_piece => 'you have no piece there',
31 not_your_piece => 'that piece is not yours',
32 wrong_distance => 'a piece moves exactly as far as the roll',
33 own_piece => 'one of your own pieces is already on that square',
34 safe_rosette => 'a piece on a rosette cannot be captured',
35 overshoot => 'a piece leaves the board only on the exact roll',
36 bad_record => 'the record does not agree with the game it describes',
37 );
38 }
39  
40 58 has code => (is => 'ro');
41  
42 58 has message => (is => 'ro');
43  
44 58 has detail => (is => 'ro');
45  
46 2 ▶sub codes { @CODES }
Subroutine codes: called CC=1 SCAR=0.0
Pod documented
47  
48 11 ▶sub message_for {
Subroutine message_for: called CC=2 SCAR=7.2
Pod documented
49 11 my ($class, $code) = @_;
50 11 ▶ return $MESSAGE{ $code // '' };
Condition50%1/2
$code // ""
l!l
110
MC/DC0%0/1
$code // ""
$code
Truth table50%1/2
A
A= $code
Aresult
11
00
51 }
52  
53 47756 ▶sub of {
Subroutine of: called CC=4 SCAR=14.2
Pod documented
54 47756 my ($class, $code, %detail) = @_;
55 Carp::croak("Game::RoyalUr::Error: no such refusal as '" . ($code // 'undef') . "'")
56 47756 ▶ unless defined $code && exists $MESSAGE{$code};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code and exists $MESSAGE{$code} 1 47755 47756
Condition60%3/5
defined $code and exists $MESSAGE{$code}
!ll&&!rl&&r
0147755
$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
57 47755 return $class->new(code => $code, message => $MESSAGE{$code}, detail => { %detail });
58 }
59  
60 58 1;
61  
62 __END__
« blib/lib/Game/RoyalUr/Rules.pm ↑ Summary blib/arch/Game/RoyalUr/Install/Files.pm »