++ed by:

1 PAUSE user(s)

Murat √únalan


Data::Type::Facet - a subelement of a type


  package Data::Type::Object::std_real;


   sub _test
     my $this = shift;

       Data::Type::ok( 1, Data::Type::Facet::match( 'std/real' ) );


Facets are bric's for Data::Type::Object's. They are partially almost trivial (more or less), but have some advantages. They are modularising the testing procedure of any datatype (and therefore giving the magic to the "summary()" in Data::Type function.


Data::Type::Facet::Exception is thrown by any facet to indicate Data::Type that it failed to pass.


Data::Type::Facet::ref( type )

  Data::Type::Facet::ref( 'ARRAY' );  # 'HASH' | 'CODE' | ..

Whether the value is a reference. If type is given, this explicit reference is required. So if $Data::Type::value = [ 1, 2 ] then

  ok( 1, Data::Type::Facet::ref( 'ARRAY' ) );

would pass. While

  ok( 1, Data::Type::Facet::ref( 'HASH' ) );

would of course not.

Data::Type::Facet::range( x, y )

  Data::Type::Facet::range( 1, 10 )

Value is numerically between the lower value x and upper limit value y (including them).

Data::Type::Facet::lines( min )

Counts the newlines \n in a textblock. Expects more then min lines (newlines).

Data::Type::Facet::less( min )

Counts the length() of a string and expects less than min.

Data::Type::Facet::max( limit )

Expects numbers under the limit (< limit).

Data::Type::Facet::min( limit )

Expects numbers above limit (> limit).

Data::Type::Facet::match( boxid )

  Data::Type::Facet::match( 'std/word' );

Please visit "CONVENTIONS" in Data::Type::Docs::RFC and Regexp::Box for details registering regexps. All regexps used by Data::Type are stored within the central registry $Data::Type::rebox (Regexp::Box). The boxid must be therefore e prior registered to $Data::Type::rebox. The already stored one can be retrieven with Data::Type::Query.


Expects an exact match (==).


Expects a defined value (as perl's defined()).


Expects not literally 'NULL'. Its test eq 'NULL'.

Data::Type::Facet::bool( 'true' | 'false' )

  Data::Type::Facet::bool( 'true' );

Expects true or false boolean value.

Data::Type::Facet::exists( key | element )

This function expects array elements with an array or a hash key within a hash, dependant on the given $Data::Type::value.


Expects a number (mostly a credit-card number) to pass the mod10 LUHN algorithm check.


Sourceforge http://sf.net/projects/datatype is hosting a project dedicated to this module. And I enjoy receiving your comments/suggestion/reports also via http://rt.cpan.org or http://testers.cpan.org.


Murat Uenalan, <muenalan@cpan.org>