Dominoes/Hand.pm

filter: Statementstmt 80.0% 44 / 55 Branchbran 80.0% 8 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 84.6% 11 / 13 Podpod 100% 10 / 10 totaltotal 78.4% 73 / 93 CC 9 SCAR 9.5
CC
9
Cov
76%
matching
6.0
remove
4.1
holds
3.0
CRAP 2.6
« Dominoes/Play.pm ↑ Summary Dominoes/Result.pm »
1 package Game::Dominoes::Hand;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 12 our $VERSION = '0.03';
9  
10 has tiles => (
11 is => 'rw',
12 isa => ArrayRef,
13 default => []
14 12 );
15  
16 229706 ▶sub count {
Subroutine count: called CC=1 SCAR=0.0
Pod documented
17 229706 return scalar @{ $_[0]->tiles };
18 }
19  
20 226836 ▶sub is_empty {
Subroutine is_empty: called CC=2 SCAR=6.9
Pod documented
21 226836 ▶ return $_[0]->count ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->count ? : 223631 3205 226836
22 }
23  
24 29458 ▶sub pips {
Subroutine pips: called CC=2 SCAR=6.9
Pod documented
25 29458 my ($self) = @_;
26 29458 my $total = 0;
27 29458 $total += $_->pips for @{ $self->tiles };
28 29458 return $total;
29 }
30  
31 29739 ▶sub add {
Subroutine add: called CC=1 SCAR=0.0
Pod documented
32 29739 my ($self, @tiles) = @_;
33 29739 push @{ $self->tiles }, grep { defined } @tiles;
34 29739 return $self;
35 }
36  
37 20248 ▶sub holds {
Subroutine holds: called CC=3 SCAR=11.0
Pod documented
38 20248 my ($self, $tile) = @_;
39 20248 ▶ return 0 unless ref $tile;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tile 0 20248 20248
40 20248 ▶ return (grep { $_->id == $tile->id } @{ $self->tiles }) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({$_->id == $tile->id;} @{$self->tiles;}) ? : 20243 5 20248
41 }
42  
43 226855 ▶sub remove {
Subroutine remove: called CC=4 SCAR=14.1
Pod documented
44 226855 my ($self, $tile) = @_;
45 226855 ▶ return undef unless ref $tile;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tile 0 226855 226855
46 226855 my $tiles = $self->tiles;
47 226855 for my $i (0 .. $#$tiles) {
48 783991 ▶ next unless $tiles->[$i]->id == $tile->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $tiles->[$i]->id == $tile->id 557136 226855 783991
49 226855 return splice @$tiles, $i, 1;
50 }
51 0 return undef;
52 }
53  
54 0 ▶sub matching {
Subroutine matching: not called CC=2 SCAR=17.9
Pod documented
55 0 my ($self, @faces) = @_;
56 0 my %want = map { $_ => 1 } grep { defined } @faces;
57 0 ▶ return [ grep { $want{ $_->high } || $want{ $_->low } } @{ $self->tiles } ];
Condition0%0/3
$want{$_->high} || $want{$_->low}
l!l&&r!l&&!r
000
MC/DC0%0/2
$want{$_->high} || $want{$_->low}
$want{$_->high} $want{$_->low}
Truth table0%0/3
A || B
A= $want{$_->high}B= $want{$_->low}
ABresult
1X1
011
000
58 }
59  
60 255645 ▶sub sorted {
Subroutine sorted: called CC=1 SCAR=0.0
Pod documented
61 255645 my ($self) = @_;
62 255645 return [ sort { $a->id <=> $b->id } @{ $self->tiles } ];
63 }
64  
65 0 ▶sub clone {
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
66 0 my ($self) = @_;
67 0 return ref($self)->new(tiles => [ @{ $self->tiles } ]);
68 }
69  
70 11 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
Pod documented
71 11 my ($self) = @_;
72 11 return join ' ', map { $_->stringify } @{ $self->sorted };
73 }
74  
75 12 1;
76  
77 __END__
« Dominoes/Play.pm ↑ Summary Dominoes/Result.pm »