Data::Type 0.01.04 review

Download
by rbytes.net on

Data::Type is a Perl module with versatile data and value types. SYNOPSIS use Data::Type qw(:all); use Error q

License: Perl Artistic License
File size: 22K
Developer: Murat ?nalan
0 stars award from rbytes.net

Data::Type is a Perl module with versatile data and value types.

SYNOPSIS

use Data::Type qw(:all);
use Error qw(:try);

try
{
verify $email , EMAIL;
verify $homepage , URI('http');
verify $cc , CREDITCARD( 'MASTERCARD', 'VISA' );
verify $answer_a , YESNO;
verify $gender , GENDER;
verify 'one' , ENUM( qw(one two three) );
verify [qw(two six)], SET( qw(one two three four five six) ) );
verify $server_ip4 , IP('v4');
verify $server_ip6 , IP('v6');

verify 'A35231AH1' , CINS;
verify '14565935' , ISSN;
verify 'DE' , LANGCODE;
verify 'German' , LANGNAME;

verify '012345678905', UPC();
verify '5276440065421319', CREDITCARD( 'MASTERCARD' ) );

verify 'ATGCAAAT' , BIO::DNA;
verify 'AUGGGAAAU' , BIO::RNA;

verify '01001001110110101', BINARY;
verify '0F 0C 0A', HEX;

verify '0' , DEFINED;
verify '234' , NUM( 20 );
verify '1' , BOOL( 'true' );
verify '100' , INT;
verify '1.1' , REAL;

my $foo = bless( '123', 'SomeThing' );

verify $foo , REF;
verify $foo , REF( qw(SomeThing Else) );
verify [ 'bar' ] , REF( 'ARRAY' );

verify ' ' x 20 , VARCHAR( 20 );
verify '2001-01-01' , DATE( 'MYSQL' );
verify '16 Nov 94 22:28:20 PST' , DATE( 'DATEPARSE' );
verify '9999-12-31 23:59:59', DATETIME;
verify '1970-01-01 00:00:00', TIMESTAMP;
verify '-838:59:59' , TIME;
verify '2155' , YEAR;
verify '69' , YEAR(2);
verify '0' x 20 , TINYTEXT;
verify '0' x 20 , MEDIUMTEXT;
verify '0' x 20 , LONGTEXT;
verify '0' x 20 , TEXT;

verify '80' , PORT;
verify 'www.cpan.org', DOMAIN;
}
catch Type::Exception with
{
my $e = shift;

printf "Expected '%s' %s at %s line %sn",
$e->value,
$e->type->info,
$e->was_file,
$e->was_line;

foreach my $entry ( testplan( $e->type ) )
{
printf "texpecting it %s %s ", $entry->[1] ? 'is' : 'is NOT', $entry->[0]->info();
}
};

# believe it or not, this really works

foreach ( EMAIL, WORD, CREDITCARD( 'MASTERCARD', 'VISA' ), BIO::DNA, HEX )
{
print $_->info;
print $_->usage;
print $_->export; # does it have other names
print $_->param; # what are my choice i.e. [yes,no]
print $_->isa( 'IType::Business' ); # is it a Business related type ?
print $_->VERSION; # first apperance in Data::Type release
}

# tied interface (alias 'typ')

try
{
typ ENUM( qw(DNA RNA) ), ( my $a, my $b );

print "a is typ'ed" if istyp( $a );

$a = 'DNA'; # $alias only accepts 'DNA' or 'RNA'
$a = 'RNA';
$a = 'xNA'; # throws exception

untyp( $alias );
}
catch Type::Exception ::with
{
printf "Expected '%s' %s at %s line %sn",
$e->value,
$e->type->info,
$e->was_file,
$e->was_line;
};

dverify( $email, EMAIL ) or die $!;

my $g = Data::Type::Guard->new(

allow => [ 'Human', 'Others' ], # blessed objects of that type

tests =>
{
email => EMAIL( 1 ), # mxcheck ON ! see Email::Valid
firstname => WORD,
social_id => [ NUM, VARCHAR( 10 ) ],
contacts => sub { my %args = @_; exists $args{lucy} },
}
);

$g->inspect( $h );

# compact version

overify { email => EMAIL( 1 ), firstname => WORD }, $object_a, $object_b;

print toc();

print catalog();

This module supports versatile data and value types. Out of the ordinary it supports parameterised types (like databases have i.e. VARCHAR(80) ). When you try to feed a typed variable against some odd data, this module explains what he would have expected.

Requirements:
Perl

Data::Type 0.01.04 keywords