blib/lib/Game/RoyalUr/Error.pm

filter: Statementstmt 85.7% 12 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 89.4% 17 / 19 CC 1 SCAR 0.6
CC
1
Cov
86%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/lib/Game/RoyalUr/Bot.pm ↑ Summary blib/lib/Game/RoyalUr/Result.pm »
1 package Game::RoyalUr::Error;
2  
3 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 0 ▶use Object::Proto::Sugar;
Subroutine BEGIN: called CC=1 SCAR=2.6
9  
10 our $VERSION = '0.03';
11  
12 my (@CODES, %MESSAGE);
13 BEGIN {
14 @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 %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 has code => (is => 'ro');
41  
42 has message => (is => 'ro');
43  
44 has detail => (is => 'ro');
45  
46 sub codes { @CODES }
47  
48 sub message_for {
49 my ($class, $code) = @_;
50 return $MESSAGE{ $code // '' };
51 }
52  
53 sub of {
54 my ($class, $code, %detail) = @_;
55 Carp::croak("Game::RoyalUr::Error: no such refusal as '" . ($code // 'undef') . "'")
56 unless defined $code && exists $MESSAGE{$code};
57 return $class->new(code => $code, message => $MESSAGE{$code}, detail => { %detail });
58 }
59  
60 1;
61  
62 __END__
« blib/lib/Game/RoyalUr/Bot.pm ↑ Summary blib/lib/Game/RoyalUr/Result.pm »