| 1 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | package Games::Bowling::Scorecard::AsText; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | { | ||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | $Games::Bowling::Scorecard::AsText::VERSION = '0.105'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | } | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # ABSTRACT: format a bowling scorecard as text | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | sub card_as_text { | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | my ($self, $card) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
card_as_text: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | my $hdr = '+-----+-----+-----+-----+-----+-----+-----+-----+-----+-------+'; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | my $balls = ''; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | my $scores = ''; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | my @frames = $card->frames; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 4 | INDEX: for my $i (0 .. 8) { | |||||||||||||||||||||||||||||||||||||||||
| 21 | 36 | my $frame = $frames[ $i ]; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 36 | ▶ | unless ($frame) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | $_ .= '| ' for $balls, $scores; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | next INDEX; | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 31 | $balls .= sprintf '| %s ', $self->_two_balls($frame->balls); | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 31 | my $score = $card->score_through($i + 1); | |||||||||||||||||||||||||||||||||||||||||
| 30 | 31 | ▶ | $scores .= defined $score | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | ? sprintf '| %3u ', $score | ||||||||||||||||||||||||||||||||||||||||||
| 32 | : '| '; | ||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | TENTH: for (1) { | |||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | my $frame = $frames[ 9 ]; | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | ▶ | unless ($frame) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | $_ .= '| |' for $balls, $scores; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | last TENTH; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | $balls .= sprintf '| %s |', $self->_three_balls($frame->balls); | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | my $score = $card->score_through(10); | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | $scores .= defined $score | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | ? sprintf '| %3u |', $score | ||||||||||||||||||||||||||||||||||||||||||
| 49 | : '| |'; | ||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | return "$hdr\n" | |||||||||||||||||||||||||||||||||||||||||
| 53 | . "$balls\n" | ||||||||||||||||||||||||||||||||||||||||||
| 54 | . "$scores\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | sub _two_balls { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 54 | ▶ | my ($self, $b1, $b2) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_two_balls: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 54 | ▶ | return ' ' unless defined $b1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 53 | ▶ | sprintf '%s %s', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition100%4/4
$b1 or "-"
$b2 or "-"
MC/DC100%1/1
$b1 or "-"
$b1
MC/DC100%1/1
$b2 or "-"
$b2
Truth table100%2/2
A
A= $b1
Truth table100%2/2
A
A= $b2
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | $b1 == 10 ? 'X' : $b1 || '-', | ||||||||||||||||||||||||||||||||||||||||||
| 64 | $b1 == 10 ? ' ' : defined $b2 ? $b1 + $b2 == 10 ? '/' : $b2 || '-' : ' '; | ||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | sub _three_balls { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 22 | ▶ | my ($self, $b1, $b2, $b3) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_three_balls: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 22 | ▶ | return ' ' unless defined $b1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 21 | ▶ | if ($b1 == 10) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 12 | ▶ | return 'X ' unless defined $b2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 10 | ▶ | return sprintf 'X X %s', defined $b3 ? $b3 == 10 ? 'X' : $b3 || '-' : ' ' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%2/2
$b3 or "-"
MC/DC100%1/1
$b3 or "-"
$b3
Truth table100%2/2
A
A= $b3
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | if $b2 == 10; | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 6 | return sprintf 'X %s', $self->_two_balls($b2, $b3); | |||||||||||||||||||||||||||||||||||||||||
| 79 | } elsif (not defined $b2) { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | ▶ | return sprintf '%s ', $b1 || '-'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$b1 || '-'
MC/DC100%1/1
$b1 || '-'
$b1
Truth table100%2/2
A
A= $b1
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | } elsif ($b1 + $b2 == 10) { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 4 | ▶ | return sprintf '%s %s', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%2/2
$b3 or "-"
MC/DC100%1/1
$b3 or "-"
$b3
Truth table100%2/2
A
A= $b3
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | $self->_two_balls($b1, $b2), | ||||||||||||||||||||||||||||||||||||||||||
| 84 | defined $b3 ? $b3 == 10 ? 'X' : $b3 || '-' : ' '; | ||||||||||||||||||||||||||||||||||||||||||
| 85 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | return sprintf '%s ', $self->_two_balls($b1, $b2); | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | 300; | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||||||||||||||||