NAME
Game::Mahjong::Error - a refused move, as an object and not an exception
VERSION
Version 0.01
SYNOPSIS
my $e = Game::Mahjong::Error->throw('tile_not_held', legal => \@legal);
$e->error; # 1
$e->tile_not_held; # 1
$e->code; # 'tile_not_held'
$e->message; # 'you do not hold that tile'
DESCRIPTION
The rules return one of these for a move they refuse; nothing in the engine dies for a player's mistake. A caller tests $result->error or the flag it is interested in. The sentences here are the engine's English for a terminal; the site keeps its own, translated, keyed by the same codes.
The codes
not_your_turn the seat is not the one waited on
wrong_phase a discard in a window, an answer outside one
tile_not_held a discard, a kong or a chow naming a tile the seat has not got
cannot_claim the seat has no such claim on the tile in the window
not_a_meld the two tiles named for a chow do not run with it
no_kong a kong after a chow or pung this turn, or with no fourth tile
not_a_win the hand is not a complete structure
too_few_points complete, but under eight without flowers
no_window an answer when no window is open
already_answered a second answer in one window
game_over the game has finished
bad_move not a move the rules know
METHODS
throw
A class method that returns (does not die) a flagged error. Dies only if asked for a flag that does not exist, which is programmer error.
code
The flag that is set.
error
Always true, so a result can be tested without knowing which flag to ask for.
message
The English sentence.
legal
The legal moves at the time, when the rules supply them.
flags
The list of flags.
messages
A copy of the flag-to-sentence table.
not_your_turn, wrong_phase, tile_not_held, cannot_claim, not_a_meld, no_kong, not_a_win, too_few_points, no_window, already_answered, game_over, bad_move
The flag accessors: 1 on the one that was thrown, undef on the rest.
SEE ALSO
AUTHOR
LNATION <email@lnation.org>
LICENSE AND COPYRIGHT
This software is Copyright (c) 2026 by LNATION <email@lnation.org>.
This is free software, licensed under the Artistic License 2.0.