NAME

Getopt::Alt - Alternate method of processing command line arguments

VERSION

This documentation refers to Getopt::Alt version 0.1.

SYNOPSIS

use Getopt::Alt;

# Create a new options object
my $opt = Getopt::Alt->new(
    {
        default => { string => 'default' },
    },
    [
        'string|s=s',
        ...
    ],
);
print "String = " . $opt->opt->{string} . "\n";

DESCRIPTION

The aim of Getopt::Alt is to provide an alternative to Getopt::Long that allows your simple script to easily grow to a more complex script or to a package with multiple commands. The simple usage is quite similar to Getopt::Long:

In Getopt::Long you might get your options like:

use Getopt::Long;
my %options = ( string => 'default' );
GetOptions(
    \%options,
    'string|s=s',
    ...
);

The found options are now stored in the %options hash.

In Getopt::Alt you might do the following:

use Getopt::Alt qw/get_options/;
my %default = ( string => 'default' );
my $opt = get_options(
    \%default,
    'string|s=s',
    ...
);
my %options = %{ $opt->opt };

This will also result in the options stored in the %options hash.

Some other differences between Getopt::Alt and Getopt::Long include:

  • Bundling - is on by default

  • Case sensitivity is on by default

  • Throws error rather than returning errors.

SUBROUTINES/METHODS

new ( \%config, \@optspec )

config

default - HashRef

Sets the default values for all the options. The values in opt will be reset with the values in here each time process is called

files - ArrayRef[Str]

Any arguments that not consumed as part of options (usually files), if argv was not specified then this value would be put back into @ARGV.

argv - ArrayRef[Str]

The arguments that you wish to process, this defaults to @ARGV.

bundle - bool

Turns on bundling of arguments eg -rv is equivalent to -r -v. This is on by default.

ignore_case - bool

Turns ignoring of the case of arguments, off by default.

helper - bool

If set to a true value this will cause the help, man, and VERSION options to be added the end of your

help -

???

cmds - ArrayRef[Getopt::Alt::Command]

If the Getopt::Alt is being used as part of a package where individual commands have their own modules this parameter stores an instance of each commands. (Not yet fully implemented.

options - ArrayRef[Getopt::Alt::Option]

The individual command option specifications processed.

opt - HashRef

The values processed from the argv.

default - HashRef

The default values for each option. The default value is not modified by processing, so if set the same default will be used from call to call.

Return: Getopt::Alt -

Description:

get_options (@options | $setup, $options)

get_options ($default, 'opt1', 'opt2' ... )

This is the equivalent of calling new(...)->process but it does some extra argument processing.

Note: The second form is the same basically the same as Getopt::Long's getOptions called with a hash ref as the first parameter.

BUILD ()

internal method

process ()

best_option ()

get_files ()

DIAGNOSTICS

CONFIGURATION AND ENVIRONMENT

DEPENDENCIES

INCOMPATIBILITIES

BUGS AND LIMITATIONS

There are no known bugs in this module.

Please report problems to Ivan Wills (ivan.wills@gmail.com).

Patches are welcome.

AUTHOR

Ivan Wills - (ivan.wills@gmail.com)

LICENSE AND COPYRIGHT

Copyright (c) 2009 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.