NAME
Data::Sah::Manual::Extending - Extending Data::Sah
VERSION
version 0.18
DESCRIPTION
This document explains the various ways of extending Data::Sah.
ADDING A NEW CLAUSE
Example: Add an is_palindrome
clause to str
.
Create a distribution called Data-Sah-TypeX-str-is_palindrome
In lib/Data/Sah/TypeX/str/is_palindrome.pm, write:
package Data::Sah::TypeX::str::is_palindrome; use Data::Sah::Util::Compiler qw(add_clause add_translation_path); add_clause("str", "is_palindrome", definition => { }, handlers => { perl => sub { ... }, js => sub { ... }, human => sub { ... }, }, );
Provide translation of messages
For example, for Indonesian, in lib/Data/Sah/Lang/id_ID/TypeX/str/is_palindrome.pm write:
package Data::Sah::Lang::id_ID::TypeX::str::is_palindrome: ...
Add more language files as necessary.
CREATING A NEW TYPE
Example: complex number.
Create distribution Data-Sah-Type-complex
In lib/Data/Sah/Type/complex.pm write:
package Data::Sah::Type::complex; use Moo::Role; use Data::Sah::Util::Role 'has_clause'; with 'Data::Sah::Type::Comparable'; with 'Data::Sah::Type::Sortable'; ... 1;
In lib/Data/Sah/Compiler/perl/TH/complex.pm write:
XXX
In lib/Data/Sah/Compiler/js/TH/complex.pm write:
XXX
In lib/Data/Sah/Compiler/human/TH/complex.pm write:
XXX
Provide translation of messages
For example, for Indonesian, in lib/Data/Sah/Lang/id_ID/Type/complex.pm write:
package Data::Sah::Lang::id_ID::TypeX::str::is_palindrome: ...
Add more language files as necessary.
ADDING A NEW FUNCTION
XXX
CREATING A NEW FUNCTION SET
XXX
CREATING A NEW COMPILER
Take a look at one of the existing compilers like Data::Sah::Compiler::perl or Data::Sah::Compiler::human.
AUTHOR
Steven Haryanto <stevenharyanto@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 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.