Data::Rx::TypeBundle::Rx - Build types from Data::Rx schema (experimental)
version 0.103520
use Data::Rx; use Data::Rx::TypeBundle::Rx; my $custom_type_library = Data::Rx::TypeBundle::Rx->new; $custom_type_library->register_type('tag:example.com:rx/pos', { type => '//num', range => { 'min-ex' => 0 }, }); $custom_type_library->register_type('tag:example.com:rx/neg', { type => '//num', range => { 'max-ex' => 0 }, }); my $rx = Data::Rx->new({ prefix => { ext => 'tag:example.com:rx/' }, type_plugins => [ $custom_type_lib ], }); my $pos_checker = $rx->make_schema({ type => '/ext/pos' }); $pos_checker->check(10); # OK $pos_checker->check(0); # NOT OK $pos_checker->check(-10); # NOT OK my $neg_checker = $rx->make_schema({ type => '/ext/neg' }); $neg_checker->check(10); # NOT OK $neg_checker->check(0); # NOT OK $neg_checker->check(-10); # OK
This provides tools for creating Data::Rx type definitions. This is really just a way for creating reusable type aliases.
my $type_library = Data::Rx::TypeBundle::Rx->new;
Constructs a new type library object.
$type_library->register_type($type_uri, $definition);
This registers a new Rx type alias. The $type_uri should be the namespace to assign the type to and the $definition should be a Data::Rx schema definition to assign to that type.
$type_uri
$definition
Used by Data::Rx. Returns all of the Data::Rx::Type::Rx type plugins that have been registered.
The one thing you do need to beware of is that all of your types need to be registered before passing this object off to Data::Rx. Any types registered after passing this object to the Data::Rx constructor or "register_type_plugin" in Data::Rx method will not be known to Data::Rx.
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
This software is copyright (c) 2010 by Qubling Software LLC.
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::Rx::TypeBundle::Rx, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Rx::TypeBundle::Rx
CPAN shell
perl -MCPAN -e shell install Data::Rx::TypeBundle::Rx
For more information on module installation, please visit the detailed CPAN module installation guide.