| 1 | package Game::Reversi::Result; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 10 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 10 | our @RESULTS; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 10 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 10 | @RESULTS = qw/score draw timeout abandoned resign/; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | has winner => ( | ||||||||||||||||||||||||||||
| 17 | is => 'ro' | ||||||||||||||||||||||||||||
| 18 | 10 | ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | has result => ( | ||||||||||||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||||||||||
| 22 | isa => Str | ||||||||||||||||||||||||||||
| 23 | 10 | ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | has counts => ( | ||||||||||||||||||||||||||||
| 26 | is => 'ro', | ||||||||||||||||||||||||||||
| 27 | isa => HashRef | ||||||||||||||||||||||||||||
| 28 | 10 | ); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | has score => ( | ||||||||||||||||||||||||||||
| 31 | is => 'ro' | ||||||||||||||||||||||||||||
| 32 | 10 | ); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | has places => ( | ||||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||
| 36 | isa => HashRef | ||||||||||||||||||||||||||||
| 37 | 10 | ); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 376 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 376 | my ($self) = @_; | |||||||||||||||||||||||||||
| 41 | 376 | ▶ | my $result = $self->result // ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->result // ""
MC/DC0%0/1
$self->result // ""
$self->result
Truth table50%1/2
A
A= $self->result
| |||||||||||||||||||||||||||||
| 42 | die "Game::Reversi::Result: '$result' is not a result" | ||||||||||||||||||||||||||||
| 43 | 376 | ▶ | unless grep { $_ eq $result } @RESULTS; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 375 | ▶ | die 'Game::Reversi::Result: a draw has no winner' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$result eq "draw" and defined $self->winner
MC/DC100%2/2
$result eq "draw" and defined $self->winner
$result eq "draw"
defined $self->winner
Truth table100%3/3
A and B
A= $result eq "draw"B= defined $self->winner
| |||||||||||||||||||||||||||||
| 45 | if $result eq 'draw' && defined $self->winner; | ||||||||||||||||||||||||||||
| 46 | 374 | return $self; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub results { return [ @RESULTS ] } | ||||||||||||||||||||||||||
|
Subroutine
results: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 19 | ▶ | sub natural { | ||||||||||||||||||||||||||
|
Subroutine
natural: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 19 | my ($self) = @_; | |||||||||||||||||||||||||||
| 53 | 19 | ▶ | return ($self->result eq 'score' || $self->result eq 'draw') ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->result eq "score" or $self->result eq "draw"
MC/DC50%1/2
$self->result eq "score" or $self->result eq "draw"
$self->result eq "score"
$self->result eq "draw"
Truth table66%2/3
A or B
A= $self->result eq "score"B= $self->result eq "draw"
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub stringify { | ||||||||||||||||||||||||||
|
Subroutine
stringify: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 58 | 0 | my $score = $self->score; | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | my $line = defined $self->winner ? uc($self->winner) . ' wins' : 'a tie'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $line .= ', ' . $score->{b} . ' to ' . $score->{w} if $score; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | $line .= ' (' . $self->result . ')' unless $self->natural; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | return $line; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 10 | 1; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||||||||||