NAME

Game::Merrills::Error - a move the game refused, and why

VERSION

Version 0.03

SYNOPSIS

my $move = $game->move('d2-d4');

if (ref $move eq 'Game::Merrills::Error') {
	$move->code;                 # 'not_a_move'
	$move->message;              # 'that is not a move'
	$move->not_a_move;           # 1
	$move->legal;                # what could be played instead
}

DESCRIPTION

When a player asks for something the rules do not allow, the game does not die. It hands back one of these in place of the move, and the game is left exactly as it was.

Every refusal has one flag set, a name for the reason that code can test, and a message a person can read. The message is a sentence without its capital or its full stop, so it can be put into a longer one.

throw is the house's name for making one. It returns the object and does not die.

The reasons

game_over

The game has ended.

not_a_move

What was asked for could not be read as a move at all.

men_in_hand

A man was moved while the side still has men to place.

no_men_in_hand

A man was placed when the side has none left in hand.

not_your_man

The point to move from holds no man of the side to move.

occupied

The point to land on is not empty.

not_adjacent

The man was moved to a point that is not next to it along a line, by a side that may not fly.

must_remove

The move closes a mill and does not say which man it takes.

nothing_to_remove

The move names a man to take and closes no mill.

no_man_there

The point named to take from holds no enemy man.

man_in_mill

The man named is in a mill, and an enemy man outside any mill could be taken instead.

The move is not legal for a reason none of the others covers.

no_offer

A draw was accepted or declined that the other side had not offered.

nothing_to_undo

No move has been played, so none can be taken back.

PROPERTIES

All are read only.

game_over

not_a_move

men_in_hand

no_men_in_hand

not_your_man

occupied

not_adjacent

must_remove

nothing_to_remove

no_man_there

man_in_mill

not_legal

no_offer

nothing_to_undo

One for each reason above, true on the refusal that has that reason and undefined on every other.

$error->occupied;

error

Always true, so that anything a game returns can be asked whether it is one.

$error->error;

message

The reason, as a sentence without its capital or full stop.

$error->message;

An arrayref of the Game::Merrills::Move objects that could have been played instead. Empty when the game is over.

$error->legal;

METHODS

throw

Makes a refusal from a flag, with anything further to set on it. Returns it. Dies when the flag is not one of the reasons.

my $error = Game::Merrills::Error->throw('occupied', legal => $moves);

flags

Every reason, as a list, in the order a refusal is searched for its code.

my @flags = Game::Merrills::Error->flags;

messages

A hashref of the message for every reason, a fresh copy each time.

my $messages = Game::Merrills::Error->messages;

code

The name of the reason.

$error->code;                    # 'occupied'

stringify

The same as "message".

$error->stringify;

PACKAGE VARIABLES

@FLAGS

The reasons, in order.

%MESSAGE

The message for each reason.

AUTHOR

LNATION, <email at lnation.org>

LICENSE AND COPYRIGHT

This software is Copyright (c) 2026 by LNATION.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)