| 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
| |||||||||||||
| 34 | die 'Game::Dominoes::Result: unknown reason ' . $self->reason | ||||||||||||
| 35 | 26 | ▶ | unless grep { $_ eq $self->reason } @REASONS; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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
MC/DC0%0/1
$$scores{$_->[0]} // 0
$$scores{$_->[0]}
Truth table50%1/2
A
A= $$scores{$_->[0]}
| |||||||||||||
| 78 | 4 | } @{ $self->ranking }; | |||||||||||
| 79 | 4 | ▶ | my $head = $self->is_draw ? 'Drawn' : 'Seat ' . $self->winner . ' wins'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | 4 | ▶ | return $head . ' by ' . ($self->reason // 'unknown') . ': ' . $order; | ||||||||||
|
Condition50%1/2
$self->reason // "unknown"
MC/DC0%0/1
$self->reason // "unknown"
$self->reason
Truth table50%1/2
A
A= $self->reason
| |||||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | 12 | 1; | |||||||||||
| 84 | |||||||||||||
| 85 | __END__ | ||||||||||||