Andrew Sterling Hanenkamp > Data-Rx-TypeBundle-Rx-0.103520 > Data::Rx::TypeBundle::Rx

Download:
Data-Rx-TypeBundle-Rx-0.103520.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.103520   Source  

NAME ^

Data::Rx::TypeBundle::Rx - Build types from Data::Rx schema (experimental)

VERSION ^

version 0.103520

SYNOPSIS ^

  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

DESCRIPTION ^

This provides tools for creating Data::Rx type definitions. This is really just a way for creating reusable type aliases.

METHODS ^

new

  my $type_library = Data::Rx::TypeBundle::Rx->new;

Constructs a new type library object.

register_type

  $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_plugins

Used by Data::Rx. Returns all of the Data::Rx::Type::Rx type plugins that have been registered.

CAVEATS ^

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.

AUTHOR ^

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE ^

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.

syntax highlighting: