| 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
Condition33%1/3
defined $flag and $Game::Mahjong::Error::MESSAGE{$flag}
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}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||