NAME

Config::Checker - Validate configuration objects against a template

SYNOPSIS

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 $@;

DESCRIPTION

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].

{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:

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.

Quantity

Values may specifiy a quantity. The quantity is pre-pended to the description:

source: '+name of input the data[TEXT]'

The quantity specifiers are:

+(list separator)

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.

*(list separator)

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.

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.

%

This value should be a hash that is not validated.

?

The item is optional.

?ltdefault valuegt

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]'

LICENSE

This package may be used and redistributed under the terms of either the Artistic 2.0 or LGPL 2.1 license.