| 1 | package Game::Fanorona::Error; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 25 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 25 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 25 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | 25 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 25 | ▶ | use Object::Proto::Sugar; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||
| 10 | 25 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||
| 12 | 25 | our @CODES; | |||||||||||||||||||||||||||||||||||||
| 13 | 25 | our %MESSAGE; | |||||||||||||||||||||||||||||||||||||
| 14 | 25 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 25 | @CODES = qw( | |||||||||||||||||||||||||||||||||||||
| 16 | game_over | ||||||||||||||||||||||||||||||||||||||
| 17 | not_a_side | ||||||||||||||||||||||||||||||||||||||
| 18 | offer_standing | ||||||||||||||||||||||||||||||||||||||
| 19 | no_offer | ||||||||||||||||||||||||||||||||||||||
| 20 | own_offer | ||||||||||||||||||||||||||||||||||||||
| 21 | chain_open | ||||||||||||||||||||||||||||||||||||||
| 22 | nothing_to_stop | ||||||||||||||||||||||||||||||||||||||
| 23 | bad_move | ||||||||||||||||||||||||||||||||||||||
| 24 | off_board | ||||||||||||||||||||||||||||||||||||||
| 25 | no_stone | ||||||||||||||||||||||||||||||||||||||
| 26 | not_your_stone | ||||||||||||||||||||||||||||||||||||||
| 27 | not_the_stone | ||||||||||||||||||||||||||||||||||||||
| 28 | not_adjacent | ||||||||||||||||||||||||||||||||||||||
| 29 | no_line | ||||||||||||||||||||||||||||||||||||||
| 30 | point_taken | ||||||||||||||||||||||||||||||||||||||
| 31 | same_direction | ||||||||||||||||||||||||||||||||||||||
| 32 | point_revisited | ||||||||||||||||||||||||||||||||||||||
| 33 | paika_in_chain | ||||||||||||||||||||||||||||||||||||||
| 34 | takes_nothing | ||||||||||||||||||||||||||||||||||||||
| 35 | choose_capture | ||||||||||||||||||||||||||||||||||||||
| 36 | must_capture | ||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||
| 38 | 25 | %MESSAGE = ( | |||||||||||||||||||||||||||||||||||||
| 39 | game_over => 'the game is already over', | ||||||||||||||||||||||||||||||||||||||
| 40 | not_a_side => 'that is not one of the two sides', | ||||||||||||||||||||||||||||||||||||||
| 41 | offer_standing => 'a draw has already been offered', | ||||||||||||||||||||||||||||||||||||||
| 42 | no_offer => 'no draw has been offered', | ||||||||||||||||||||||||||||||||||||||
| 43 | own_offer => 'you cannot answer your own offer', | ||||||||||||||||||||||||||||||||||||||
| 44 | chain_open => 'a move is in progress: finish it or stop', | ||||||||||||||||||||||||||||||||||||||
| 45 | nothing_to_stop => 'no move is in progress', | ||||||||||||||||||||||||||||||||||||||
| 46 | bad_move => 'that is not a move', | ||||||||||||||||||||||||||||||||||||||
| 47 | off_board => 'that point is not on the board', | ||||||||||||||||||||||||||||||||||||||
| 48 | no_stone => 'there is no stone there', | ||||||||||||||||||||||||||||||||||||||
| 49 | not_your_stone => 'that stone is not yours', | ||||||||||||||||||||||||||||||||||||||
| 50 | not_the_stone => 'the stone that is taking must go on, or stop', | ||||||||||||||||||||||||||||||||||||||
| 51 | not_adjacent => 'a stone steps to the next point along a line', | ||||||||||||||||||||||||||||||||||||||
| 52 | no_line => 'no line runs that way from there', | ||||||||||||||||||||||||||||||||||||||
| 53 | point_taken => 'a stone is standing there', | ||||||||||||||||||||||||||||||||||||||
| 54 | same_direction => 'a stone may not step twice running in the same direction', | ||||||||||||||||||||||||||||||||||||||
| 55 | point_revisited => 'a stone may not come back to a point in the same move', | ||||||||||||||||||||||||||||||||||||||
| 56 | paika_in_chain => 'a stone that has taken may stop, and may not then move on without taking', | ||||||||||||||||||||||||||||||||||||||
| 57 | takes_nothing => 'that step takes nothing that way', | ||||||||||||||||||||||||||||||||||||||
| 58 | choose_capture => 'that step can take two ways: say which, A or W', | ||||||||||||||||||||||||||||||||||||||
| 59 | must_capture => 'a stone can be taken, so one must be', | ||||||||||||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||
| 63 | 25 | has code => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||
| 65 | 25 | has message => (is => 'ro', default => ''); | |||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||
| 67 | 25 | has move => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||
| 69 | 25 | my $MAKING = 0; | |||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | 88 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 72 | 88 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 73 | 88 | ▶ | Carp::croak('Game::Fanorona::Error: a refusal is made by Game::Fanorona::Error->of') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 74 | unless $MAKING; | ||||||||||||||||||||||||||||||||||||||
| 75 | 87 | return; | |||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||
| 78 | 88 | ▶ | sub of { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
of: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 79 | 88 | my ($class, $code, %extra) = @_; | |||||||||||||||||||||||||||||||||||||
| 80 | Carp::croak("Game::Fanorona::Error: no such refusal as '" . ($code // 'undef') . "'") | ||||||||||||||||||||||||||||||||||||||
| 81 | 88 | ▶ | unless defined $code && exists $MESSAGE{$code}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
defined $code and exists $Game::Fanorona::Error::MESSAGE{$code}
$code // "undef"
MC/DC50%1/2
defined $code and exists $Game::Fanorona::Error::MESSAGE{$code}
defined $code
exists $Game::Fanorona::Error::MESSAGE{$code}
MC/DC0%0/1
$code // "undef"
$code
Truth table66%2/3
A and B
A= defined $codeB= exists $Game::Fanorona::Error::MESSAGE{$code}
Truth table50%1/2
A
A= $code
| |||||||||||||||||||||||||||||||||||||||
| 82 | 87 | $MAKING = 1; | |||||||||||||||||||||||||||||||||||||
| 83 | 87 | my $made = eval { | |||||||||||||||||||||||||||||||||||||
| 84 | $class->new( | ||||||||||||||||||||||||||||||||||||||
| 85 | code => $code, | ||||||||||||||||||||||||||||||||||||||
| 86 | message => $MESSAGE{$code}, | ||||||||||||||||||||||||||||||||||||||
| 87 | 87 | ▶ | (defined $extra{move} ? (move => "$extra{move}") : ()), | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||||||||||||
| 89 | }; | ||||||||||||||||||||||||||||||||||||||
| 90 | 87 | my $died = $@; | |||||||||||||||||||||||||||||||||||||
| 91 | 87 | $MAKING = 0; | |||||||||||||||||||||||||||||||||||||
| 92 | 87 | ▶ | Carp::croak($died) unless $made; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 93 | 87 | return $made; | |||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||
| 96 | 3 | ▶ | sub is { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 97 | 3 | my ($self, $code) = @_; | |||||||||||||||||||||||||||||||||||||
| 98 | 3 | ▶ | return defined $code && $self->code eq $code ? 1 : 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $code and $self->code eq $code
MC/DC100%2/2
defined $code and $self->code eq $code
defined $code
$self->code eq $code
Truth table100%3/3
A and B
A= defined $codeB= $self->code eq $code
| |||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | sub codes { @CODES } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
codes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||
| 103 | 43 | ▶ | sub message_for { $MESSAGE{ $_[1] // '' } } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
message_for: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
$_[1] // ""
MC/DC0%0/1
$_[1] // ""
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||
| 105 | 22 | ▶ | sub known { defined $_[1] && exists $MESSAGE{ $_[1] } ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
known: called CC=3 SCAR=11.1
Pod
documented
Branch: 1 branch
Condition66%2/3
defined $_[1] and exists $Game::Fanorona::Error::MESSAGE{$_[1]}
MC/DC50%1/2
defined $_[1] and exists $Game::Fanorona::Error::MESSAGE{$_[1]}
defined $_[1]
exists $Game::Fanorona::Error::MESSAGE{$_[1]}
Truth table66%2/3
A and B
A= defined $_[1]B= exists $Game::Fanorona::Error::MESSAGE{$_[1]}
| |||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||
| 107 | 25 | 1; | |||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||||||||||||||||||||