Steven Haryanto > Data-Schema-0.136 > Data::Schema::Manual::TypeHandler

Download:
Data-Schema-0.136.tar.gz

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Source  

NAME ^

Data::Schema::Manual::TypeHandler

VERSION ^

version 0.136

OVERVIEW ^

This document explains how to write type handler using Perl.

NAME ^

Data::Schema::Manual::TypeHandler - Writing type handler for Data::Schema

INTRODUCTION ^

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.

API ^

cmp($a, $b)

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.

handle_pre_check_attrs($data)

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.

handle_type($data, $attr_hashes)

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().;

handle_attr_NAME($data, $arg)

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.

Should return 1 when succesful or 0 if fails. If there are errors, please log them using $validator->data_error().;

USING YOUR NEW TYPE ^

To use your new type, register it via:

 $validator->register_type('Your::Class');

or

 $validator->register_type($your_obj);

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.

syntax highlighting: