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