NAME
Opt::Imistic - Optimistic option parsing
SYNOPSIS
use Opt::Imistic;
die if $ARGV{exit};
DESCRIPTION
Most option parsers end up doing the same thing but you have to write a whole spec to do it. This one just gets all the options and then gets out of your way.
For the most part, your command-line options will probably be one of two things: a toggle (or maybe a counter), or a key/value pair. Opt::Imistic assumes this and parses your options. If you need more control over it, Opt::Imistic is not for you and you might want to try a module such as Getopt::Long.
The hash %ARGV
contains your arguments. The argument name is provided as the key and the value is provided as the value. If the argument appeared multiple times, the values are grouped as an array ref. If you use the same argument multiple times and sometimes without a value then that instance of the option will be represented as undef. If you provide the option multiple times and none has a value then your value is the count of the number of times the option appeared.
Long options start with --
. Short options are single letters and start with -
. Multiple short options can be grouped without repeating the -
. Currently the value must be separated from the option letter in the case of short options; but for long options, both whitespace and a single =
are considered delimiters.
The options are considered to stop on the first argument that does not start with a -
and cannot be construed as the value to an option. You can use the standard --
to force the end of option parsing. Everything after the last option goes under the special key -
, which can never be an option name. These are also left on @ARGV so that <>
still works.
Examples help
script.pl -abcde
a => 1
b => 1
c => 1
d => 1
e => 1
That one's obvious.
script.pl -a foo.pl
a => 'foo.pl'
@ARGV = ()
script.pl -a -- foo.pl
a => 1
- => 'foo.pl'
@ARGV = ('foo.pl')
script.pl -foo
f => 1
o => 2
script.pl -foo bar
f => 1
o => [undef, 'bar']
script.pl --foo bar --foo=bar
foo => ['bar', 'bar']
BUGS AND TODOS
No known bugs, but undesirable behaviour should be reported.
Please note the TODO list first:
- Implement hints to the parser to allow single options not to require delimiting from their values
- Implement further hints to alias options.
- Implement a required list and a usage string
AUTHOR
Altreus <altreus@perl.org>