File Coverage

blib/lib/Game/Cribbage/Play/Score.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Game::Cribbage::Play::Score;
2              
3 5     5   36 use strict;
  5         11  
  5         207  
4 5     5   26 use warnings;
  5         21  
  5         277  
5              
6 5     5   43 use Rope;
  5         28  
  5         42  
7 5     5   1770 use Rope::Autoload;
  5         11  
  5         48  
8              
9             property scores => (
10             initable => 1,
11             writeable => 0,
12             configurable => 0,
13             enumerable => 1,
14             value => {
15             run => [3, 4, 5, 6, 7],
16             pair => [2, 6, 12],
17             fifteen => 2,
18             go => 1,
19             pegged => 1,
20             flipped => 1
21             }
22             );
23              
24             property [qw/total_score pair run fifteen pegged go flipped/] => (
25             initable => 1,
26             writeable => 1,
27             configurable => 0,
28             enumerable => 1
29             );
30              
31             property [qw/player card/] => (
32             initable => 1,
33             writeable => 0,
34             configurable => 0,
35             enumerable => 1
36             );
37              
38             function score => sub {
39             my ($self) = @_;
40             my $score = 0;
41             for (qw/fifteen go pegged flipped/) {
42             if ( $self->$_ ) {
43             $score += $self->scores->{$_};
44             }
45             }
46             for (qw/pair run/) {
47             if ($self->$_) {
48             $score += $self->scores->{$_}->[$self->$_ - 1];
49             }
50             }
51             $self->total_score = $score;
52             return $score;
53             };
54              
55             1;