NAME
Getopt::EX::Loader - RC/Module loader
SYNOPSIS
use Getopt::EX::Loader;
my $loader = Getopt::EX::Loader->new(
BASECLASS => 'App::example',
);
$loader->load_file("$ENV{HOME}/.examplerc");
$loader->deal_with(\@ARGV);
my $parser = Getopt::Long::Parser->new;
$parser->getoptions(... , $loader->builtins);
or
$parser->getoptions(\%hash, ... , $loader->hashed_builtins(\%hash));
DESCRIPTION
This is the main interface to use Getopt::EX modules. You can create a loader object, load user-defined rc files, load modules specified by command arguments, substitute user-defined options and insert default options defined in rc files or modules, and get module-defined built-in option definitions for the option parser.
Most of the work is done in the deal_with method. It parses command arguments and loads modules specified by the -M option by default. Then it scans options and substitutes them according to the definitions in the rc file or modules. If the RC file and modules define default options, they are inserted into the arguments.
Modules can define built-in options which should be handled by the option parser. They can be retrieved by the builtins method, so you should pass them to the option parser.
If option values are stored in a hash, use hashed_builtins with the hash reference. Actually, builtins works even for hash storage in the current version of the Getopt::Long module, but it is not documented.
If App::example is given as a BASECLASS of the loader object, it is prepended to all module names. So command line
% example -Mfoo
will load App::example::foo module.
In this case, if the module App::example::default exists, it is loaded automatically without explicit indication. The default module can be used just like a startup RC file.
METHODS
- configure name => value, ...
-
- RCFILE
-
Define the name of startup file.
- BASECLASS
-
Define the base class for user-defined modules. Use an array reference to specify multiple base classes; they are tried to be loaded in order.
- MODULE_OPT
-
Define the module option string. String
-Mis set by default. - DEFAULT
-
Define the default module name. The string
defaultis set by default. Set toundefif you don't want to load any default module. - PARSE_MODULE_OPT
-
Defaults to true, and parses module options given to the
deal_withmethod. When disabled, module options in command line arguments are not processed, but module options given in rc or module files are still effective. - IGNORE_NO_MODULE
-
Defaults to false, and the process dies when a given module was not found on the system. When set to true, the program ignores non-existing modules and stops parsing at that point, leaving the argument untouched.
- buckets
-
Returns the loaded Getopt::EX::Module object list.
- load_file
-
Loads the specified file.
- load_module
-
Loads the specified module.