Config-Validate
view release on metacpan or search on metacpan
my $result = $obj->validate(config => $config)
If it is called as a function, then it accepts two parameters. The
"config" parameter should be the data structure/config to be validated,
and the "schema" parameter should be the schema.
my $result = validate(config => $config, schema => $schema)
The "config" parameter above can be a hash reference, or it can be a
"Config::General" object. If it is a "Config::General" object, then the
validate sub will automatically call the "getall" method on the object.
If any errors are encountered, then the validate sub will call die to
throw an exception. In that case the value of $@ contain an error
message describing the problem.
There was formerly a one and two argument variant of this sub. It is
still supported, but deprecated.
add_type
The "add_type" method allows you to register a validation type on just a
single instance of "Config::Validate". The parameters are as follows:
* name This is the name to be specified in the schema to use this
validation type. This is a mandatory parameter.
* validate
The value of "validate" should be a callback that will be run
when it is necessary to validate a field of this type. The
callback will be passed the "Config::Validate" object, the name
of the field being validated, the schema definition of that
field, and an array reference containing the path into the data
structure. You can use the "mkpath" method to convert the path
to a more readable form for error messages and such.
* init The value of "init" should be a callback that will be run before
any validation is done. The callback will be passed the
"Config::Validate" object, the schema, and the configuration
being validated.
* finish
The value of "finish" should be a callback that will be run
after any validation is done. The callback will be passed the
"Config::Validate" object, the schema, and the configuration
being validated.
add_default_type
The "add_default_type" method allows you to register a validation type
for all new "Config::Validate" instances. It can be called as a
function, class method, or instance method. If it is called as an
instance method, then the new type will also be added to that instance.
The parameters are the same as "add_type".
reset_default_types
The "reset_default_types" method removes all user defined types from the
base class. Any instances that are alread created will retain their
existing type configuration.
mkpath
This is a convenience function for people writing callbacks and user
defined type validation. It takes either an array or array reference and
returns a string that represents the path to a specific item in the
configuration. This might be useful if you're interested in having your
error messages be consistent with the rest of "Config::Validate". This
is available for export, but not exported by default. Note: this is a
function, not a method.
AUTHOR
Clayton O'Neill
Eval for e-mail address: "join('@', join('.', qw(cv 20 coneill)),
'xoxy.net')"
LICENSE AND COPYRIGHT
Copyright (C) 2007-2008 by Clayton O'Neill
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself, either Perl version 5.8.5 or, at
your option, any later version of Perl 5 you may have available.
( run in 2.873 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )