NAME

Game::Checkers::Error - what a move was refused for

VERSION

Version 0.01

SYNOPSIS

my $move = $game->move('11-16');

if (ref $move eq 'Game::Checkers::Error') {
	print $move->message, "\n";
	print "you could play: ", join(', ', @{$move->legal}), "\n"
		if @{$move->legal};
}

DESCRIPTION

A player's mistake is returned, never thrown: "move" in Game::Checkers gives back one of these instead of a Game::Checkers::Move, in the shape Game::Cribbage::Error uses. Only a programmer error dies, and a square outside 1 to 32 or a colour that is not black or white is a programmer error.

Every error carries the flag for what went wrong, a sentence for a person, and the moves that were available instead, because both the terminal and a web client want to show them.

PROPERTIES

error

Readonly, always true, so a caller can test one thing whatever went wrong.

$error->error;

message

Readonly string, one sentence for a person.

$error->message;

Readonly arrayref of the Game::Checkers::Move objects that were legal instead. For an ambiguous move it is the moves the notation matched.

$error->legal;

game_over

The game had already finished.

not_a_move

The string or hashref did not parse as a move at all.

not_your_piece

The square is empty or holds the other side's piece.

must_capture

A simple move was offered while a jump was available. Capture is compulsory.

wrong_direction

A man was moved backwards.

occupied

The destination square is not empty.

The move parsed, and it was the right player's piece, but it is not in the legal list. A jump over your own piece, a two square slide, and a multi jump stopped part way all arrive here.

ambiguous

The short form of a jump matched more than one legal sequence. Give the whole path.

no_offer

A draw was accepted or declined when none had been offered.

nothing_to_undo

"undo" in Game::Checkers was called on a game that has not moved.

FUNCTIONS

throw

Class method building an error from a flag, despite the name: it returns the error rather than dying, because that is the contract. Extra arguments are passed to the constructor, so legal can be overridden.

Game::Checkers::Error->throw('must_capture', legal => $moves);

code

The name of the flag that is set, which is what a web layer turns into an error code.

$error->code;   # 'must_capture'

stringify

The same as "message".

AUTHOR

LNATION, <email at lnation.org>

BUGS

Please report any bugs or feature requests to bug-game-checkers at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Game-Checkers. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Game::Checkers

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

This software is Copyright (c) 2026 by LNATION.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)