blib/lib/Game/Snake/Result.pm

filter: Statementstmt 100% 38 / 38 Branchbran 91.6% 11 / 12 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 9 / 9 Podpod 75.0% 3 / 4 totaltotal 94.5% 69 / 73 CC 10 SCAR 14.7
CC
10
Cov
96%
BUILD
8.1
died
2.0
stringify
2.0
CRAP 4.4
« blib/lib/Game/Snake/Bot.pm ↑ Summary blib/lib/Game/Snake/Error.pm »
1 package Game::Snake::Result;
2  
3 15 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 15 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 15 our $VERSION = '0.12';
11  
12 15 our @CAUSES = qw/ wall body full quit /;
13  
14 15 my %IS_CAUSE = map { $_ => 1 } @CAUSES;
15  
16 15 my %SENTENCE = (
17 wall => 'hit the wall',
18 body => 'ran into yourself',
19 full => 'filled the board',
20 quit => 'quit',
21 );
22  
23 has cause => (
24 is => 'ro',
25 isa => Str
26 15 );
27  
28 has score => (
29 is => 'ro',
30 isa => Int,
31 default => 0
32 15 );
33  
34 has length => (
35 is => 'ro',
36 isa => Int,
37 default => 0
38 15 );
39  
40 has ticks => (
41 is => 'ro',
42 isa => Int,
43 default => 0
44 15 );
45  
46 has speed => (
47 is => 'ro',
48 isa => Int,
49 default => 0
50 15 );
51  
52 51 ▶sub BUILD {
Subroutine BUILD: called CC=8 SCAR=20.9
Pod undocumented
53 51 my ($self) = @_;
54  
55 51 my $cause = $self->cause;
56 Carp::croak("Game::Snake::Result: '" . (defined $cause ? $cause : 'undef')
57 . "' is not a cause")
58 51 ▶ unless defined $cause && $IS_CAUSE{$cause};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $cause and $IS_CAUSE{$cause} 2 49 51
defined $cause ? : 1 1 2
Condition100%3/3
defined $cause and $IS_CAUSE{$cause}
!ll&&!rl&&r
1149
MC/DC100%2/2
defined $cause and $IS_CAUSE{$cause}
defined $cause $IS_CAUSE{$cause}
Truth table100%3/3
A and B
A= defined $causeB= $IS_CAUSE{$cause}
ABresult
0X0
100
111
59  
60 49 for my $name (qw/ score length ticks speed /) {
61 193 my $value = $self->$name;
62 193 ▶ Carp::croak("Game::Snake::Result: $name must be a whole number, not "
Branch: 2 branches
BranchTrueFalseTotal
unless defined $value and $value =~ /\A[0-9]+\z/u 1 192 193
defined $value ? : 1 0 1
Condition66%2/3
defined $value and $value =~ /\A[0-9]+\z/u
!ll&&!rl&&r
01192
MC/DC50%1/2
defined $value and $value =~ /\A[0-9]+\z/u
defined $value $value =~ /\A[0-9]+\z/u
Truth table66%2/3
A and B
A= defined $valueB= $value =~ /\A[0-9]+\z/u
ABresult
0X0
100
111
63 . (defined $value ? "'$value'" : 'undef'))
64 unless defined $value && $value =~ /\A[0-9]+\z/;
65 }
66  
67 48 return;
68 }
69  
70 1 ▶sub causes { return [@CAUSES] }
Subroutine causes: called CC=1 SCAR=0.0
Pod documented
71  
72 37 ▶sub died {
Subroutine died: called CC=2 SCAR=6.9
Pod documented
73 37 my ($self) = @_;
74 37 ▶ return $self->cause eq 'quit' ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->cause eq 'quit' ? : 24 13 37
75 }
76  
77 34 ▶sub stringify {
Subroutine stringify: called CC=2 SCAR=6.9
Pod documented
78 34 my ($self) = @_;
79 34 my $tail = sprintf '%s at %d points, %d long', $SENTENCE{ $self->cause },
80 $self->score, $self->length;
81 34 ▶ return $self->died ? "Game over: $tail" : ucfirst $tail;
Branch: 1 branch
BranchTrueFalseTotal
$self->died ? : 11 23 34
82 }
83  
84 15 1;
85  
86 __END__
« blib/lib/Game/Snake/Bot.pm ↑ Summary blib/lib/Game/Snake/Error.pm »