| 1 | package Game::Cribbage::Play::Score; | ||||||||||
| 2 | |||||||||||
| 3 | 13 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 13 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 13 | ▶ | use Object::Proto::Sugar -types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | has scores => ( | ||||||||||
| 9 | is => 'ro', | ||||||||||
| 10 | isa => HashRef, | ||||||||||
| 11 | 159 | ▶ | builder => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 12 | { | ||||||||||
| 13 | 159 | run => [3, 4, 5, 6, 7], | |||||||||
| 14 | pair => [2, 6, 12], | ||||||||||
| 15 | fifteen => 2, | ||||||||||
| 16 | go => 1, | ||||||||||
| 17 | pegged => 1, | ||||||||||
| 18 | flipped => 2 | ||||||||||
| 19 | } | ||||||||||
| 20 | } | ||||||||||
| 21 | 13 | ); | |||||||||
| 22 | |||||||||||
| 23 | has [qw/total_score pair run fifteen pegged go flipped/] => ( | ||||||||||
| 24 | is => 'rw', | ||||||||||
| 25 | isa => Int | ||||||||||
| 26 | 13 | ); | |||||||||
| 27 | |||||||||||
| 28 | has [qw/player card/] => ( | ||||||||||
| 29 | is => 'ro', | ||||||||||
| 30 | isa => Object | ||||||||||
| 31 | 13 | ); | |||||||||
| 32 | |||||||||||
| 33 | 204 | ▶ | sub score { | ||||||||
|
Subroutine
score: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 34 | 204 | my ($self) = @_; | |||||||||
| 35 | 204 | my $score = 0; | |||||||||
| 36 | 204 | for (qw/fifteen go pegged flipped/) { | |||||||||
| 37 | 816 | ▶ | if ( $self->$_ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 58 | $score += $self->scores->{$_}; | |||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | 204 | for (qw/pair run/) { | |||||||||
| 42 | 408 | ▶ | if ($self->$_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 38 | $score += $self->scores->{$_}->[$self->$_ - 1]; | |||||||||
| 44 | } | ||||||||||
| 45 | } | ||||||||||
| 46 | 204 | $self->total_score($score); | |||||||||
| 47 | 204 | return $score; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 13 | 1; | |||||||||
| 51 | |||||||||||
| 52 | __END__ | ||||||||||