blib/lib/Game/Dominoes/Result.pm

filter: Statementstmt 90.7% 49 / 54 Branchbran 70.0% 7 / 10 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 10 / 12 Podpod 87.5% 7 / 8 totaltotal 83.3% 75 / 90 CC 9 SCAR 8.5
CC
9
Cov
85%
stringify
4.2
BUILD
3.1
reasons
2.0
CRAP 2.3
« blib/lib/Game/Dominoes/Hand.pm ↑ Summary blib/lib/Game/Dominoes/Boneyard.pm »
1 package Game::Dominoes::Result;
2  
3 38 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 38 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
5  
6 38 ▶use Object::Proto::Sugar -types;
Subroutine __ANON__: called CC=1 SCAR=0.0
7  
8 38 our $VERSION = '0.05';
9  
10 38 our @REASONS;
11  
12 38 ▶BEGIN { @REASONS = qw/target blocked resign timeout/ }
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 has places => (
15 is => 'ro',
16 isa => HashRef,
17 default => {}
18 38 );
19  
20 has scores => (
21 is => 'ro',
22 isa => HashRef,
23 default => {}
24 38 );
25  
26 has reason => (
27 is => 'ro',
28 isa => Str
29 38 );
30  
31 38 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.3
Pod undocumented
32 38 my ($self) = @_;
33 38 ▶ if (defined $self->reason) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->reason) 38 0 38
34 die 'Game::Dominoes::Result: unknown reason ' . $self->reason
35 38 ▶ unless grep { $_ eq $self->reason } @REASONS;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $self->reason;} @Game::Dominoes::Result::REASONS 0 38 38
36 }
37 38 return $self;
38 }
39  
40 0 ▶sub reasons {
Subroutine reasons: not called CC=1 SCAR=6.9
Pod documented
41 0 return [@REASONS];
42 }
43  
44 15 ▶sub winners {
Subroutine winners: called CC=1 SCAR=0.0
Pod documented
45 15 my ($self) = @_;
46 15 my $places = $self->places;
47 15 return [ sort { $a <=> $b } grep { $places->{$_} == 1 } keys %$places ];
48 }
49  
50 7 ▶sub winner {
Subroutine winner: called CC=2 SCAR=6.9
Pod documented
51 7 my ($self) = @_;
52 7 my $winners = $self->winners;
53 7 ▶ return @$winners == 1 ? $winners->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@$winners == 1 ? : 6 1 7
54 }
55  
56 7 ▶sub is_draw {
Subroutine is_draw: called CC=2 SCAR=6.9
Pod documented
57 7 ▶ return @{ $_[0]->winners } > 1 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@{$_[0]->winners;} > 1 ? : 1 6 7
58 }
59  
60 0 ▶sub seats {
Subroutine seats: not called CC=1 SCAR=6.9
Pod documented
61 0 my ($self) = @_;
62 0 return [ sort { $a <=> $b } keys %{ $self->places } ];
63 }
64  
65 6 ▶sub ranking {
Subroutine ranking: called CC=2 SCAR=6.9
Pod documented
66 6 my ($self) = @_;
67 6 my $places = $self->places;
68 6 my %by;
69 6 push @{ $by{ $places->{$_} } }, $_ for keys %$places;
70 6 return [ map { [ sort { $a <=> $b } @{ $by{$_} } ] } sort { $a <=> $b } keys %by ];
71 }
72  
73 5 ▶sub stringify {
Subroutine stringify: called CC=4 SCAR=14.2
Pod documented
74 5 my ($self) = @_;
75 5 my $scores = $self->scores;
76 my $order = join ', ', map {
77 12 ▶ join(' and ', map { "seat $_" } @$_) . ' (' . ($scores->{ $_->[0] } // 0) . ')'
Condition50%1/2
$$scores{$_->[0]} // 0
l!l
120
MC/DC0%0/1
$$scores{$_->[0]} // 0
$$scores{$_->[0]}
Truth table50%1/2
A
A= $$scores{$_->[0]}
Aresult
11
00
78 5 } @{ $self->ranking };
79 5 ▶ my $head = $self->is_draw ? 'Drawn' : 'Seat ' . $self->winner . ' wins';
Branch: 1 branch
BranchTrueFalseTotal
$self->is_draw ? : 0 5 5
80 5 ▶ return $head . ' by ' . ($self->reason // 'unknown') . ': ' . $order;
Condition50%1/2
$self->reason // "unknown"
l!l
50
MC/DC0%0/1
$self->reason // "unknown"
$self->reason
Truth table50%1/2
A
A= $self->reason
Aresult
11
00
81 }
82  
83 38 1;
84  
85 __END__
« blib/lib/Game/Dominoes/Hand.pm ↑ Summary blib/lib/Game/Dominoes/Boneyard.pm »