Dominoes/Boneyard.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Dominoes/Scoring.pm ↑ Summary Dominoes/Error.pm »
1 package Game::Dominoes::Boneyard;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 0 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=2.6
7  
8 our $VERSION = '0.04';
9  
10 has tiles => (
11 is => 'rw',
12 isa => ArrayRef,
13 default => []
14 );
15  
16 has reserve => (
17 is => 'rw',
18 isa => Int,
19 default => 0
20 );
21  
22 sub BUILD {
23 my ($self) = @_;
24 die 'Game::Dominoes::Boneyard: reserve must not be negative'
25 if $self->reserve < 0;
26 return $self;
27 }
28  
29 sub count {
30 return scalar @{ $_[0]->tiles };
31 }
32  
33 sub drawable {
34 my ($self) = @_;
35 my $n = $self->count - $self->reserve;
36 return $n > 0 ? $n : 0;
37 }
38  
39 sub is_empty {
40 return $_[0]->count ? 0 : 1;
41 }
42  
43 sub can_draw {
44 return $_[0]->drawable ? 1 : 0;
45 }
46  
47 sub draw {
48 my ($self) = @_;
49 return undef unless $self->can_draw;
50 return shift @{ $self->tiles };
51 }
52  
53 sub peek {
54 return [ @{ $_[0]->tiles } ];
55 }
56  
57 sub pips {
58 my ($self) = @_;
59 my $total = 0;
60 $total += $_->pips for @{ $self->tiles };
61 return $total;
62 }
63  
64 1;
65  
66 __END__
« Dominoes/Scoring.pm ↑ Summary Dominoes/Error.pm »