Scorecard/Frame.pm

filter: Statementstmt 100% 53 / 53 Branchbran 100% 24 / 24 Conditioncond 91.6% 11 / 12 MC/DCmcdc 85.7% 6 / 7 Subroutinesub 100% 12 / 12 Podpod 100% 7 / 7 totaltotal 98.2% 113 / 115 SCAR 28.9
CC
18
Cov
99%
roll_ok
8.0
_check_pending
6.0
_check_done
4.0
CRAP 18.0
« Scorecard/AsText.pm ↑ Summary Scorecard.pm »
1 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Games::Bowling::Scorecard::Frame;
5 {
6 7 $Games::Bowling::Scorecard::Frame::VERSION = '0.105';
7 }
8 # ABSTRACT: one frame on a scorecard
9  
10  
11 7 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 sub new {
15 81 ▶ my ($class) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
16  
17 81 bless {
18 balls => [],
19 score => 0,
20  
21 done => 0,
22 pending => 0,
23 } => $class;
24 }
25  
26  
27 sub record { ## no critic Ambiguous
28 194 ▶ my ($self, $ball) = @_;
Subroutine record: called CC=3 SCAR=11.0
Pod documented
29  
30 194 ▶ if ($self->is_done) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_done) 42 152 194
31 42 ▶ if ($self->is_pending) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_pending) { } 41 1 42
32 41 $self->{pending}--;
33 41 $self->{score} += $ball;
34 41 return;
35 } else {
36 1 Carp::croak "two balls already recorded for frame";
37 }
38 }
39  
40 152 $self->roll_ok($ball);
41  
42 152 push @{ $self->{balls} }, $ball;
43 152 $self->{score} += $ball;
44  
45 152 $self->_check_done;
46 152 $self->_check_pending;
47 }
48  
49 sub _check_pending {
50 152 ▶ my ($self) = @_;
Subroutine _check_pending: called CC=6 SCAR=17.9
51 152 ▶ return unless $self->is_done;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_done 73 79 152
52  
53 79 my @balls = $self->balls;
54  
55 79 ▶ return $self->{pending} = 2 if @balls == 1 and $balls[0] == 10;
Branch: 1 branch
BranchTrueFalseTotal
if @balls == 1 and $balls[0] == 10 15 64 79
Condition66%2/3
@balls == 1 and $balls[0] == 10
!ll&&!rl&&r
64015
MC/DC50%1/2
@balls == 1 and $balls[0] == 10
@balls == 1 $balls[0] == 10
Truth table66%2/3
A and B
A= @balls == 1B= $balls[0] == 10
ABresult
0X0
100
111
56 64 ▶ return $self->{pending} = 1 if @balls == 2 and $balls[0] + $balls[1] == 10;
Branch: 1 branch
BranchTrueFalseTotal
if @balls == 2 and $balls[0] + $balls[1] == 10 12 52 64
Condition100%3/3
@balls == 2 and $balls[0] + $balls[1] == 10
!ll&&!rl&&r
74512
MC/DC100%2/2
@balls == 2 and $balls[0] + $balls[1] == 10
@balls == 2 $balls[0] + $balls[1] == 10
Truth table100%3/3
A and B
A= @balls == 2B= $balls[0] + $balls[1] == 10
ABresult
0X0
100
111
57 }
58  
59 sub _check_done {
60 152 ▶ my ($self) = @_;
Subroutine _check_done: called CC=4 SCAR=13.9
61  
62 152 my @balls = $self->balls;
63  
64 152 ▶ $self->{done} = 1 if (@balls == 1 and $balls[0] == 10) or @balls == 2;
Branch: 1 branch
BranchTrueFalseTotal
if @balls == 1 and $balls[0] == 10 or @balls == 2 84 68 152
Condition100%6/6
@balls == 1 and $balls[0] == 10 or @balls == 2
l!l&&r!l&&!r
206468
@balls == 1 and $balls[0] == 10
!ll&&!rl&&r
716120
MC/DC100%3/3
@balls == 1 and $balls[0] == 10 or @balls == 2
@balls == 1 $balls[0] == 10 @balls == 2
Truth table80%4/5
A and B or C
A= @balls == 1B= $balls[0] == 10C= @balls == 2
ABCresult
11X1
0X11
1011
0X00
1000
65 }
66  
67  
68 sub roll_ok {
69 164 ▶ my ($self, $ball) = @_;
Subroutine roll_ok: called CC=8 SCAR=20.8
Pod documented
70  
71 164 ▶ Carp::croak "the frame is done" if $self->is_done;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_done 1 163 164
72 163 ▶ Carp::croak "you can't bowl an undefined number of pins!" if !defined $ball;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ball 1 162 163
73 162 ▶ Carp::croak "you can't bowl more than 10 on a single ball" if $ball > 10;
Branch: 1 branch
BranchTrueFalseTotal
if $ball > 10 2 160 162
74 160 ▶ Carp::croak "you can't bowl less than 0 on a single ball" if $ball < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $ball < 0 1 159 160
75 159 ▶ Carp::croak "you can't knock down a partial pin" if $ball != int($ball);
Branch: 1 branch
BranchTrueFalseTotal
if $ball != int $ball 1 158 159
76  
77 158 my $i = 0;
78 158 $i += $_ for $self->balls, $ball;
79  
80 158 ▶ Carp::croak "bowling a $ball would bring the frame above 10" if $i > 10;
Branch: 1 branch
BranchTrueFalseTotal
if $i > 10 12 146 158
81 }
82  
83  
84 sub score {
85 297 ▶ my ($self) = @_;
Subroutine score: called CC=1 SCAR=0.0
Pod documented
86 297 return $self->{score};
87 }
88  
89  
90 sub is_pending {
91 925 ▶ my ($self) = @_;
Subroutine is_pending: called CC=1 SCAR=0.0
Pod documented
92 925 return $self->{pending};
93 }
94  
95  
96 sub is_done {
97 760 ▶ my ($self) = @_;
Subroutine is_done: called CC=1 SCAR=0.0
Pod documented
98 760 return $self->{done};
99 }
100  
101  
102 sub balls {
103 574 ▶ my ($self) = @_;
Subroutine balls: called CC=1 SCAR=0.0
Pod documented
104 574 return @{ $self->{balls} };
105 }
106  
107 7 300;
108  
109 __END__
« Scorecard/AsText.pm ↑ Summary Scorecard.pm »