Reversi/Error.pm

filter: Statementstmt 96.4% 27 / 28 Branchbran 100% 4 / 4 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 90.0% 45 / 50 CC 6 SCAR 7.7
CC
6
Cov
92%
stringify
3.3
code
3.0
throw
2.0
CRAP 2.2
« Reversi/Scoring.pm ↑ Summary Reversi/Opening.pm »
1 package Game::Reversi::Error;
2  
3 13 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 13 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
5  
6 13 ▶use Object::Proto::Sugar -types;
Subroutine __ANON__: called CC=1 SCAR=0.0
7  
8 13 our $VERSION = '0.03';
9  
10 13 our (@FLAGS, %MESSAGE);
11  
12 13 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 13 @FLAGS = qw/
14 not_centre
15 square_taken
16 not_your_turn
17 no_flip
18 has_move
19 game_over
20 /;
21  
22 13 %MESSAGE = (
23 not_centre => 'the first four discs go in the centre four',
24 square_taken => 'that square is already taken',
25 not_your_turn => 'it is not your turn',
26 no_flip => 'that move outflanks nothing',
27 has_move => 'you have a move, so your turn cannot be forfeited',
28 game_over => 'the game is over',
29 );
30 }
31  
32 has [@FLAGS] => (
33 is => 'ro'
34 13 );
35  
36 has error => (
37 is => 'ro',
38 default => 1
39 13 );
40  
41 has message => (
42 is => 'ro',
43 isa => Str
44 13 );
45  
46 has legal => (
47 is => 'ro',
48 isa => ArrayRef,
49 default => []
50 13 );
51  
52 101 ▶sub throw {
Subroutine throw: called CC=2 SCAR=6.9
Pod documented
53 101 my ($class, $flag, %extra) = @_;
54 101 ▶ die "'$flag' is not an error flag" unless $MESSAGE{$flag};
Branch: 1 branch
BranchTrueFalseTotal
unless $Game::Reversi::Error::MESSAGE{$flag} 1 100 101
55 return $class->new(
56 $flag => 1,
57 100 message => $MESSAGE{$flag},
58 %extra
59 );
60 }
61  
62 103 ▶sub code {
Subroutine code: called CC=3 SCAR=11.1
Pod documented
63 103 my ($self) = @_;
64 103 for my $flag (@FLAGS) {
65 452 ▶ return $flag if $self->$flag;
Branch: 1 branch
BranchTrueFalseTotal
if $self->$flag 103 349 452
66 }
67 0 return undef;
68 }
69  
70 1 ▶sub flags { return [@FLAGS] }
Subroutine flags: called CC=1 SCAR=0.0
Pod documented
71  
72 5 ▶sub stringify {
Subroutine stringify: called CC=3 SCAR=12.0
Pod documented
73 5 my ($self) = @_;
74 5 ▶ return ($self->code // 'error') . ': ' . ($self->message // '');
Condition50%2/4
$self->code // "error"
l!l
50
$self->message // ""
l!l
50
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
75 }
76  
77 13 1;
78  
79 __END__
« Reversi/Scoring.pm ↑ Summary Reversi/Opening.pm »