| 1 | package Game::Checkers::Error; | ||||||||||
| 2 | |||||||||||
| 3 | 27 | ▶ | use strict; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 27 | ▶ | use warnings; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 27 | ▶ | use Object::Proto::Sugar -types; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 27 | our $VERSION = '0.03'; | |||||||||
| 9 | |||||||||||
| 10 | 27 | our (@FLAGS, %MESSAGE); | |||||||||
| 11 | |||||||||||
| 12 | # has is installed through BEGIN::Lift, so it runs at compile time: a list it is | ||||||||||
| 13 | # given must be built at compile time too | ||||||||||
| 14 | 27 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 27 | @FLAGS = qw/ | |||||||||
| 16 | game_over | ||||||||||
| 17 | not_a_move | ||||||||||
| 18 | not_your_piece | ||||||||||
| 19 | must_capture | ||||||||||
| 20 | wrong_direction | ||||||||||
| 21 | occupied | ||||||||||
| 22 | not_legal | ||||||||||
| 23 | ambiguous | ||||||||||
| 24 | no_offer | ||||||||||
| 25 | nothing_to_undo | ||||||||||
| 26 | /; | ||||||||||
| 27 | |||||||||||
| 28 | 27 | %MESSAGE = ( | |||||||||
| 29 | game_over => 'the game is over', | ||||||||||
| 30 | not_a_move => 'that is not a move', | ||||||||||
| 31 | not_your_piece => 'you have no piece on that square', | ||||||||||
| 32 | must_capture => 'a capture is available, so it must be taken', | ||||||||||
| 33 | wrong_direction => 'a man cannot move backwards', | ||||||||||
| 34 | occupied => 'that square is not empty', | ||||||||||
| 35 | not_legal => 'that is not a legal move', | ||||||||||
| 36 | ambiguous => 'that could be more than one move, so give the whole path', | ||||||||||
| 37 | no_offer => 'there is no draw to accept', | ||||||||||
| 38 | nothing_to_undo => 'there is nothing to undo', | ||||||||||
| 39 | ); | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | has [@FLAGS] => ( | ||||||||||
| 43 | is => 'ro' | ||||||||||
| 44 | 27 | ); | |||||||||
| 45 | |||||||||||
| 46 | has error => ( | ||||||||||
| 47 | is => 'ro', | ||||||||||
| 48 | default => 1 | ||||||||||
| 49 | 27 | ); | |||||||||
| 50 | |||||||||||
| 51 | has message => ( | ||||||||||
| 52 | is => 'ro', | ||||||||||
| 53 | isa => Str | ||||||||||
| 54 | 27 | ); | |||||||||
| 55 | |||||||||||
| 56 | has legal => ( | ||||||||||
| 57 | is => 'ro', | ||||||||||
| 58 | isa => ArrayRef, | ||||||||||
| 59 | default => [] | ||||||||||
| 60 | 27 | ); | |||||||||
| 61 | |||||||||||
| 62 | 39 | ▶ | sub throw { | ||||||||
|
Subroutine
throw: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 63 | 39 | my ($class, $flag, %extra) = @_; | |||||||||
| 64 | 39 | ▶ | die "'$flag' is not an error flag" unless $MESSAGE{$flag}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | return $class->new( | ||||||||||
| 66 | $flag => 1, | ||||||||||
| 67 | 39 | message => $MESSAGE{$flag}, | |||||||||
| 68 | %extra | ||||||||||
| 69 | ); | ||||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 3 | ▶ | sub code { | ||||||||
|
Subroutine
code: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 73 | 3 | my ($self) = @_; | |||||||||
| 74 | 3 | for my $flag (@FLAGS) { | |||||||||
| 75 | 17 | ▶ | return $flag if $self->$flag; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | } | ||||||||||
| 77 | 0 | return undef; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 1 | ▶ | sub stringify { | ||||||||
|
Subroutine
stringify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 81 | 1 | return $_[0]->message; | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 27 | 1; | |||||||||
| 85 | |||||||||||
| 86 | __END__ | ||||||||||