NAME
Data::Verify - versatile data/type verification, validation and testing
SYNOPSIS
use Data::Verify qw(:all); use Error qw(:try);
# EMAIL, URI, IPV4 are standard types
try
{
verify( $cgi->param( 'email' ), EMAIL );
verify( $cgi->param( 'homepage' ) , URI('http') );
verify( $cgi->param( 'serverip' ) , IPV4 );
}
catch Type::Exception with
{
printf "Expected '%s' %s at %s line %s\n", $_->value, $_->type->info, $_->was_file, $_->was_line foreach @_;
};
DESCRIPTION
This module supports 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. It doesnt support casting (yet).
KEYWORDS
data types, data manipulation, data patterns, user input, tie
TYPES
Data::Verify 0.01_13 supports 26 types:
BOOL - a true or false value
EMAIL - an email address
GENDER - a gender (male|female)
INT - an integer
IPV4 - an IPv4 network address
MYSQL_BLOB - a 'blob' or 'text' with a max length of 65535 (2^16 - 1) cha..
MYSQL_DATE - a date
MYSQL_DATETIME - a date and time combination
MYSQL_ENUM - a member of an enumeration
MYSQL_LONGBLOB - a 'blob' or 'text' with a max length of 4294967295 (2^32 - 1..
MYSQL_LONGTEXT - a 'blob' or 'text' with a max length of 4294967295 (2^32 - 1..
MYSQL_MEDIUMBLOB - a 'blob' or 'text' with a max length of 16777215 (2^24 - 1) ..
MYSQL_MEDIUMTEXT - a 'blob' or 'text' with a max length of 16777215 (2^24 - 1) ..
MYSQL_SET - a set
MYSQL_TEXT - a 'blob' or 'text' with a max length of 65535 (2^16 - 1) cha..
MYSQL_TIME - a time
MYSQL_TIMESTAMP - a timestamp
MYSQL_TINYBLOB - a 'blob' or 'text' with a max length of 255 (2^8 - 1) charac..
MYSQL_TINYTEXT - a 'blob' or 'text' with a max length of 255 (2^8 - 1) charac..
MYSQL_YEAR - a year in 2- or 4-digit format
NUM - a number
QUOTED - a quoted string
REAL - a real
URI - an http uri
VARCHAR - a string with limited length of choice (default 60)
WORD - a word (without spaces)
NUMERIC TYPES
INT, NUM, REAL
DATE AND TIME TYPES
MYSQL_DATE, MYSQL_DATETIME, MYSQL_TIME, MYSQL_TIMESTAMP, MYSQL_YEAR
STRING (CHARACTERS) TYPES
EMAIL, GENDER, IPV4, MYSQL_BLOB, MYSQL_LONGBLOB, MYSQL_LONGTEXT, MYSQL_MEDIUMBLOB, MYSQL_MEDIUMTEXT, MYSQL_TEXT, MYSQL_TINYBLOB, MYSQL_TINYTEXT, QUOTED, URI, VARCHAR, WORD
OTHER TYPES
MYSQL_ENUM, MYSQL_SET
INTERFACE
FUNCTIONS
verify( $teststring, $type, [ .. ] ) - Verifies a 'value' against a 'type'.
Example
see SYNOPSIS.
TYPE BINDING
typ/untyp/istyp
Example
try { typ MYSQL_ENUM( qw(Murat mo muri) ), \( my $alias );
$alias = 'Murat';
$alias = 'mo';
$alias = 'XXX';
}
catch Type::Exception ::with
{
printf "Expected '%s' %s at %s line %s\n", $_->value, $_->type->info, $_->was_file, $_->was_line foreach @_;
};
Exceptions
Exceptions are implemented via the 'Error' module.
Type::Exception
This is a base class inheriting 'Error'.
Failure::Type
Is a 'Type::Exception' and has following additional members:
bool:
expected - reserved for future use
returned - reserved for future use
string:
was_file - the filename where the exception was thrown
int:
was_line - the line number
ref:
type - the type 'object' used for verification
value - a reference to the data given for verification against the type
Failure::Function (Internal use only)
This exception is thrown in the verification process if a Function (which is a subelement of the verification process) fails.
Is a 'Type::Exception' and has following additional members.
bool:
expected - reserved for future use
returned - reserved for future use
ref:
type - the type 'object' used for verification
Retrieving Type Information
catalog()
returns a static string containing a listing of all know types (and a short information). This may be used to get an overview via:
perl -e "use Data::Verify qw(:all); print catalog()"
testplan( $type )
Returns the entry-objects how the type is verified. This may be used to create a textual description how a type is verified.
foreach my $entry ( testplan( $type ) )
{
printf "\texpecting it %s %s ", $entry->[1] ? 'is' : 'is NOT', strlimit( $entry->[0]->info() );
}
EXPORT
all = (typ untyp istyp verify catalog testplan), map { uc } @types
None by default.
AUTHOR
Murat Ünalan, <murat.uenalan@cpan.org>
SEE ALSO
Data::Types, String::Checker, Regexp::Common, Data::FormValidator, HTML::FormValidator, CGI::FormMagick::Validator, CGI::Validate, Email::Valid, Email::Valid::Loose, Embperl::Form::Validate, Attribute::Types
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 1402:
Non-ASCII character seen before =encoding in 'Ünalan,'. Assuming CP1252