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 1 1 100.0
total 30 30 100.0


line stmt bran cond sub pod time code
1             package Game::Cribbage::Play::Score;
2              
3 10     10   54 use strict;
  10         14  
  10         333  
4 10     10   35 use warnings;
  10         12  
  10         478  
5              
6 10     10   38 use Object::Proto::Sugar -types;
  10         14  
  10         57  
7              
8             has scores => (
9             is => 'ro',
10             isa => HashRef,
11             builder => sub {
12             {
13 75     75   453 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 1 4489 my ($self) = @_;
35 111         122 my $score = 0;
36 111         143 for (qw/fifteen go pegged flipped/) {
37 444 100       773 if ( $self->$_ ) {
38 24         57 $score += $self->scores->{$_};
39             }
40             }
41 111         128 for (qw/pair run/) {
42 222 100       412 if ($self->$_) {
43 17         47 $score += $self->scores->{$_}->[$self->$_ - 1];
44             }
45             }
46 111         180 $self->total_score($score);
47 111         258 return $score;
48             }
49              
50             1;
51              
52             __END__