NAME
Getopt::Chain::v005::Context - Per-command context
DESCRIPTION
A context encapsulates the current state of execution, including:
The name of the current command (or undef if at the "root")
Every option parsed so far
Options local to the current command
The arguments as they were BEFORE parsing options for this command
The arguments remaining AFTER parsing options for this command
METHODS
$context->command
Returns the name of the current command (or undef in a special case)
./script --verbose edit --file xyzzy.c
# The command name is "edit" in the edit subroutine
./script --help
# The command name is undef in the root subroutine
$context->option( <name> )
Returns the value of the option for <name>
<name> should be primary name of the option (see Getopt::Long for more information on primary/alias naming)
If called in list context and the value of option is an ARRAY reference, then this method returns a list:
./script --exclude apple --exclude banana --exclude --cherry
...
my @exclude = $context->option( exclude )
See Hash::Param for more usage information
$context->options( <name>, <name>, ... )
Similar to ->option( <name> ) except for many-at-once
Returns a list in list context, and an ARRAY reference otherwise (you could end up with a LoL situation in that case)
See Hash::Param for more usage information
$context->options
Returns the keys of the option hash in list context
Returns the option HASH reference in scalar context
./script --verbose
...
if ( $context->options->{verbose} ) { ... }
See Hash::Param for more usage information
$context->local_option
$context->local_options
Behave similarly to ->option and ->options, except only cover options local to the current command
./script --verbose edit --file xyzzy.c
$context->local_option( file ) # Returns 'xyzzy.c'
$context->local_option( verbose ) # Doesn't return anything
$context->option( verbose ) # Returns 1
$context->stash
An initially empty HASH reference that can be used for sharing inter-command information
Similar to the stash in Catalyst
$context->arguments
Returns a copy of the arguments (@ARGV) for the current command BEFORE option parsing
Returns an ARRAY reference (still a copy) when called in scalar context
./script --verbose edit --file xyzzy.c
# At the very beginning:
$context->arguments # Returns ( --verbose edit --file xyzzy.c )
# In the "edit" subroutine:
$context->arguments # Returns ( edit --file xyzzy.c )
$context->remaining_arguments
Returns a copy of the remaining arguments (@ARGV) for the current command AFTER option parsing
Returns an ARRAY reference (still a copy) when called in scalar context
./script --verbose edit --file xyzzy.c
# At the very beginning:
$context->remaining_arguments # Returns ( edit --file xyzzy.c )
# In the "edit" subroutine:
$context->remaining_arguments # Returns ( )
$context->abort( [ ... ] )
Immediately exit the process with exit code of -1
If the optional ... (message) is given, then print that out to STDERR first