blib/lib/Game/Oware/Error.pm

filter: Statementstmt 96.5% 28 / 29 Branchbran 100% 6 / 6 Conditioncond 71.4% 5 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 91.6% 55 / 60 CC 8 SCAR 9.4
CC
8
Cov
93%
throw
4.0
stringify
3.3
code
3.0
CRAP 2.6
« blib/lib/Game/Oware/Board.pm ↑ Summary blib/lib/Game/Oware/Scoring.pm »
1 package Game::Oware::Error;
2  
3 17 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 17 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
5  
6 17 ▶use Object::Proto::Sugar -types;
Subroutine __ANON__: called CC=1 SCAR=0.0
7  
8 17 our $VERSION = '0.03';
9  
10 17 our (@FLAGS, %MESSAGE);
11  
12 17 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 17 @FLAGS = qw/ not_your_turn not_your_house empty_house must_feed game_over /;
14  
15 17 %MESSAGE = (
16 not_your_turn => 'it is not your turn',
17 not_your_house => 'that house is on your opponent side of the board',
18 empty_house => 'that house has no seeds in it',
19 must_feed => 'your opponent has no seeds, so you must play a house '
20 . 'that reaches them',
21 game_over => 'this game has finished',
22 );
23 }
24  
25 17 has [@FLAGS] => (is => 'ro');
26  
27 has error => (
28 is => 'ro',
29 default => 1
30 17 );
31  
32 has message => (
33 is => 'ro',
34 isa => Str
35 17 );
36  
37 has legal => (
38 is => 'ro',
39 isa => ArrayRef,
40 default => []
41 17 );
42  
43 14 ▶sub throw {
Subroutine throw: called CC=4 SCAR=13.9
Pod documented
44 14 my ($class, $flag, %extra) = @_;
45 die "'" . (defined $flag ? $flag : 'undef') . "' is not an error flag"
46 14 ▶ unless defined $flag && $MESSAGE{$flag};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $flag and $Game::Oware::Error::MESSAGE{$flag} 2 12 14
defined $flag ? : 1 1 2
Condition100%3/3
defined $flag and $Game::Oware::Error::MESSAGE{$flag}
!ll&&!rl&&r
1112
MC/DC100%2/2
defined $flag and $Game::Oware::Error::MESSAGE{$flag}
defined $flag $Game::Oware::Error::MESSAGE{$flag}
Truth table100%3/3
A and B
A= defined $flagB= $Game::Oware::Error::MESSAGE{$flag}
ABresult
0X0
100
111
47 12 return $class->new($flag => 1, message => $MESSAGE{$flag}, %extra);
48 }
49  
50 9 ▶sub code {
Subroutine code: called CC=3 SCAR=11.1
Pod documented
51 9 my ($self) = @_;
52 9 for my $flag (@FLAGS) {
53 27 ▶ return $flag if $self->$flag;
Branch: 1 branch
BranchTrueFalseTotal
if $self->$flag 9 18 27
54 }
55 0 return undef;
56 }
57  
58 2 ▶sub flags { return [@FLAGS] }
Subroutine flags: called CC=1 SCAR=0.0
Pod documented
59  
60 1 ▶sub messages { return { %MESSAGE } }
Subroutine messages: called CC=1 SCAR=0.0
Pod documented
61  
62 1 ▶sub stringify {
Subroutine stringify: called CC=3 SCAR=12.0
Pod documented
63 1 my ($self) = @_;
64 1 ▶ return ($self->code // 'error') . ': ' . ($self->message // '');
Condition50%2/4
$self->code // "error"
l!l
10
$self->message // ""
l!l
10
MC/DC0%0/1
$self->code // "error"
$self->code
MC/DC0%0/1
$self->message // ""
$self->message
Truth table50%1/2
A
A= $self->code
Aresult
11
00
Truth table50%1/2
A
A= $self->message
Aresult
11
00
65 }
66  
67 17 1;
68  
69 __END__
« blib/lib/Game/Oware/Board.pm ↑ Summary blib/lib/Game/Oware/Scoring.pm »