File Coverage

blib/lib/Game/Cribbage/Play/Score.pm
Criterion Covered Total %
statement 20 20 100.0
branch 4 4 100.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 29 30 96.6


line stmt bran cond sub pod time code
1             package Game::Cribbage::Play::Score;
2              
3 10     10   51 use strict;
  10         15  
  10         374  
4 10     10   36 use warnings;
  10         16  
  10         456  
5              
6 10     10   58 use Object::Proto::Sugar -types;
  10         11  
  10         57  
7              
8             has scores => (
9             is => 'ro',
10             isa => HashRef,
11             builder => sub {
12             {
13 75     75   412 run => [3, 4, 5, 6, 7],
14             pair => [2, 6, 12],
15             fifteen => 2,
16             go => 1,
17             pegged => 1,
18             flipped => 1
19             }
20             }
21             );
22              
23             has [qw/total_score pair run fifteen pegged go flipped/] => (
24             is => 'rw',
25             isa => Int
26             );
27              
28             has [qw/player card/] => (
29             is => 'ro',
30             isa => Object
31             );
32              
33             sub score {
34 111     111 0 4638 my ($self) = @_;
35 111         120 my $score = 0;
36 111         138 for (qw/fifteen go pegged flipped/) {
37 444 100       792 if ( $self->$_ ) {
38 24         48 $score += $self->scores->{$_};
39             }
40             }
41 111         125 for (qw/pair run/) {
42 222 100       403 if ($self->$_) {
43 17         45 $score += $self->scores->{$_}->[$self->$_ - 1];
44             }
45             }
46 111         190 $self->total_score($score);
47 111         243 return $score;
48             }
49              
50             1;