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
« Dominoes/Hand.pm ↑ Summary Dominoes/Boneyard.pm »
1 package Game::Dominoes::Result;
2  
3 12 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
5  
6 12 ▶use Object::Proto::Sugar -types;
Subroutine __ANON__: called CC=1 SCAR=0.0
7  
8 12 our $VERSION = '0.03';
9  
10 12 our @REASONS;
11  
12 12 ▶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 12 );
19  
20 has scores => (
21 is => 'ro',
22 isa => HashRef,
23 default => {}
24 12 );
25  
26 has reason => (
27 is => 'ro',
28 isa => Str
29 12 );
30  
31 26 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.3
Pod undocumented
32 26 my ($self) = @_;
33 26 ▶ if (defined $self->reason) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->reason) 26 0 26
34 die 'Game::Dominoes::Result: unknown reason ' . $self->reason
35 26 ▶ unless grep { $_ eq $self->reason } @REASONS;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $self->reason;} @Game::Dominoes::Result::REASONS 0 26 26
36 }
37 26 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 13 ▶sub winners {
Subroutine winners: called CC=1 SCAR=0.0
Pod documented
45 13 my ($self) = @_;
46 13 my $places = $self->places;
47 13 return [ sort { $a <=> $b } grep { $places->{$_} == 1 } keys %$places ];
48 }
49  
50 6 ▶sub winner {
Subroutine winner: called CC=2 SCAR=6.9
Pod documented
51 6 my ($self) = @_;
52 6 my $winners = $self->winners;
53 6 ▶ return @$winners == 1 ? $winners->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@$winners == 1 ? : 5 1 6
54 }
55  
56 6 ▶sub is_draw {
Subroutine is_draw: called CC=2 SCAR=6.9
Pod documented
57 6 ▶ return @{ $_[0]->winners } > 1 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@{$_[0]->winners;} > 1 ? : 1 5 6
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 5 ▶sub ranking {
Subroutine ranking: called CC=2 SCAR=6.9
Pod documented
66 5 my ($self) = @_;
67 5 my $places = $self->places;
68 5 my %by;
69 5 push @{ $by{ $places->{$_} } }, $_ for keys %$places;
70 5 return [ map { [ sort { $a <=> $b } @{ $by{$_} } ] } sort { $a <=> $b } keys %by ];
71 }
72  
73 4 ▶sub stringify {
Subroutine stringify: called CC=4 SCAR=14.2
Pod documented
74 4 my ($self) = @_;
75 4 my $scores = $self->scores;
76 my $order = join ', ', map {
77 10 ▶ join(' and ', map { "seat $_" } @$_) . ' (' . ($scores->{ $_->[0] } // 0) . ')'
Condition50%1/2
$$scores{$_->[0]} // 0
l!l
100
MC/DC0%0/1
$$scores{$_->[0]} // 0
$$scores{$_->[0]}
Truth table50%1/2
A
A= $$scores{$_->[0]}
Aresult
11
00
78 4 } @{ $self->ranking };
79 4 ▶ my $head = $self->is_draw ? 'Drawn' : 'Seat ' . $self->winner . ' wins';
Branch: 1 branch
BranchTrueFalseTotal
$self->is_draw ? : 0 4 4
80 4 ▶ return $head . ' by ' . ($self->reason // 'unknown') . ': ' . $order;
Condition50%1/2
$self->reason // "unknown"
l!l
40
MC/DC0%0/1
$self->reason // "unknown"
$self->reason
Truth table50%1/2
A
A= $self->reason
Aresult
11
00
81 }
82  
83 12 1;
84  
85 __END__
« Dominoes/Hand.pm ↑ Summary Dominoes/Boneyard.pm »