| 1 | package Game::Snake::Error; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 15 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 15 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 15 | our $VERSION = '0.12'; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 15 | our (@CODES, %MESSAGE); | |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 15 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 15 | @CODES = qw/ same_direction reverse not_active /; | |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 15 | %MESSAGE = ( | |||||||||||||||||||||||||||||||
| 18 | same_direction => 'the snake is already heading that way', | ||||||||||||||||||||||||||||||||
| 19 | reverse => 'a snake cannot turn back on itself', | ||||||||||||||||||||||||||||||||
| 20 | not_active => 'this game has finished', | ||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | has code => ( | ||||||||||||||||||||||||||||||||
| 25 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 26 | isa => Str | ||||||||||||||||||||||||||||||||
| 27 | 15 | ); | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | has message => ( | ||||||||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 31 | isa => Str | ||||||||||||||||||||||||||||||||
| 32 | 15 | ); | |||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | has error => ( | ||||||||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 36 | default => 1 | ||||||||||||||||||||||||||||||||
| 37 | 15 | ); | |||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 8 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 40 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 41 | 8 | my $code = $self->code; | |||||||||||||||||||||||||||||||
| 42 | Carp::croak("Game::Snake::Error: '" . (defined $code ? $code : 'undef') | ||||||||||||||||||||||||||||||||
| 43 | . "' is not a code") | ||||||||||||||||||||||||||||||||
| 44 | 8 | ▶ | unless defined $code && $MESSAGE{$code}; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $code and $Game::Snake::Error::MESSAGE{$code}
MC/DC50%1/2
defined $code and $Game::Snake::Error::MESSAGE{$code}
defined $code
$Game::Snake::Error::MESSAGE{$code}
Truth table66%2/3
A and B
A= defined $codeB= $Game::Snake::Error::MESSAGE{$code}
| |||||||||||||||||||||||||||||||||
| 45 | 7 | return; | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 9 | ▶ | sub of { | ||||||||||||||||||||||||||||||
|
Subroutine
of: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 49 | 9 | my ($class, $code) = @_; | |||||||||||||||||||||||||||||||
| 50 | Carp::croak("Game::Snake::Error: '" . (defined $code ? $code : 'undef') | ||||||||||||||||||||||||||||||||
| 51 | . "' is not a code") | ||||||||||||||||||||||||||||||||
| 52 | 9 | ▶ | unless defined $code && $MESSAGE{$code}; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
defined $code and $Game::Snake::Error::MESSAGE{$code}
MC/DC100%2/2
defined $code and $Game::Snake::Error::MESSAGE{$code}
defined $code
$Game::Snake::Error::MESSAGE{$code}
Truth table100%3/3
A and B
A= defined $codeB= $Game::Snake::Error::MESSAGE{$code}
| |||||||||||||||||||||||||||||||||
| 53 | 7 | return $class->new(code => $code, message => $MESSAGE{$code}); | |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 3 | ▶ | sub codes { return [@CODES] } | ||||||||||||||||||||||||||||||
|
Subroutine
codes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | sub messages { return { %MESSAGE } } | ||||||||||||||||||||||||||||||
|
Subroutine
messages: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 61 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 62 | 1 | return $self->code . ': ' . $self->message; | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 15 | 1; | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||||||||||||||