| 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
Condition100%3/3
defined $flag and $Game::Oware::Error::MESSAGE{$flag}
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}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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"
$self->message // ""
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
Truth table50%1/2
A
A= $self->message
| |||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 17 | 1; | |||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | __END__ | ||||||||||||||||||||||||||||||||