blib/lib/Game/Checkers/Error.pm

filter: Statementstmt 96.1% 25 / 26 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 95.0% 38 / 40 CC 4 SCAR 6.0
CC
4
Cov
93%
code
3.0
throw
2.0
__ANON__
1.0
CRAP 1.8
« blib/lib/Game/Checkers/Piece.pm ↑ Summary blib/lib/Game/Checkers/Move.pm »
1 package Game::Checkers::Error;
2  
3 30 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 30 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
5  
6 30 ▶use Object::Proto::Sugar -types;
Subroutine __ANON__: called CC=1 SCAR=0.0
7  
8 30 our $VERSION = '0.04';
9  
10 30 our (@FLAGS, %MESSAGE);
11  
12 # has is installed through BEGIN::Lift, so it runs at compile time: a list it is
13 # given must be built at compile time too
14 30 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
15 30 @FLAGS = qw/
16 game_over
17 not_a_move
18 not_your_piece
19 must_capture
20 wrong_direction
21 occupied
22 not_legal
23 ambiguous
24 no_offer
25 nothing_to_undo
26 /;
27  
28 30 %MESSAGE = (
29 game_over => 'the game is over',
30 not_a_move => 'that is not a move',
31 not_your_piece => 'you have no piece on that square',
32 must_capture => 'a capture is available, so it must be taken',
33 wrong_direction => 'a man cannot move backwards',
34 occupied => 'that square is not empty',
35 not_legal => 'that is not a legal move',
36 ambiguous => 'that could be more than one move, so give the whole path',
37 no_offer => 'there is no draw to accept',
38 nothing_to_undo => 'there is nothing to undo',
39 );
40 }
41  
42 has [@FLAGS] => (
43 is => 'ro'
44 30 );
45  
46 has error => (
47 is => 'ro',
48 default => 1
49 30 );
50  
51 has message => (
52 is => 'ro',
53 isa => Str
54 30 );
55  
56 has legal => (
57 is => 'ro',
58 isa => ArrayRef,
59 default => []
60 30 );
61  
62 39 ▶sub throw {
Subroutine throw: called CC=2 SCAR=7.1
Pod documented
63 39 my ($class, $flag, %extra) = @_;
64 39 ▶ die "'$flag' is not an error flag" unless $MESSAGE{$flag};
Branch: 1 branch
BranchTrueFalseTotal
unless $Game::Checkers::Error::MESSAGE{$flag} 0 39 39
65 return $class->new(
66 $flag => 1,
67 39 message => $MESSAGE{$flag},
68 %extra
69 );
70 }
71  
72 3 ▶sub code {
Subroutine code: called CC=3 SCAR=11.1
Pod documented
73 3 my ($self) = @_;
74 3 for my $flag (@FLAGS) {
75 17 ▶ return $flag if $self->$flag;
Branch: 1 branch
BranchTrueFalseTotal
if $self->$flag 3 14 17
76 }
77 0 return undef;
78 }
79  
80 1 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
Pod documented
81 1 return $_[0]->message;
82 }
83  
84 30 1;
85  
86 __END__
« blib/lib/Game/Checkers/Piece.pm ↑ Summary blib/lib/Game/Checkers/Move.pm »