NAME

Config::General::Validate - Validate Config::General Configs

SYNOPSIS

use Config::General::Validate;

my $validator = new Config::General::Validate($reference);

if ( $validator->validate($config_general_object) ) {
  print "valid\n";
}
else {
  print "invalid\n";
}

if ( $validator->validate($config_hash_reference) ) {
  print "valid\n";
}
else {
  print "invalid\n";
}

DESCRIPTION

This module validates a config parsed by Config::General against a given hash structure.

The following data types can be used:

int  - an integer
word - a single word
line - a line of text
text - a whole text(blob) including newlines.

Example validator structure:

$reference = { user => 'word', uid => 'int' };

The following config would be validated successful:

$config = { user => 'HansDampf',  uid => 92 };

this one not:

$config = { user => 'Hans Dampf', uid => 'nine' };
                         ^                ^^^^
                         |                |
                         |                +----- is not a number
                         +---------------------- space not allowed

SUBROUTINES/METHODS

validate($config)

$config can be either a normal hash reference you'd like to validate (which allows you to use the module for any hash, not only the ones generated by Config::General) or a Config::General object.

It returns a true value if the given structure looks valid.

If the return value is false (0), then the error message will be written to the variable $!.

ARRAY

Arrays must be handled in a special way, just define an array with two elements and the second empty. The config will only validated against the first element in the array.

We assume all elements in an array must have the same structure.

Example:

$reference = {
               [
                 {
                    user => 'word',
                    uid => 'int'
                 },
                 {} # empty 2nd element
               ]
              };

CONFIGURATION AND ENVIRONMENT

No environment variables will be used.

SEE ALSO

I recommend you to read the following documentations, which are supplied with perl:

perlreftut                     Perl references short introduction
perlref                        Perl references, the rest of the story
perldsc                        Perl data structures intro
perllol                        Perl data structures: arrays of arrays

Config::General::Extended      Object oriented interface to parsed configs
Config::General::Interpolated  Allows to use variables inside config files

LICENSE AND COPYRIGHT

Copyright (c) 2007 Thomas Linden

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

BUGS AND LIMITATIONS

See rt.cpan.org for current bugs, if any.

INCOMPATIBILITIES

None known.

DIAGNOSTICS

To debug Config::General::Validate use the perl debugger, see perldebug.

DEPENDENCIES

Config::General::Validate depends on the module Config::General.

AUTHOR

Thomas Linden <tlinden |AT| cpan.org>

VERSION

1.00