| 1 | package Game::Gin::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 | hand_over => 'the hand is over', | ||
| 12 | not_your_turn => 'it is not your turn', | ||
| 13 | not_legal => 'the rules do not offer that', | ||
| 14 | not_held => 'that card is not in your hand', | ||
| 15 | just_taken => 'you may not discard the card you have just taken', | ||
| 16 | cannot_knock => 'your deadwood is above the knock threshold', | ||
| 17 | not_big_gin => 'that hand is not big gin', | ||
| 18 | no_seed => 'a hand needs a seed', | ||
| 19 | ); | ||
| 20 | |||
| 21 | has code => (is => 'ro', isa => Str); | ||
| 22 | has message => (is => 'ro', isa => Str); | ||
| 23 | |||
| 24 | sub new_code { | ||
| 25 | my ($class, $code) = @_; | ||
| 26 | return $class->new( | ||
| 27 | code => $code, | ||
| 28 | message => $MESSAGE{$code} // $code, | ||
| 29 | ); | ||
| 30 | } | ||
| 31 | |||
| 32 | sub codes { return sort keys %MESSAGE } | ||
| 33 | |||
| 34 | 1; | ||
| 35 | |||
| 36 | __END__ |