The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

SYNOPSIS

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

  ...

   sub _test
   {
     my $this = shift;

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

DESCRIPTION

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.

EXCEPTIONS

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

FACETS

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

  Data::Type::Facet::ref();
  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.

Data::Type::Facet::is()

Expects an exact match (==).

Data::Type::Facet::defined()

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

Data::Type::Facet::null()

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.

Data::Type::Facet::mod10check()

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

CONTACT

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.

AUTHOR

Murat Uenalan, <muenalan@cpan.org>