use App::ConfigWild; $cfg = new ConfigWild; $cfg = new ConfigWild "configfile";
keyword = value
where keyword is a token which may contain Perl regular expressions surrounded by curly brackets, i.e.
foobar.{\d+}.name = goo
and value is the remainder of the line after any whitespace following the = character is removed.
Keywords which contain regular expressions are termed wildcard keywords; those without are called absolute keywords. Wildcard keywords serve as templates to allow grouping of keywords which have the same value. For instance, say you've got a set of keywords which normally have the same value, but where on occaision you'd like to override the default:
p.{\d+}.foo = goo
p.99.foo = flabber
value may reference environmental variables or other ConfigWild variables via the following expressions:
${var}:
foo = ${HOME}/foo
If the variable doesn't exist, the expression is replaced with an empty string.
$(var).
root = ${HOME}
foo = $(root)/foo
If the variable doesn't exist, the expression is replaced with an empty string. Variable expansions can be nested, as in
root = /root branch = $(root)/branch tree = $(branch)/tree
tree will evaluate to /root/branch/tree.
$var. In this case, if var is not a ConfigWild variable, it is assumed to be and environmental variable. If the variable
doesn't exist, the expression is left as is.
Lines which begin with the # character are ignored. There is also a set of directives which alter the
where and how ConfigWild reads configuration information. Each directive begins with the % character and appears alone on a line in the config file:
undef upon error.
It returns 1 upon success, undef if an error ocurred. The error message may be retrieved with the errmsg method.
undef and sets the objects error message (see errmsg()).
For example,
die( $cfg->errmsg, "\n" )
if $cfg->load_cmd( \@ARGV, { Exists => 1} );
undef is returned.
$keyword from the list of keywords (either absolute or wild) stored in the object.
The keyword must be an exact match. It is not an error to delete a keyword
which doesn't exist.
undef if not.
undef and sets the object's error message upon error. The available parameters
are:
For example,
$cfg = new ConfigWild "foo.cnf";
$cfg->set_attr( { UNDEF => \&undefined_keyword } );
sub undefined_keyword
{
my $keyword = shift;
return 33;
}
You may also use this to centralize error messages:
sub undefined_keyword
{
my $keyword = shift;
die("undefined keyword requested: $keyword\n");
}
To reset this to the default behavior, set UNDEF to undef.
$foo = $cfg->value( 'keyword' ); $foo = $cfg->keyword;
If keyword doesn't exist, it returns undef.
Similarly, you can set a keyword's value using a similar syntax. The following are equivalent, if the keyword already exists:
$cfg->set( 'keyword', $value ); $cfg->keyword( $value );
If the keyword doesn't exist, the second statement does nothing.
It is a bit more time consuming to use these methods rather than using set and value.
This package was heavily influenced by App::Config by Andy Wardley.