Data::Schema::Manual::TypeHandler
version 0.134
This document explains how to write type handler using Perl.
Data::Schema::Manual::TypeHandler - Writing type handler for Data::Schema
Type handler allows DS to recognize and validate a new type.
Any object can become a type handler as long as it satisfies these requirements:
1. It has a validator([$validator]) method to retrieve/set the validator property.
2. It has cmp() method.
2. Define handle_pre_check_attrs() method.
3. Define handle_type() method.
4. Define zero or more handle_attr_*() methods.
It is usually more convenient to subclass from Data::Schema::Type::Base so you are relieved from many of these tasks, unless you are creating some exotic type. With Data::Schema::Type::Base, you usually need to override handle_pre_check_attrs() and write some handle_attr_*() methods.
Called by DST::Base's various handle_attr_*() methods to allow subclass to provide comparison function. Should return -1, 0, 1 a la Perl's cmp() or undef if comparison is undefined for the type.
Called by DST::Base's handle_type() to give a chance to subclass to inspect the data whether its value is acceptable for the type.
Called by the validator's _validate() method. $attr_hashes is an arrayref of attribute hash. Each attribute hash is a mapping attribute name and values.
Should return 1 when succesful or 0 if fails. If there are errors, please log them using $validator->data_error().;
This is called by DST::Base's handle_type() when encountering type attribute of name=NAME in the attribute hashes. This makes it convenient to support new attribute, by just adding a method with the appropriate name.
To use your new type, register it via:
$validator->register_type('Your::Class');
or
$validator->register_type($your_obj);
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.