| 1 | package Game::Durak::Error; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Object::Proto::Sugar -types; | ||
| 7 | |||
| 8 | our $VERSION = '0.04'; | ||
| 9 | |||
| 10 | my %MESSAGE = ( | ||
| 11 | no_seed => 'a deal needs a seed', | ||
| 12 | bad_deal => 'a deal number counts from one', | ||
| 13 | bad_seats => 'this engine deals two seats', | ||
| 14 | game_over => 'the deal is over', | ||
| 15 | not_your_turn => 'it is not your turn', | ||
| 16 | wrong_phase => 'that move does not fit this stage of the bout', | ||
| 17 | not_legal => 'the rules do not offer that', | ||
| 18 | card_not_held => 'you do not hold that card', | ||
| 19 | beats_nothing => 'that card does not beat the one in front of you', | ||
| 20 | rank_not_in_bout => 'nothing on the table has that rank', | ||
| 21 | bout_full => 'the attack is already as large as it may be', | ||
| 22 | must_attack => 'a bout has to be opened before it can be beaten off', | ||
| 23 | not_the_six => 'that exchange is not yours to make', | ||
| 24 | talon_shut => 'the turned up trump has been drawn', | ||
| 25 | ); | ||
| 26 | |||
| 27 | has code => (is => 'ro', isa => Str); | ||
| 28 | has message => (is => 'ro', isa => Str); | ||
| 29 | |||
| 30 | sub new_code { | ||
| 31 | my ($class, $code) = @_; | ||
| 32 | return $class->new( | ||
| 33 | code => $code, | ||
| 34 | message => defined $MESSAGE{$code} ? $MESSAGE{$code} : $code, | ||
| 35 | ); | ||
| 36 | } | ||
| 37 | |||
| 38 | sub codes { return sort keys %MESSAGE } | ||
| 39 | |||
| 40 | 1; | ||
| 41 | |||
| 42 | __END__ |