The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::Schema::Type::Scalar - Role for scalar types

VERSION

version 0.136

SYNOPSIS

    use Data::Schema;

DESCRIPTION

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.

TYPE ATTRIBUTES

deps => [[SCHEMA1, SCHEMA2], [SCHEMA1B, SCHEMA2B], ...]

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.

AUTHOR

  Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

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.