blib/lib/Game/Mahjong/Error.pm

filter: Statementstmt 89.6% 26 / 29 Branchbran 50.0% 3 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 77.7% 7 / 9 Podpod 100% 4 / 4 totaltotal 77.3% 41 / 53 CC 6 SCAR 11.0
CC
6
Cov
79%
throw
6.0
code
3.0
flags
2.0
CRAP 3.0
« blib/lib/Game/Mahjong/Hand.pm ↑ Summary blib/lib/Game/Mahjong/Tally.pm »
1 package Game::Mahjong::Error;
2  
3 34 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 34 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
5 34 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
6  
7 34 ▶use Object::Proto::Sugar -types;
Subroutine __ANON__: called CC=1 SCAR=0.0
8  
9 34 our $VERSION = '0.03';
10  
11 34 our (@FLAGS, %MESSAGE);
12  
13 34 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
14 34 @FLAGS = qw/
15 not_your_turn wrong_phase tile_not_held cannot_claim not_a_meld
16 no_kong not_a_win too_few_points no_window already_answered
17 game_over bad_move
18 /;
19  
20 34 %MESSAGE = (
21 not_your_turn => 'it is not your turn',
22 wrong_phase => 'that is not what the game is waiting for',
23 tile_not_held => 'you do not hold that tile',
24 cannot_claim => 'you cannot claim that tile',
25 not_a_meld => 'those tiles do not make a set with it',
26 no_kong => 'you cannot declare a kong now',
27 not_a_win => 'that hand is not complete',
28 too_few_points => 'that hand is worth fewer than eight points',
29 no_window => 'there is nothing to answer',
30 already_answered => 'you have already answered',
31 game_over => 'this game has finished',
32 bad_move => 'that is not a move',
33 );
34 }
35  
36 34 has [@FLAGS] => (is => 'ro');
37  
38 has error => (
39 is => 'ro',
40 default => 1
41 34 );
42  
43 has message => (
44 is => 'ro',
45 isa => Str
46 34 );
47  
48 has legal => (
49 is => 'ro',
50 isa => ArrayRef,
51 default => []
52 34 );
53  
54 24 ▶sub throw {
Subroutine throw: called CC=4 SCAR=17.9
Pod documented
55 24 my ($class, $flag, %extra) = @_;
56 die "'" . (defined $flag ? $flag : 'undef') . "' is not an error flag"
57 24 ▶ unless defined $flag && $MESSAGE{$flag};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $flag and $Game::Mahjong::Error::MESSAGE{$flag} 0 24 24
defined $flag ? : 0 0 0
Condition33%1/3
defined $flag and $Game::Mahjong::Error::MESSAGE{$flag}
!ll&&!rl&&r
0024
MC/DC0%0/2
defined $flag and $Game::Mahjong::Error::MESSAGE{$flag}
defined $flag $Game::Mahjong::Error::MESSAGE{$flag}
Truth table33%1/3
A and B
A= defined $flagB= $Game::Mahjong::Error::MESSAGE{$flag}
ABresult
0X0
100
111
58 24 return $class->new($flag => 1, message => $MESSAGE{$flag}, %extra);
59 }
60  
61 24 ▶sub code {
Subroutine code: called CC=3 SCAR=11.1
Pod documented
62 24 my ($self) = @_;
63 24 for my $flag (@FLAGS) {
64 154 ▶ return $flag if $self->$flag;
Branch: 1 branch
BranchTrueFalseTotal
if $self->$flag 24 130 154
65 }
66 0 return undef;
67 }
68  
69 0 ▶sub flags { return [@FLAGS] }
Subroutine flags: not called CC=1 SCAR=6.9
Pod documented
70  
71 0 ▶sub messages { return { %MESSAGE } }
Subroutine messages: not called CC=1 SCAR=6.9
Pod documented
72  
73 34 1;
74  
75 __END__
« blib/lib/Game/Mahjong/Hand.pm ↑ Summary blib/lib/Game/Mahjong/Tally.pm »