Data-Processor
view release on metacpan or search on metacpan
my $error_collection = $p->validate($data, verbose=>0);
# no errors :-)
# in case of errors:
# ------------------
# print each error on one line.
say $error_collection;
# same
for my $e ($error_collection->as_array){
say $e;
# do more..
}
DESCRIPTION
Data::Processor is a tool for transforming, verifying, and producing
Perl data structures from / against a schema, defined as a Perl data
structure.
METHODS
new
my $processor = Data::Processor->new($schema);
optional parameters: - indent: count of spaces to insert when printing
in verbose mode. Default 4 - depth: level at which to start. Default is
0. - verbose: Set to a true value to print messages during processing.
validate Validate the data against a schema. The schema either needs to be
present already or be passed as an argument.
my $error_collection = $processor->validate($data, verbose=>0);
validate_schema
check that the schema is valid. This method gets called upon creation
of a new Data::Processor object.
my $error_collection = $processor->validate_schema();
merge_schema
merges another schema into the schema (optionally at a specific node)
my $error_collection = $processor->merge_schema($schema_2);
merging rules: - merging transformers will result in an error - merge
checks if all merged elements match existing elements - non existing
elements will be added from merging schema - validators from existing
and merging schema get combined
schema
Returns the schema. Useful after schema merging.
transform_data
Transform one key in the data according to rules specified as callbacks
that themodule calls for you. Transforms the data in-place.
my $validator = Data::Processor::Validator->new($schema, data => $data)
my $error_string = $processor->transform($key, $schema_key, $value);
This is not tremendously useful at the moment, especially because
validate() transforms during validation.
make_data
Writes a data template using the information found in the schema.
my $data = $processor->make_data(data=>$data);
make_pod
Write descriptive pod from the schema.
my $pod_string = $processor->make_pod();
SCHEMA REFERENCE
Top-level keys and members
The schema is described by a nested hash. At the top level, and within
a members definition, the keys are the same as the structure you are
describing. So for example:
my $schema = {
coordinates => {
members => {
x => {
description => "the x coordinate",
},
y => {
description => "the y coordinate",
},
}
}
};
This schema describes a structure which might look like this:
{ coordinates => { x => 1, y => 2} }
Obviously this can be nested all the way down:
my $schema = {
house => {
members => {
bungalow => {
members => {
rooms => {
#...
}
}
}
}
}
};
( run in 0.546 second using v1.01-cache-2.11-cpan-39bf76dae61 )