| 1 | package Game::Shogi::Error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use Object::Proto::Sugar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 9 | my @CODES = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | bad_move not_your_piece not_in_hand cannot_reach occupied | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | promote_not_allowed promote_required dead_piece two_pawns in_check pawn_drop_mate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | game_over not_your_turn cannot_declare nothing_to_undo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 9 | my %MESSAGE = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | bad_move => 'that is not a move', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | not_your_piece => 'there is no piece of yours there', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | not_in_hand => 'you have none of that piece in hand', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | cannot_reach => 'that piece cannot move there', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | occupied => 'a piece cannot be dropped onto another', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | promote_not_allowed => 'that piece may not promote on that move', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | promote_required => 'that piece must promote on that move', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | dead_piece => 'a piece cannot be dropped where it could never move', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | two_pawns => 'you already have an unpromoted pawn on that file', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | in_check => 'that would leave your king in check', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | pawn_drop_mate => 'a pawn may not be dropped to give mate', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | game_over => 'the game is already over', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | not_your_turn => 'it is not your turn', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | cannot_declare => 'the impasse may not be declared', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | nothing_to_undo => 'there is no move to take back', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 9 | my @FAULT = (undef, @CODES[ 0 .. 10 ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 9 | has code => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 9 | has message => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 29 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=4 SCAR=17.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 29 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 29 | my $code = $self->code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | Carp::croak("Game::Shogi::Error: no such refusal '" . ($code // 'undef') . "'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 29 | ▶ | unless defined $code && exists $MESSAGE{$code}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
defined $code and exists $MESSAGE{$code}
$code // "undef"
MC/DC0%0/2
defined $code and exists $MESSAGE{$code}
defined $code
exists $MESSAGE{$code}
MC/DC0%0/1
$code // "undef"
$code
Truth table33%1/3
A and B
A= defined $codeB= exists $MESSAGE{$code}
Truth table0%0/2
A
A= $code
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 29 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 30 | ▶ | sub throw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 30 | my ($class, $code, $detail) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | Carp::croak("Game::Shogi::Error: no such refusal '" . ($code // 'undef') . "'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 30 | ▶ | unless defined $code && exists $MESSAGE{$code}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
defined $code and exists $MESSAGE{$code}
$code // "undef"
MC/DC50%1/2
defined $code and exists $MESSAGE{$code}
defined $code
exists $MESSAGE{$code}
MC/DC0%0/1
$code // "undef"
$code
Truth table66%2/3
A and B
A= defined $codeB= exists $MESSAGE{$code}
Truth table50%1/2
A
A= $code
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 29 | my $message = $MESSAGE{$code}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 29 | ▶ | $message .= ": $detail" if defined $detail && length $detail; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $detail and length $detail
MC/DC50%1/2
defined $detail and length $detail
defined $detail
length $detail
Truth table66%2/3
A and B
A= defined $detailB= length $detail
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 29 | return $class->new(code => $code, message => $message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 19 | ▶ | sub of_fault { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
of_fault: called CC=5 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 19 | my ($class, $fault) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 19 | ▶ | return undef unless defined $fault && $fault =~ /\A[0-9]+\z/ && $fault >= 1 && $FAULT[$fault]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
defined $fault and $fault =~ /\A[0-9]+\z/u and $fault >= 1 and $FAULT[$fault]
defined $fault and $fault =~ /\A[0-9]+\z/u and $fault >= 1
defined $fault and $fault =~ /\A[0-9]+\z/u
MC/DC0%0/4
defined $fault and $fault =~ /\A[0-9]+\z/u and $fault >= 1 and $FAULT[$fault]
defined $fault
$fault =~ /\A[0-9]+\z/u
$fault >= 1
$FAULT[$fault]
Truth table20%1/5
A and B and C and D
A= defined $faultB= $fault =~ /\A[0-9]+\z/uC= $fault >= 1D= $FAULT[$fault]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 19 | return $class->throw($FAULT[$fault]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | sub codes { @CODES } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
codes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub known { defined $_[1] && exists $MESSAGE{ $_[1] } ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
known: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
Condition0%0/3
defined $_[1] and exists $MESSAGE{$_[1]}
MC/DC0%0/2
defined $_[1] and exists $MESSAGE{$_[1]}
defined $_[1]
exists $MESSAGE{$_[1]}
Truth table0%0/3
A and B
A= defined $_[1]B= exists $MESSAGE{$_[1]}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 11 | ▶ | sub message_for { defined $_[1] ? $MESSAGE{ $_[1] } : undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
message_for: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub stringify { $_[0]->message } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||