NAME

Getopt::Awesome - Expands the Getopt *automatically* for modules.

DESCRIPTION

First of, this module was very inspired in the Getopt::Modular CPAN apckage, however at the moment of creating this module the dependency chain of the mentioned module was very large so I though would be a nice idea to copy some concepts from it and the regular Getopt.

Now, this module is handy if you want to give "getopt options" to a module like it could be a normal perl script (.pl) and don't want to be rewriting all the options over and over everytime.

When user asks for help usage (-h or --help) he/she will also get all the available options that were set via this module.

All options are prefixed by the package name in lowercase where namespace separator (::) gets replaced by a dash (-), so --help will return:

--foo-bar-option Description --foo-bar-option2 Description 2

and so on..

See the SYNOPSYS section for examples.

NOTE 1: The use of short aliases is not supported for options defined in modules, only for main (the .pl script). NOTE 2: In your perl script (.pl) remember to call parse_opts otherwise the values of the options you request might be undef, empty or have your default values. ARGV is ONLY parsed when parse_opt is called.

SYNOPSYS

package Your::Package;

use Getopt::Awesome qw(:common);
define_option('foo=s', 'Fooi bar');
...or...

define_options(
    ('foo=s', 'Foo'),
    ('bar=s', 'Bar'));

parse_opts();
my $foo_val = get_opt('option_name', 'Default value');

FUNCTIONS

define_options (array)

use Getopt::Awesome;
Getopt::Awesome qw(:common);

define_options(
    ('option_name', 'Option description')
);

It defines the given options for current package, please note the options defined in the current caller package are not shared with other modules, this means that 'foo' option from package 'Foo' will not exist or will have different value from the 'foo' option of 'Bar' package.

Each array item should consist at least of 1 item with a max of 2. The first parameter should be the option name while the second one (optional) is the option description.

Some notes about the option name, the first item of every array:

* It's a required parameter. * It accepts any of the Getopt::Long option name styles (=s, !, =%s, etc).

define_option (string, optional string)

use Getopt::Awesome qw(:common);

define_option('option_name', 'Description');

It calls the define_options subroutine for adding the given option.

Please refer to the documentation of define_options for a more complete description about it, but basically some notes:

* The option name is a required parameter * The option accepts any of te Getopt::Long option name styles.

get_opt ([string package], string option name, string default value)

use Getopt::Awesome qw(:common);

my $val = get_opt('option_name', 'Some default opt');

It will return the value of the given option, if there's no option set then undefined will be returned.

Please note that if the option is set to expect a list you will receive a list, same for integer, strings, booleans, etc. Same as it happens with the Getopt::Long.

set_opt ([string package], string option name, string value)

use Getopt::Awesome qw(:common);

set_opt('option_name', 'Value');

parse_opts

This subroutine should never be called directly unless you want to re-parse the arguments or that your module is not getting called from a perl script (.pl).

In case you want to call it:

use Getopt::Awesome qw(:common);

parse_opts();

usage

Based on all the current options it will returns a nice and helpful 'guide' to use the current options.

Although the usage gets called directly if a -h or --help is passed and also if no_usage is set you can call it directly:

use Getopt::Awesome qw(:all);

usage();

_build_all_options

Should _never_ be called. It will parse all the options we have right now from main and other modules and prepare a hash that GetOpt::Long-GetOptions> will use to parse the arguments.

_get_option_package

Returns the right option package where the options are going to be stored.