Getopt::Chain::v005::Context - Per-command context
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
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
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
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)
Returns the keys of the option hash in list context
Returns the option HASH reference in scalar context
./script --verbose ... if ( $context->options->{verbose} ) { ... }
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
An initially empty HASH reference that can be used for sharing inter-command information
Similar to the stash in Catalyst
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 )
Returns a copy of the remaining arguments (@ARGV) for the current command AFTER option parsing
./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 ( )
Immediately exit the process with exit code of -1
If the optional ... (message) is given, then print that out to STDERR first
Getopt::Chain::v005
To install Getopt::Chain, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Getopt::Chain
CPAN shell
perl -MCPAN -e shell install Getopt::Chain
For more information on module installation, please visit the detailed CPAN module installation guide.