Data::Schema::Type::Base - Base class for Data::Schema type handler
version 0.136
use Data::Schema;
This is the base class for all type handlers. Normally you wouldn't use this type but one of its subclasses.
This method is called by handle_type() before checking type attributes. It should return true if checking passes or false if checking fails. By default it does nothing but returns true. Override this method if you want to add additional checking.
handle_type()
Return attribute keys in execute order. Some type might need some attributes to be executed first (because they have some side-effect, etc), e.g. DST::Hash overrides this to put 'allow_extra_keys' first, because later 'keys' needs to know the state of 'allow_extra_keys'.
Otherwise, you can just return the keys in any/default order (the default implementation).
Check data against type (and all type attributes). Returns 1 if success, 0 if fails. You normally do not need to override this method. This method is called by the validator (Data::Schema object).
Also handle the 'required' and 'forbidden' (and their alias: 'set') attributes, these are special so they're handled here. All the other attributes are handled using 'handle_attr_XXX' methods.
Show an English representation of this data type.
Attributes that are handled by the Base:
Aliases: set=>1
If set to 1, require that data be defined. Otherwise, allow undef (the default behaviour).
By default, undef will pass even elaborate schema:
ds_validate(undef, "int"); # valid ds_validate(undef, [int => {min=>0, max=>10, divisible_by=>3}]); # valid!
However:
ds_validate(undef, [int=>{required=>1}]); # invalid
This behaviour's rationale is much like NULLs in SQL: we *can't* validate something that is unknown/unset.
Aliases: set=>0
This is the opposite of required, requiring that data be not defined (i.e. undef).
ds_validate(1, [int=>{forbidden=>1}]); # invalid ds_validate(undef, [int=>{forbidden=>1}]); # valid
Alias for required or forbidden. set=>1 equals required=>1, while set=>0 equals forbidden=>1.
Supply a default value.
ds_validate(undef, [int => {required=>1}]); # invalid, data undefined ds_validate(undef, [int => {required=>1, default=>3}]); # valid
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.