NAME
Getopt::Pad::Result - The object GetOptions returns
SYNOPSIS
my $opt = GetOptions(
options => { 'log-level' => { type => 'string', default => 'info' } },
commands => {
resize => { options => { width => { type => 'int' } } },
},
);
# tool --log-level debug resize --width 640
$opt->logLevel; # 'debug'
$opt->command; # 'resize'
$opt->subcommand->width; # 640
$opt->help; # prints the help and exits
$opt->version; # prints the version and exits
DESCRIPTION
GetOptions returns a result object for the top level of the spec. For every command the command line selects, there is one more result object, reachable through subcommand. Each result object has one reader per option and arg of its level, plus the methods below.
The class of a result object is generated by Getopt::Pad for the readers of its level, and inherits from Getopt::Pad::Result. Its name is internal; use $opt->isa('Getopt::Pad::Result') to check for a result object.
The readers are read-only: there are no methods to set values, and calling a reader with an argument is an error. The values are plain Perl data: strings, numbers, and for options with several values arrayrefs and hashrefs. (One exception: a JSON true or false given to an option that is not a flag or bool, such as a string option, is returned as a JSON::PP::Boolean object, which stringifies to 1 or 0.) These references belong to the result object; if your program changes their contents, the reader returns the changed data from then on. Other parses are not affected. What each kind of option returns is listed in "Values by option kind" in Getopt::Pad, and how reader names are derived from option names in "Reader names" in Getopt::Pad.
METHODS
command
my $name = $opt->command;
The name of the command selected on this level, as declared in the spec. undef if the level has no commands, or if the command is optional (see "commandRequired" in Getopt::Pad) and was not given.
subcommand
my $commandResult = $opt->subcommand;
The result object of the selected command, with the readers of that command's options and args. undef whenever command is undef.
help
$opt->help;
Prints the help text of this result object's level to STDOUT and exits the program with status 0. It is the same text that --help prints on that level. $opt->subcommand->help prints the help of the selected command.
version
$opt->version;
Prints the program name and version to STDOUT, as the automatic --version option does, and exits the program with status 0.
RESERVED NAMES
Because every result object has the methods above and the methods every Perl object has, some names cannot be used for options and args. See "Reserved names" in Getopt::Pad for the list.
SEE ALSO
"RESULT OBJECT" in Getopt::Pad, Getopt::Pad
AUTHOR
davenonymous <perl@davenonymous.com>
COPYRIGHT AND LICENSE
Copyright 2026 davenonymous
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.