Alastair Douglas > Opt-Imistic-0.03 > Opt::Imistic

Download:
Opt-Imistic-0.03.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.03   Source   Latest Release: Opt-Imistic-0.04

NAME ^

Opt::Imistic - Optimistic option parsing

SYNOPSIS ^

    use Opt::Imistic;
    die if $ARGV{exit};

    use Opt::Imistic ( demand => ['c'], usage => 'Usage: prog -c foo' );
    # Program will fail at BEGIN if -c is not passed.

^

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 ^

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']

HINTS ^

Provide an array ref as the first argument to the import list to define a list of required options. Required options are assumed to require an argument because it doesn't make sense to require an option at compile time if you didn't need a value for it.

The second argument may be a string, which will be displayed as a usage string if a required option is not passed.

Other hints may be implemented.

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.

AUTHOR ^

Altreus <altreus@perl.org>

syntax highlighting: