NAME

Game::Reversi::Error - why a move was refused

VERSION

Version 0.01

SYNOPSIS

my $error = Game::Reversi::Opening->check($board, $square);
if ($error) {
    warn $error->code;        # 'not_centre'
    warn $error->message;     # 'the first four discs go in the centre four'
}

DESCRIPTION

A refusal, returned rather than thrown. Every rejection a player can cause comes back as one of these, so a caller tests a return value instead of wrapping a move in eval. die is kept for programmer error: a move that came out of legal and was then refused is a fault in the code, not in the player.

The flag list grows a phase at a time

Every flag is reachable from a real refusal and the suite asserts each one. A code nothing can produce is dead weight, and here it is worse than that: the site adapter maps every flag onto one of its own error codes, so an unreachable flag becomes an unreachable row in a table somebody has to keep.

METHODS

not_centre, square_taken, not_your_turn, no_flip, has_move, game_over

One predicate per flag: true on the error that carries it, false otherwise. This list has to be kept in step with @FLAGS, and t/pod-coverage.t is what notices when it is not, since each flag becomes an accessor.

throw

Builds the error for a flag, filling in its message. Dies on a flag that is not in the list, because that is a typo rather than a refusal.

code

The flag that is set.

message

The sentence for it.

What could have been done instead, where the caller supplied it.

flags

Every flag this class knows.

error

Always true, so a caller can test the returned value directly.

stringify

The code and the message together.

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.