| 1 | package Term::Chess::Error; | ||||||||||
| 2 | |||||||||||
| 3 | 7 | ▶ | use 5.014; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 7 | ▶ | use warnings; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 7 | ▶ | use Object::Proto::Sugar -types; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 7 | our $VERSION = '0.02'; | |||||||||
| 10 | |||||||||||
| 11 | 7 | our @FLAGS; | |||||||||
| 12 | 7 | ▶ | BEGIN { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 7 | @FLAGS = qw( | |||||||||
| 14 | bad_move | ||||||||||
| 15 | game_over | ||||||||||
| 16 | not_your_turn | ||||||||||
| 17 | no_piece | ||||||||||
| 18 | bad_promotion | ||||||||||
| 19 | in_check | ||||||||||
| 20 | not_legal | ||||||||||
| 21 | ); | ||||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 7 | our %MESSAGE; | |||||||||
| 25 | 7 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 7 | %MESSAGE = ( | |||||||||
| 27 | bad_move => 'that is not a move', | ||||||||||
| 28 | game_over => 'the game is already over', | ||||||||||
| 29 | not_your_turn => 'that piece is not yours to move', | ||||||||||
| 30 | no_piece => 'there is no piece there', | ||||||||||
| 31 | bad_promotion => 'a pawn reaching the last rank must say what it becomes', | ||||||||||
| 32 | in_check => 'that would leave your king in check', | ||||||||||
| 33 | not_legal => 'that piece cannot move there', | ||||||||||
| 34 | ); | ||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 7 | has [@FLAGS] => (is => 'ro'); | |||||||||
| 38 | |||||||||||
| 39 | 7 | has error => (is => 'ro', default => 1); | |||||||||
| 40 | |||||||||||
| 41 | 7 | has message => (is => 'ro', isa => Str, default => ''); | |||||||||
| 42 | |||||||||||
| 43 | 7 | has legal => (is => 'ro', isa => ArrayRef, default => []); | |||||||||
| 44 | |||||||||||
| 45 | 41 | ▶ | sub throw { | ||||||||
|
Subroutine
throw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 46 | 41 | my ($class, $flag, %extra) = @_; | |||||||||
| 47 | 41 | ▶ | die "Term::Chess::Error: no such flag '$flag'" unless exists $MESSAGE{$flag}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | return $class->new( | ||||||||||
| 49 | $flag => 1, | ||||||||||
| 50 | error => 1, | ||||||||||
| 51 | 40 | message => $MESSAGE{$flag}, | |||||||||
| 52 | %extra, | ||||||||||
| 53 | ); | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 23 | ▶ | sub code { | ||||||||
|
Subroutine
code: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 57 | 23 | my ($self) = @_; | |||||||||
| 58 | 23 | for my $flag (@FLAGS) { | |||||||||
| 59 | 69 | ▶ | return $flag if $self->$flag; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | } | ||||||||||
| 61 | 0 | return undef; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 1 | ▶ | sub stringify { $_[0]->message } | ||||||||
|
Subroutine
stringify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 65 | |||||||||||
| 66 | 1 | ▶ | sub flags { @FLAGS } | ||||||||
|
Subroutine
flags: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 67 | |||||||||||
| 68 | 7 | ▶ | sub message_for { $MESSAGE{ $_[1] } } | ||||||||
|
Subroutine
message_for: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 69 | |||||||||||
| 70 | 3 | ▶ | sub known { exists $MESSAGE{ $_[1] } ? 1 : 0 } | ||||||||
|
Subroutine
known: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||
| 71 | |||||||||||
| 72 | 7 | 1; | |||||||||
| 73 | |||||||||||
| 74 | __END__ | ||||||||||