NAME

Data::Sah::Manual::Extending - Extending Data::Sah

VERSION

This document describes version 0.26 of module Data::Sah::Manual::Extending (in distribution Data-Sah), released on 2014-04-28.

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.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Data-Sah.

SOURCE

Source repository is at https://github.com/sharyanto/perl-Data-Sah.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Sah

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 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.