blib/lib/Game/RoyalUr/Result.pm

filter: Statementstmt 85.7% 12 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 89.4% 17 / 19 CC 1 SCAR 0.6
CC
1
Cov
86%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/lib/Game/RoyalUr/Error.pm ↑ Summary blib/lib/Game/RoyalUr.pm »
1 package Game::RoyalUr::Result;
2  
3 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 0 ▶use Object::Proto::Sugar;
Subroutine BEGIN: called CC=1 SCAR=2.6
9  
10 our $VERSION = '0.03';
11  
12 my %HOW;
13 BEGIN {
14 %HOW = (home => 1, resign => 1, ply_cap => 1);
15 }
16  
17 has winner => (is => 'ro');
18  
19 has how => (is => 'ro');
20  
21 has final => (is => 'ro');
22  
23 has home => (is => 'ro');
24  
25 has plies => (is => 'ro', default => 0);
26  
27 sub BUILD {
28 my ($self) = @_;
29 my ($winner, $how) = ($self->winner, $self->how);
30 Carp::croak("Game::RoyalUr::Result: how is one of " . join(', ', sort keys %HOW))
31 unless defined $how && $HOW{$how};
32 Carp::croak("Game::RoyalUr::Result: a winner is 'light' or 'dark'")
33 if defined $winner && $winner ne 'light' && $winner ne 'dark';
34 Carp::croak('Game::RoyalUr::Result: a game that ran to the ply cap has no winner')
35 if $how eq 'ply_cap' && defined $winner;
36 Carp::croak("Game::RoyalUr::Result: a game ended by $how has a winner")
37 if $how ne 'ply_cap' && !defined $winner;
38 return;
39 }
40  
41 sub is_draw { defined $_[0]->winner ? 0 : 1 }
42  
43 sub loser {
44 my ($self) = @_;
45 my $winner = $self->winner;
46 return undef unless defined $winner;
47 return $winner eq 'light' ? 'dark' : 'light';
48 }
49  
50 1;
51  
52 __END__
« blib/lib/Game/RoyalUr/Error.pm ↑ Summary blib/lib/Game/RoyalUr.pm »