NAME
Game::Terminal::Kit::Options - the options a game offers before it starts
VERSION
Version 0.05
SYNOPSIS
package Game::Checkers::Terminal;
sub options {
return [
{ name => 'level', type => 'int', min => 1, max => 5,
help => 'the strength of the bot' },
{ name => 'side', type => 'enum', choices => [qw(black white random)],
help => 'your side; black moves first' },
{ name => 'hotseat', type => 'flag',
help => 'two people at one keyboard, no bot' },
];
}
# and in whatever asks the player
use Game::Terminal::Kit::Options;
my $fields = Game::Checkers::Terminal->options;
my %values = (level => 3, hotseat => 1);
my @argv = Game::Terminal::Kit::Options::argv_for($fields, \%values);
# --level 3 --hotseat
DESCRIPTION
A game says which of its command line options a person would want to set before playing, as a list of fields, and anything that starts the game can then show them as a form and turn the answers back into a command line. The game stays the one place its options are written down.
A field
A hash reference with a name, which is the option without its dashes, a type, and a help of one short clause. The types:
int-
A whole number from
mintomax. Sent as--name 3. enum-
One of
choices, an array reference of two or more. Sent as--name choice. flag-
On or off. Sent as
--namewhen on and not at all when off. bool-
On, off, or left alone. Sent as
--name, as--no-name, or not at all. str-
Any text. Sent as
--name text.
A value that is undef is one the player left alone, and nothing is sent for it: the game's own default applies, and nobody else has to know what it is.
FUNCTIONS
None is exported.
step_value
my $next = Game::Terminal::Kit::Options::step_value($field, $current, +1);
The value one step up or down from the current one. A number stops at its ends; a choice goes round; a flag turns over; a bool goes round its three states. From a value left alone, up gives the least number or the first choice and down gives the greatest or the last. Text does not step.
check_value
my ($value, $error) = Game::Terminal::Kit::Options::check_value($field, $text);
What typed text means for the field: the value, or a sentence saying what the field takes. Blank text is a value left alone, undef with no error. A choice is matched without regard to case.
argv_for
my @argv = Game::Terminal::Kit::Options::argv_for(\@fields, \%values);
The command line for those values, in the order of the fields. A value under extra is split as a shell would split it and put last.
validate
my @wrong = Game::Terminal::Kit::Options::validate(\@fields);
What is wrong with a list of fields, one sentence each; nothing when it is sound. A name must be lower case letters, digits and dashes and may not be there twice; ascii, pick, help, version and extra are kept by the launcher; every field needs help and a type; a number needs its ends in order and a choice needs two.
types
reserved
The types and the kept names, sorted.
SEE ALSO
Game::Terminal::Kit, Game::Terminal.
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)