Dominoes/Error.pm

filter: Statementstmt 89.2% 25 / 28 Branchbran 75.0% 3 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 87.5% 7 / 8 Podpod 100% 4 / 4 totaltotal 78.0% 39 / 50 CC 6 SCAR 14.3
CC
6
Cov
78%
stringify
12.0
code
3.0
throw
2.0
CRAP 4.2
« Dominoes/Set.pm ↑ Summary Dominoes/Play.pm »
1 package Game::Dominoes::Error;
2  
3 12 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
5  
6 12 ▶use Object::Proto::Sugar -types;
Subroutine __ANON__: called CC=1 SCAR=0.0
7  
8 12 our $VERSION = '0.03';
9  
10 12 our (@FLAGS, %MESSAGE);
11  
12 12 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 12 @FLAGS = qw/
14 not_your_turn
15 tile_not_held
16 end_mismatch
17 no_such_arm
18 arm_closed
19 game_over
20 bad_move
21 /;
22  
23 12 %MESSAGE = (
24 not_your_turn => 'it is not your turn',
25 tile_not_held => 'you do not hold that tile',
26 end_mismatch => 'that tile does not match that end',
27 no_such_arm => 'there is no such arm',
28 arm_closed => 'that arm is not open yet',
29 game_over => 'the game is over',
30 bad_move => 'that is not a move',
31 );
32 }
33  
34 has [@FLAGS] => (
35 is => 'ro'
36 12 );
37  
38 has error => (
39 is => 'ro',
40 default => 1
41 12 );
42  
43 has message => (
44 is => 'ro',
45 isa => Str
46 12 );
47  
48 has legal => (
49 is => 'ro',
50 isa => ArrayRef,
51 default => []
52 12 );
53  
54 17 ▶sub throw {
Subroutine throw: called CC=2 SCAR=7.1
Pod documented
55 17 my ($class, $flag, %extra) = @_;
56 17 ▶ die "'$flag' is not an error flag" unless $MESSAGE{$flag};
Branch: 1 branch
BranchTrueFalseTotal
unless $Game::Dominoes::Error::MESSAGE{$flag} 0 17 17
57 return $class->new(
58 $flag => 1,
59 17 message => $MESSAGE{$flag},
60 %extra
61 );
62 }
63  
64 16 ▶sub code {
Subroutine code: called CC=3 SCAR=11.1
Pod documented
65 16 my ($self) = @_;
66 16 for my $flag (@FLAGS) {
67 71 ▶ return $flag if $self->$flag;
Branch: 1 branch
BranchTrueFalseTotal
if $self->$flag 16 55 71
68 }
69 0 return undef;
70 }
71  
72 1 ▶sub flags {
Subroutine flags: called CC=1 SCAR=0.0
Pod documented
73 1 return [@FLAGS];
74 }
75  
76 0 ▶sub stringify {
Subroutine stringify: not called CC=3 SCAR=24.8
Pod documented
77 0 my ($self) = @_;
78 0 ▶ return ($self->code // 'error') . ': ' . ($self->message // '');
Condition0%0/4
$self->code // "error"
l!l
00
$self->message // ""
l!l
00
MC/DC0%0/1
$self->code // "error"
$self->code
MC/DC0%0/1
$self->message // ""
$self->message
Truth table0%0/2
A
A= $self->code
Aresult
11
00
Truth table0%0/2
A
A= $self->message
Aresult
11
00
79 }
80  
81 12 1;
82  
83 __END__
« Dominoes/Set.pm ↑ Summary Dominoes/Play.pm »