Data::Schema::Type::Scalar - Role for scalar types
version 0.136
use Data::Schema;
This is the role for scalar types. It provides attributes like 'deps'. Lots of types are scalars, e.g. num, str, etc.
Role consumer is not required to provide any method.
Aliases: dep
If data matches SCHEMA1, then data must also match SCHEMA2.
This is not unlike an if-elsif statement.
See also Data::Schema::Type::Either where you can also write attribute 'of' => [SCHEMA1, SCHEMA1B, ...]. But the disadvantage of the 'of' attribute of 'either' type is it does not report validation error details for SCHEMA2, SCHEMA2B, etc. It just report that data does not match any of SCHEMA1/SCHEMA1B/...
Example (in YAML):
- either - set: 1 of: [str, array, hash] deps: - [str, [str, {one_of: [str, string, int, float, ...]}]] - [array, [array, {minlen: 2, ...}]] - [hash, [hash, {keys: {type: ..., def: ..., attr_hashes: ...}}]]
The above YAML snippet is actually from DS schema. A schema can be str (first form), array (second form), or hash (third form). For each form, we define further validation in the 'deps' attribute. If we write the above schema like this instead:
- either - set: 1 of: - [str, {one_of: [str, string, int, float, ...]}] - [array, {minlen: 2, ...}] - [hash, {keys: {type: ..., def: ..., attr_hashes: ...}}]
Then whenever there's a validation failure somewhere, the error details will be hidden because the final error will just be from 'either's 'of' attribute: that none of the alternatives matches.
Steven Haryanto <stevenharyanto@gmail.com>
This software is copyright (c) 2009 by Steven Haryanto.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Data::Schema, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Schema
CPAN shell
perl -MCPAN -e shell install Data::Schema
For more information on module installation, please visit the detailed CPAN module installation guide.