Config::Checker - Validate configuration objects against a template
use Config::Checker; my $checker = eval config_checker_source; die $@ if $@; my $prototype_config = 'YAML stuff'; my $config = YAML::Load($config_file); eval { $checker->($config, $prototype_config); } print "invalid config: $@" if $@;
Config::Checker provides a method for verifying configuration data against a prototype. The prototype is either a perl object or is a YAML string.
The prototype is structured the same as the configuration file (assuming the configuration data is specified in YAML). Hashes are hashes, arrays are arrays, etc. Arrays of hashes should have just one record in the prototype. That one record will be matched against all the records in the configuration.
Most things are a hash and organized as KEY: VALUE pairs.
The key and value should both be descriptive. Additionaly, keys and values can have a type specified, code executed, or a quantity specified.
All keys are considered manditory unless the quantity specifier says otherwise.
[TYPE]
Keys and values can be followed with a [TYPE] signifier. The TYPES that are currently tested against are: [HOSTNAME], [DATE], [CODE], [INTEGER], [SIZE], [MODULE_NAME] and [PATH].
[HOSTNAME]
[DATE]
[CODE]
[INTEGER]
[SIZE]
[MODULE_NAME]
[PATH]
{code}
Keys and values can be followed with a {code} block. The code is executed. Unless it returns a true value, the configuration is deemed invalid. To precisely control the error message, the code can set the variable $error. For example:
$error
format: 'record format for this source{valid_parser($_[0]) or $error = "invalid parser: <$_[0]> at $context"}'
When there is both a [TYPE] and a {code} specifier, the [TYPE] comes first.
Values may specifiy a quantity. The quantity is pre-pended to the description:
source: '+name of input the data[TEXT]'
The quantity specifiers are:
+
One or more of these are required. If there is more than one, they should be in an array. If there is just one and it's not in an array, it will be put into one.
If there is a list separator, and there is only one item, then that one item will be split up with the list separator and whitespace cleaned.
*
Zero or more of these are allowed. If there is exactly one and it's not an array, it will be put into an array.
%
This value should be a hash that is not validated.
?
The item is optional.
?ltdefault valuegt
lt
gt
The item is optional in the configuration, but if it not specified a default value will be supplied.
temporary_storage: '?</tmp>Where to keep tmp files[PATH]'
This package may be used and redistributed under the terms of either the Artistic 2.0 or LGPL 2.1 license.
To install Config::Checker, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Config::Checker
CPAN shell
perl -MCPAN -e shell install Config::Checker
For more information on module installation, please visit the detailed CPAN module installation guide.