blib/lib/Game/Merrills/Error.pm

filter: Statementstmt 96.5% 28 / 29 Branchbran 100% 6 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 5 / 5 totaltotal 98.1% 54 / 55 CC 6 SCAR 7.9
CC
6
Cov
97%
throw
4.0
code
3.0
__ANON__
1.0
CRAP 2.2
« blib/lib/Game/Merrills/Points.pm ↑ Summary bin/merrills »
1 package Game::Merrills::Error;
2  
3 80 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 80 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
5  
6 80 ▶use Object::Proto::Sugar -types;
Subroutine __ANON__: called CC=1 SCAR=0.0
7  
8 80 our $VERSION = '0.02';
9  
10 80 our (@FLAGS, %MESSAGE);
11  
12 80 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 80 @FLAGS = qw/
14 game_over
15 not_a_move
16 men_in_hand
17 no_men_in_hand
18 not_your_man
19 occupied
20 not_adjacent
21 must_remove
22 nothing_to_remove
23 no_man_there
24 man_in_mill
25 not_legal
26 no_offer
27 nothing_to_undo
28 /;
29  
30 80 %MESSAGE = (
31 game_over => 'the game is over',
32 not_a_move => 'that is not a move',
33 men_in_hand => 'you still have men to place, so place one',
34 no_men_in_hand => 'every man is placed, so move one',
35 not_your_man => 'you have no man on that point',
36 occupied => 'that point is not empty',
37 not_adjacent => 'a man moves along a line to the next point',
38 must_remove => 'that closes a mill, so say which man you take',
39 nothing_to_remove => 'that closes no mill, so it takes no man',
40 no_man_there => 'there is no man of theirs on that point to take',
41 man_in_mill => 'a man in a mill is safe while another stands outside one',
42 not_legal => 'that is not a legal move',
43 no_offer => 'there is no draw to answer',
44 nothing_to_undo => 'there is nothing to undo',
45 );
46 }
47  
48 has [@FLAGS] => (
49 is => 'ro'
50 80 );
51  
52 has error => (
53 is => 'ro',
54 default => 1
55 80 );
56  
57 has message => (
58 is => 'ro',
59 isa => Str
60 80 );
61  
62 has legal => (
63 is => 'ro',
64 isa => ArrayRef,
65 2 ▶ default => sub { [] }
Subroutine __ANON__: called CC=1 SCAR=0.0
66 80 );
67  
68 16990 ▶sub throw {
Subroutine throw: called CC=4 SCAR=13.9
Pod documented
69 16990 my ($class, $flag, %extra) = @_;
70 die "'" . (defined $flag ? $flag : 'undef') . "' is not an error flag"
71 16990 ▶ unless defined $flag && $MESSAGE{$flag};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $flag and $Game::Merrills::Error::MESSAGE{$flag} 2 16988 16990
defined $flag ? : 1 1 2
Condition100%3/3
defined $flag and $Game::Merrills::Error::MESSAGE{$flag}
!ll&&!rl&&r
1116988
MC/DC100%2/2
defined $flag and $Game::Merrills::Error::MESSAGE{$flag}
defined $flag $Game::Merrills::Error::MESSAGE{$flag}
Truth table100%3/3
A and B
A= defined $flagB= $Game::Merrills::Error::MESSAGE{$flag}
ABresult
0X0
100
111
72 return $class->new(
73 $flag => 1,
74 16988 message => $MESSAGE{$flag},
75 %extra
76 );
77 }
78  
79 47 ▶sub flags {
Subroutine flags: called CC=1 SCAR=0.0
Pod documented
80 47 return @FLAGS;
81 }
82  
83 48 ▶sub messages {
Subroutine messages: called CC=1 SCAR=0.0
Pod documented
84 48 return {%MESSAGE};
85 }
86  
87 33838 ▶sub code {
Subroutine code: called CC=3 SCAR=11.1
Pod documented
88 33838 my ($self) = @_;
89 33838 for my $flag (@FLAGS) {
90 157471 ▶ return $flag if $self->$flag;
Branch: 1 branch
BranchTrueFalseTotal
if $self->$flag 33838 123633 157471
91 }
92 0 return undef;
93 }
94  
95 1 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
Pod documented
96 1 return $_[0]->message;
97 }
98  
99 80 1;
100  
101 __END__
« blib/lib/Game/Merrills/Points.pm ↑ Summary bin/merrills »