Getopt::OO 0.07 review
DownloadGetopt::OO is an object oriented command line parser
|
|
Getopt::OO is an object oriented command line parser. It handles short, long and multi (--x ... -) value options. Getopt::OO module also incorporates help for options to simplify generation of usage statements.
SYNOPSIS
use Getopt::OO qw(Debug Verbose);
my ($handle) = Getopt::OO->new(@ARGV,
'-d' => {
help => 'turn on debug output',
callback => sub {Debug(1); 0},
},
'-o' => {
help => 'another option.',
},
'-f' => {
help => 'option that expects one more value.',
n_values => 1,
},
'--long' {
help => 'long option'
},
'--multiple_' => {
help => [
"Everything between '--multiple_values' and '-' is",
"an value for this options",
],
'multi_value' => 1,
'multiple= => 1, # Can happen more than once on command line.
},
other_values => {
help => 'file_1 ... file_n',
multi_value => 1,
},
);
if ($handle->Values()) {
Debug("You will get output if -d was on command line");
if (my $f = handle->Values(-f)) {
print "Got $f with the -f value.n";
}
}
else {
print "No options found on command line.n";
}
Getopt::OO is an object oriented tool for parsing command line arguments. It expects a reference to the input arguments and uses a perl hash to describe how the command line arguments should be parsed. Note that by parsed, we mean what options expect values, etc. We check to make sure values exist on the command line as necessary -- nothing else. The caller is responsible for making sure that a value that he knows should be a file exists, is writable, or whatever.
Command line arguments can be broken into two distinct types: options and values that are associated with these options. In windows, options often start with a '/' but sometimes with a '-', but in unix they almost universally start with a '-'. For this module options start with a '-'. We support two types of options: the short single dashed options and the long double dashed options.
The difference between these two is that with this module the short options can be combined into a single option, but the long options can not. For example, most of us will be familiar with the tar -xvf file command which can also be expressed as -x -v -f file. Long options can not be combined this way, so '--help' for example must always stand by itself.
The input template expects the option names as its keys. For instance if you were expecting -xv --hello as possible command line options, the keys for your template hash would be -x, -v, and --hello.
Requirements:
Perl
Getopt::OO 0.07 keywords