Provides a configuration file and command line parser for a tree-oriented configuration environment.
A global instance of the libapt-pkg _config instance is provided as $AptPkg::Config::_config, and may be imported.
The following methods are implemented:
If the key ends in ::, an array of values is returned in an array context, or a string containing the values seperated by spaces in a scalar context.
A trailing /f, /d, /b or /i causes file, directory, boolean or integer interpretation (the underlying XS call is FindAny).
For example, given the configuration file:
foo "/some/dir/" { bar "value"; }
then:
$conf->get("foo::bar") # "value" $conf->get_file("foo::bar") # "/some/dir/value" $conf->get_dir("foo::bar") # "/some/dir/value/"
1 yes true with on enable
otherwise false ('').
If the AS_SECTIONAL argument is true, then the file is parsed as a BIND-style config. That is:
foo "bar" { baz "quux"; }
is interpreted as if it were:
foo::bar { baz "quux"; }
The DEPTH argument may be used to restrict the number of nested include directives processed.
Note, the function does not return if there are errors processing the args. Use eval to trap such errors.
DEFS is a reference to an array containing a set argument definition arrays. The elements of each definition define: the short argument character, the long argument string, the configuration key and the optional argument type (defaults to Boolean).
Valid argument types are defined by the strings:
HasArg takes an argument value (-f foo) IntLevel defines an integer value (-q -q, -qq, -q2, -q=2) Boolean true/false (-d, -d=true, -d=yes, --no-d, -d=false, etc) InvBoolean same as Boolean but false with no specified sense (-d) ConfigFile load the specified configuration file ArbItem arbitary configuration string of the form key=value
The configuration key in the last two cases is ignored, and for the rest gives the key into which the value is placed.
Single case equivalents also work (has_arg == HasArg).
Example:
@files = $conf->parse_cmndline([ [ 'h', 'help', 'help' ], [ 'v', 'version', 'version' ], [ 'c', 'config-file', '', ConfigFile ], [ 'o', 'option', '', ArbItem ], ], @ARGV);
The module uses AptPkg::hash to provide a hash-like access to the object, so that $conf->{key} is equivalent to using the get/set methods.
Additionally inherits the constructor (new) and keys methods from that module.
Methods of the internal XS object (AptPkg::_config) such as Find may also be used. See AptPkg.