NAME

Commandable::Command - represent metadata for an invokable command

DESCRIPTION

Objects in this class are returned by a Commandable::Finder instance to represent individual commands that exist.

ACCESSORS

The following simple methods return metadata fields about the command

name

description

$name = $command->name;
$desc = $command->description;

Strings giving the short name (to be used on a commandline), and descriptive text for the command.

arguments

@args = $command->arguments;

A (possibly-empty) list of argument metadata structures.

options

%opts = $command->options;

A (possibly-empty) kvlist of option metadata structures.

package

$pkg = $command->package;

The package name as a plain string.

code

$sub = $command->code;

A CODE reference to the code actually implementing the command.

METHODS

parse_invocation

Since version 0.12 this method has been moved to Commandable::Finder.

ARGUMENT SPECIFICATIONS

Each argument specification is given by an object having the following structure:

name

description

$name = $argspec->name;

$desc = $argspec->description;

Text strings for the user, used to generate the help text.

optional

$bool = $argspec->optional;

If false, the option is mandatory and an error is raised if no value is provided for it. If true, it is optional and if absent an undef will passed instead.

slurpy

$bool = $argspec->slurpy;

If true, the argument will be passed as an ARRAY reference containing the entire remaining list of tokens provided by the user.

OPTION SPECIFICATIONS

Each option specification is given by an object having the following structure:

name

$name = $optspec->name;

A string giving the name of the option. This is the name it will be given in the options hash provided to the command subroutine.

names

@names = $optspec->names;

A list containing the name plus all the aliases this option is known by.

description

$desc = $optspec->description;

A text string containing information for the user, used to generate the help text.

mode

$mode = $optspec->mode;

A string that describes the behaviour of the option.

set options do not expect a value to be suppled by the user, and will store a true value in the options hash if present.

value options take a value from the rest of the token, or the next token.

--opt=value
--opt value

multi_value options can be supplied more than once; values are pushed into an ARRAY reference which is passed in the options hash.

inc options may be supplied more than once; each occurance will increment the stored value by one.

default

$val = $optspec->default;

A value to provide in the options hash if the user did not specify a different one.

negatable

$bool = $optspec->negatable;

If true, also accept a --no-OPT option to reset the value of the option to undef.

typespec

$type = $optspec->typespec;

If defined, gives a type specification that any user-supplied value must conform to.

The i type must be a string giving a (possibly-negative) decimal integer.

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>