Scorecard.pm

filter: Statementstmt 100% 56 / 56 Branchbran 100% 12 / 12 Conditioncond 100% 12 / 12 MC/DCmcdc 100% 8 / 8 Subroutinesub 100% 12 / 12 Podpod 100% 8 / 8 totaltotal 100% 108 / 108 SCAR 27.1
CC
15
Cov
100%
score_through
6.0
current_frame
4.0
record
4.0
CRAP 15.0
« Scorecard/Frame.pm ↑ Summary Scorecard/Frame/TenPinTenth.pm »
1 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Games::Bowling::Scorecard;
4 {
5 3 $Games::Bowling::Scorecard::VERSION = '0.105';
6 }
7 # ABSTRACT: score your bowling game easily
8  
9  
10 3 ▶use Games::Bowling::Scorecard::Frame;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 sub new {
14 8 ▶ my ($class) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
15  
16 8 my $self = bless { frames => [ ] } => $class;
17  
18 8 return $self;
19 }
20  
21  
22 sub frames {
23 687 ▶ my ($self) = @_;
Subroutine frames: called CC=1 SCAR=0.0
Pod documented
24  
25 687 return @{ $self->{frames} };
26 }
27  
28  
29 sub current_frame {
30 139 ▶ my ($self) = @_;
Subroutine current_frame: called CC=4 SCAR=13.9
Pod documented
31  
32 139 ▶ return if $self->is_done;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_done 1 138 139
33  
34 138 my @frames = $self->frames;
35  
36 138 my $frame = pop @frames;
37  
38 138 ▶ return $self->_next_frame if !$frame || $frame->is_done;
Branch: 1 branch
BranchTrueFalseTotal
if not $frame or $frame->is_done 74 64 138
Condition100%3/3
not $frame or $frame->is_done
l!l&&r!l&&!r
86664
MC/DC100%2/2
not $frame or $frame->is_done
not $frame $frame->is_done
Truth table100%3/3
not(A) or B
A= not $frameB= $frame->is_done
ABresult
1X1
011
000
39  
40 64 return $frame;
41 }
42  
43 sub _next_frame {
44 74 ▶ my ($self) = @_;
Subroutine _next_frame: called CC=2 SCAR=6.9
45  
46 my $frame = $self->frames == 9
47 74 ▶ ? do {
Branch: 1 branch
BranchTrueFalseTotal
$self->frames == 9 ? : 7 67 74
48 7 require Games::Bowling::Scorecard::Frame::TenPinTenth;
49 7 Games::Bowling::Scorecard::Frame::TenPinTenth->new;
50 }
51 : Games::Bowling::Scorecard::Frame->new;
52  
53 74 push @{ $self->{frames} }, $frame;
54  
55 74 return $frame;
56 }
57  
58  
59 sub pending_frames {
60 136 ▶ my ($self) = @_;
Subroutine pending_frames: called CC=1 SCAR=0.0
Pod documented
61  
62 136 my @pending_frames = grep { $_->is_pending } $self->frames;
63 }
64  
65  
66 sub record { ## no critic Ambiguous
67 81 ▶ my ($self, @balls) = @_;
Subroutine record: called CC=4 SCAR=13.9
Pod documented
68  
69 81 for my $ball (@balls) {
70 140 ▶ Carp::croak "can't record more balls on a completed scorecard"
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_done 4 136 140
71 if $self->is_done;
72  
73 136 for my $pending ($self->pending_frames) {
74 38 $pending->record($ball);
75 }
76  
77 136 $self->current_frame->record($ball);
78 }
79 }
80  
81  
82 sub score {
83 6 ▶ my ($self) = @_;
Subroutine score: called CC=2 SCAR=6.9
Pod documented
84  
85 6 my $score = 0;
86 6 $score += $_->score for $self->frames;
87  
88 6 return $score;
89 }
90  
91  
92 sub score_through {
93 44 ▶ my ($card, $n) = @_;
Subroutine score_through: called CC=6 SCAR=17.9
Pod documented
94  
95 44 ▶ Carp::croak "frame out of range" unless $n >= 1 and $n <= 10;
Branch: 1 branch
BranchTrueFalseTotal
unless $n >= 1 and $n <= 10 2 42 44
Condition100%3/3
$n >= 1 and $n <= 10
!ll&&!rl&&r
1142
MC/DC100%2/2
$n >= 1 and $n <= 10
$n >= 1 $n <= 10
Truth table100%3/3
A and B
A= $n >= 1B= $n <= 10
ABresult
0X0
100
111
96  
97 42 my @frames = $card->frames;
98 42 my $score = 0;
99  
100 42 INDEX: for my $idx (0 .. $n - 1) {
101 210 my $frame = $frames[ $idx ];
102 210 ▶ return undef if $frame->is_pending or not $frame->is_done;
Branch: 1 branch
BranchTrueFalseTotal
if $frame->is_pending or not $frame->is_done 3 207 210
Condition100%3/3
$frame->is_pending or not $frame->is_done
l!l&&r!l&&!r
21207
MC/DC100%2/2
$frame->is_pending or not $frame->is_done
$frame->is_pending not $frame->is_done
Truth table100%3/3
A or not(B)
A= $frame->is_pendingB= not $frame->is_done
ABresult
1X1
011
000
103  
104 207 $score += $frame->score;
105 }
106  
107 39 return $score;
108 }
109  
110  
111 sub is_done {
112 285 ▶ my ($self) = @_;
Subroutine is_done: called CC=2 SCAR=6.9
Pod documented
113  
114 285 my @frames = $self->frames;
115  
116 285 ▶ return (@frames == 10 and $frames[9]->is_done);
Condition100%3/3
@frames == 10 && $frames[9]->is_done
!ll&&!rl&&r
252249
MC/DC100%2/2
@frames == 10 && $frames[9]->is_done
@frames == 10 $frames[9]->is_done
Truth table100%3/3
A && B
A= @frames == 10B= $frames[9]->is_done
ABresult
0X0
100
111
117 }
118  
119  
120 3 300;
121  
122 __END__
« Scorecard/Frame.pm ↑ Summary Scorecard/Frame/TenPinTenth.pm »