blib/lib/Game/Floppy/Result.pm

filter: Statementstmt 100% 37 / 37 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.4% 68 / 72 CC 10 SCAR 14.7
CC
10
Cov
96%
BUILD
8.1
died
2.0
stringify
2.0
CRAP 4.4
« blib/lib/Game/Floppy.pm ↑ Summary blib/lib/Game/Floppy/Bot.pm »
1 package Game::Floppy::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.09';
11  
12 15 our @CAUSES = qw/ ground sky tube quit /;
13  
14 15 my %IS_CAUSE = map { $_ => 1 } @CAUSES;
15  
16 15 my %SENTENCE = (
17 ground => 'fell to the ground',
18 sky => 'flew off the top',
19 tube => 'hit a tube',
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 tubes => (
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 54 ▶sub BUILD {
Subroutine BUILD: called CC=8 SCAR=20.9
Pod undocumented
47 54 my ($self) = @_;
48  
49 54 my $cause = $self->cause;
50 Carp::croak("Game::Floppy::Result: '" . (defined $cause ? $cause : 'undef')
51 . "' is not a cause")
52 54 ▶ unless defined $cause && $IS_CAUSE{$cause};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $cause and $IS_CAUSE{$cause} 2 52 54
defined $cause ? : 1 1 2
Condition100%3/3
defined $cause and $IS_CAUSE{$cause}
!ll&&!rl&&r
1152
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
53  
54 52 for my $name (qw/ score tubes ticks /) {
55 154 my $value = $self->$name;
56 154 ▶ Carp::croak("Game::Floppy::Result: $name must be a whole number, not "
Branch: 2 branches
BranchTrueFalseTotal
unless defined $value and $value =~ /\A[0-9]+\z/u 1 153 154
defined $value ? : 1 0 1
Condition66%2/3
defined $value and $value =~ /\A[0-9]+\z/u
!ll&&!rl&&r
01153
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
57 . (defined $value ? "'$value'" : 'undef'))
58 unless defined $value && $value =~ /\A[0-9]+\z/;
59 }
60  
61 51 return;
62 }
63  
64 1 ▶sub causes { return [@CAUSES] }
Subroutine causes: called CC=1 SCAR=0.0
Pod documented
65  
66 39 ▶sub died {
Subroutine died: called CC=2 SCAR=6.9
Pod documented
67 39 my ($self) = @_;
68 39 ▶ return $self->cause eq 'quit' ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->cause eq 'quit' ? : 25 14 39
69 }
70  
71 36 ▶sub stringify {
Subroutine stringify: called CC=2 SCAR=6.9
Pod documented
72 36 my ($self) = @_;
73 36 my $tail = sprintf '%s at %d points after %d ticks', $SENTENCE{ $self->cause },
74 $self->score, $self->ticks;
75 36 ▶ return $self->died ? "Game over: $tail" : ucfirst $tail;
Branch: 1 branch
BranchTrueFalseTotal
$self->died ? : 12 24 36
76 }
77  
78 15 1;
79  
80 __END__
« blib/lib/Game/Floppy.pm ↑ Summary blib/lib/Game/Floppy/Bot.pm »