blib/lib/Game/Snake/Error.pm

filter: Statementstmt 100% 33 / 33 Branchbran 87.5% 7 / 8 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 94.0% 63 / 67 CC 7 SCAR 8.9
CC
7
Cov
96%
BUILD
4.1
of
4.0
__ANON__
1.0
CRAP 2.4
« blib/lib/Game/Snake/Result.pm ↑ Summary blib/lib/Game/Snake/Ticker.pm »
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
BranchTrueFalseTotal
unless defined $code and $Game::Snake::Error::MESSAGE{$code} 1 7 8
defined $code ? : 1 0 1
Condition66%2/3
defined $code and $Game::Snake::Error::MESSAGE{$code}
!ll&&!rl&&r
017
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}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless defined $code and $Game::Snake::Error::MESSAGE{$code} 2 7 9
defined $code ? : 1 1 2
Condition100%3/3
defined $code and $Game::Snake::Error::MESSAGE{$code}
!ll&&!rl&&r
117
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}
ABresult
0X0
100
111
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__
« blib/lib/Game/Snake/Result.pm ↑ Summary blib/lib/Game/Snake/Ticker.pm »