Data-Validate-0.09/0000755000076400007640000000000012364755676016507 5ustar richard.sonnenrichard.sonnenData-Validate-0.09/INSTALL0000644000076400007640000000036610157427716017532 0ustar richard.sonnenrichard.sonnenINSTALLATION ============ First unpack the kit, if you have not already done so: tar -xzvf Data-Validate-x.xx.tar.gz cd Data-Validate-x.xx Data::Validate can be installed with: perl Makefile.PL make make test make install Data-Validate-0.09/Makefile.PL0000644000076400007640000000111410574644703020443 0ustar richard.sonnenrichard.sonnenuse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Data::Validate', 'VERSION_FROM' => 'Validate.pm', # finds $VERSION 'DISTNAME' => 'Data-Validate', 'AUTHOR' => 'Richard Sonnen (sonnen@richardsonnen.com)', 'PREREQ_PM' => { 'POSIX' => 0, 'Math::BigInt' => 1.77, }, 'dist' => { 'COMPRESS' => 'gzip -9f', 'SUFFIX' => 'gz', 'ZIP' => '/usr/bin/zip', 'ZIPFLAGS' => '-rl', }, ); Data-Validate-0.09/MANIFEST0000644000076400007640000000054510237722071017620 0ustar richard.sonnenrichard.sonnenChanges Makefile.PL MANIFEST INSTALL README Validate.pm t/ExtUtils/TBone.pm t/is_alphanumeric.t t/is_between.t t/is_equal_to.t t/is_even.t t/is_greater_than.t t/is_integer.t t/is_less_than.t t/is_numeric.t t/is_hex.t t/is_oct.t t/is_odd.t t/is_printable.t t/length_is_between.t META.yml Module meta-data (added by MakeMaker) Data-Validate-0.09/Validate.pm0000644000076400007640000003753412364755412020576 0ustar richard.sonnenrichard.sonnenpackage Data::Validate; use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); require Exporter; use AutoLoader 'AUTOLOAD'; use POSIX; use Scalar::Util qw(looks_like_number); use Math::BigInt; use Config; @ISA = qw(Exporter); # no functions are exported by default. See EXPORT_OK @EXPORT = qw(); @EXPORT_OK = qw( is_integer is_numeric is_hex is_oct is_between is_greater_than is_less_than is_equal_to is_even is_odd is_alphanumeric is_printable length_is_between ); %EXPORT_TAGS = ( math => [qw(is_integer is_numeric is_hex is_oct is_between is_greater_than is_less_than is_equal_to is_even is_odd)], string => [qw(is_equal_to is_alphanumeric is_printable length_is_between)], ); $VERSION = '0.09'; # No preloads 1; __END__ =head1 NAME Data::Validate - common data validation methods =head1 SYNOPSIS use Data::Validate qw(:math); if(defined(is_integer($suspect))){ print "Looks like an integer\n"; } my $name = is_alphanumeric($suspect); if(defined($name)){ print "$name is alphanumeric, and has been untainted\n"; } else { print "$suspect was not alphanumeric" } # or as an object my $v = Data::Validate->new(); die "'foo' is not an integer" unless defined($v->is_integer('foo')); =head1 DESCRIPTION This module collects common validation routines to make input validation, and untainting easier and more readable. Most of the functions are not much shorter than their direct perl equivalent (and are much longer in some cases), but their names make it clear what you're trying to test for. Almost all functions return an untainted value if the test passes, and undef if it fails. This means that you should always check for a defined status explicitly. Don't assume the return will be true. (e.g. is_integer(0)) The value to test is always the first (and often only) argument. =head1 FUNCTIONS =over 4 =cut # ------------------------------------------------------------------------------- =pod =item B - constructor for OO usage new(); =over 4 =item I Returns a Data::Validator object. This lets you access all the validator function calls as methods without importing them into your namespace or using the clumsy Data::Validate::function_name() format. =item I None =item I Returns a Data::Validate object =back =cut sub new{ my $class = shift; return bless {}, $class; } # ------------------------------------------------------------------------------- =pod =item B - is the value an integer? is_integer($value); =over 4 =item I Returns the untainted number if the test value is an integer, or can be cast to one without a loss of precision. (i.e. 1.0 is considered an integer, but 1.0001 is not.) =item I =over 4 =item $value The potential integer to test. =back =item I Returns the untainted integer on success, undef on failure. Note that the return can be 0, so always check with defined() =item I Number translation is done by POSIX casting tools (strtol). =back =cut sub is_integer{ my $self = shift if ref($_[0]); my $value = shift; return unless defined($value); return unless defined(is_numeric($value)); # for efficiency # see if we can parse it to an number without loss my($int, $leftover) = POSIX::strtod($value); return if $leftover; # we're having issues testing very large integers. Math::BigInt # can do this for us, but defeats the purpose of being # lightweight. So, we're going to try a huristic method to choose # how to test for integernesss if(!$Config{uselongdouble} && length($int) > 10){ my $i = Math::BigInt->new($value); return unless $i->is_int(); # untaint ($int) = $i->bstr() =~ /(.+)/; return $int; } # shorter integer must be identical to the raw cast return unless (($int + 0) == ($value + 0)); # could still be a float at this point. return if $value =~ /[^0-9\-]/; # looks like it really is an integer. Untaint it and return ($value) = $int =~ /([\d\-]+)/; return $value + 0; } # ------------------------------------------------------------------------------- =pod =item B - is the value numeric? is_numeric($value); =over 4 =item I Returns the untainted number if the test value is numeric according to Perl's own internal rules. (actually a wrapper on Scalar::Util::looks_like_number) =item I =over 4 =item $value The potential number to test. =back =item I Returns the untainted number on success, undef on failure. Note that the return can be 0, so always check with defined() =item I Number translation is done by POSIX casting tools (strtol). =back =cut sub is_numeric{ my $self = shift if ref($_[0]); my $value = shift; return unless defined($value); return unless looks_like_number($value); # looks like it really is a number. Untaint it and return ($value) = $value =~ /([\d\.\-+e]+)/; return $value + 0; } # ------------------------------------------------------------------------------- =pod =item B - is the value a hex number? is_hex($value); =over 4 =item I Returns the untainted number if the test value is a hex number. =item I =over 4 =item $value The potential number to test. =back =item I Returns the untainted number on success, undef on failure. Note that the return can be 0, so always check with defined() =item I None =back =cut sub is_hex { my $self = shift if ref($_[0]); my $value = shift; return unless defined $value; return if $value =~ /[^0-9a-f]/i; $value = lc($value); my $int = hex($value); return unless (defined $int); my $hex = sprintf "%x", $int; return $hex if ($hex eq $value); # handle zero stripping if (my ($z) = $value =~ /^(0+)/) { return "$z$hex" if ("$z$hex" eq $value); } return; } # ------------------------------------------------------------------------------- =pod =item B - is the value an octal number? is_oct($value); =over 4 =item I Returns the untainted number if the test value is a octal number. =item I =over 4 =item $value The potential number to test. =back =item I Returns the untainted number on success, undef on failure. Note that the return can be 0, so always check with defined() =item I None =back =cut sub is_oct { my $self = shift if ref($_[0]); my $value = shift; return unless defined $value; return if $value =~ /[^0-7]/; my $int = oct($value); return unless (defined $int); my $oct = sprintf "%o", $int; return $oct if ($oct eq $value); # handle zero stripping if (my ($z) = $value =~ /^(0+)/) { return "$z$oct" if ("$z$oct" eq $value); } return; } # ------------------------------------------------------------------------------- =pod =item B - is the value between two numbers? is_between($value, $min, $max); =over 4 =item I Returns the untainted number if the test value is numeric, and falls between $min and $max inclusive. Note that either $min or $max can be undef, which means 'unlimited'. i.e. is_between($val, 0, undef) would pass for any number zero or larger. =item I =over 4 =item $value The potential number to test. =item $min The minimum valid value. Unlimited if set to undef =item $max The maximum valid value. Unlimited if set to undef =back =item I Returns the untainted number on success, undef on failure. Note that the return can be 0, so always check with defined() =back =cut sub is_between{ my $self = shift if ref($_[0]); my $value = shift; my $min = shift; my $max = shift; # must be a number my $untainted = is_numeric($value); return unless defined($untainted); # issues with very large numbers. Fall over to using # arbitrary precisions math. if(length($value) > 10){ my $i = Math::BigInt->new($value); # minimum bound if(defined($min)){ $min = Math::BigInt->new($min); return unless $i >= $min; } # maximum bound if(defined($max)){ $max = Math::BigInt->new($max); return unless $i <= $max; } # untaint ($value) = $i->bstr() =~ /(.+)/; return $value; } # minimum bound if(defined($min)){ return unless $value >= $min; } # maximum bound if(defined($max)){ return unless $value <= $max; } return $untainted; } # ------------------------------------------------------------------------------- =pod =item B - is the value greater than a threshold? is_greater_than($value, $threshold); =over 4 =item I Returns the untainted number if the test value is numeric, and is greater than $threshold. (not inclusive) =item I =over 4 =item $value The potential number to test. =item $threshold The minimum value (non-inclusive) =back =item I Returns the untainted number on success, undef on failure. Note that the return can be 0, so always check with defined() =back =cut sub is_greater_than{ my $self = shift if ref($_[0]); my $value = shift; my $threshold = shift; # must be a number my $untainted = is_numeric($value); return unless defined($untainted); # threshold must be defined return unless defined $threshold; return unless $value > $threshold; return $untainted; } # ------------------------------------------------------------------------------- =pod =item B - is the value less than a threshold? is_less_than($value, $threshold); =over 4 =item I Returns the untainted number if the test value is numeric, and is less than $threshold. (not inclusive) =item I =over 4 =item $value The potential number to test. =item $threshold The maximum value (non-inclusive) =back =item I Returns the untainted number on success, undef on failure. Note that the return can be 0, so always check with defined() =back =cut sub is_less_than{ my $self = shift if ref($_[0]); my $value = shift; my $threshold = shift; # must be a number my $untainted = is_numeric($value); return unless defined($untainted); # threshold must be defined return unless defined $threshold; return unless $value < $threshold; return $untainted; } # ------------------------------------------------------------------------------- =pod =item B - do a string/number neutral == is_equal_to($value, $target); =over 4 =item I Returns the target if $value is equal to it. Does a math comparison if both $value and $target are numeric, or a string comparison otherwise. Both the $value and $target must be defined to get a true return. (i.e. undef != undef) =item I =over 4 =item $value The value to test. =item $target The value to test against =back =item I Unlike most validator routines, this one does not necessarily untaint its return value, it just returns $target. This has the effect of untainting if the target is a constant or other clean value. (i.e. is_equal_to($bar, 'foo')). Note that the return can be 0, so always check with defined() =back =cut sub is_equal_to{ my $self = shift if ref($_[0]); my $value = shift; my $target = shift; # value and target must be defined return unless defined $value; return unless defined $target; if(defined(is_numeric($value)) && defined(is_numeric($target))){ return $target if $value == $target; } else { # string comparison return $target if $value eq $target; } return; } # ------------------------------------------------------------------------------- =pod =item B - is a number even? is_even($value); =over 4 =item I Returns the untainted $value if it's numeric, an integer, and even. =item I =over 4 =item $value The value to test. =back =item I Returns $value (untainted). Note that the return can be 0, so always check with defined(). =back =cut sub is_even{ my $self = shift if ref($_[0]); my $value = shift; return unless defined(is_numeric($value)); my $untainted = is_integer($value); return unless defined($untainted); return $untainted unless $value % 2; return; } # ------------------------------------------------------------------------------- =pod =item B - is a number odd? is_odd($value); =over 4 =item I Returns the untainted $value if it's numeric, an integer, and odd. =item I =over 4 =item $value The value to test. =back =item I Returns $value (untainted). Note that the return can be 0, so always check with defined(). =back =cut sub is_odd{ my $self = shift if ref($_[0]); my $value = shift; return unless defined(is_numeric($value)); my $untainted = is_integer($value); return unless defined($untainted); return $untainted if $value % 2; return; } # ------------------------------------------------------------------------------- =pod =item B - does it only contain letters and numbers? is_alphanumeric($value); =over 4 =item I Returns the untainted $value if it is defined and only contains letters (upper or lower case) and numbers. Also allows an empty string - ''. =item I =over 4 =item $value The value to test. =back =item I Returns $value (untainted). Note that the return can be 0, so always check with defined(). =back =cut sub is_alphanumeric{ my $self = shift if ref($_[0]); my $value = shift; return unless defined($value); return '' if $value eq ''; # allow for empty string my($untainted) = $value =~ /([a-z0-9]+)/i; return unless defined($untainted); return unless $untainted eq $value; return $untainted; } # ------------------------------------------------------------------------------- =pod =item B - does it only contain printable characters? is_alphanumeric($value); =over 4 =item I Returns the untainted $value if it is defined and only contains printable characters as defined by the composite POSIX character class [[:print:][:space:]]. Also allows an empty string - ''. =item I =over 4 =item $value The value to test. =back =item I Returns $value (untainted). Note that the return can be 0, so always check with defined(). =back =cut sub is_printable{ my $self = shift if ref($_[0]); my $value = shift; return unless defined($value); return '' if $value eq ''; # allow for empty string my($untainted) = $value =~ /([[:print:][:space:]]+)/i; return unless defined($untainted); return unless $untainted eq $value; return $untainted; } # ------------------------------------------------------------------------------- =pod =item B - is the string length between two limits? length_is_between($value, $min, $max); =over 4 =item I Returns $value if it is defined and its length is between $min and $max inclusive. Note that this function does not untaint the value. If either $min or $max are undefined they are treated as no-limit. =item I =over 4 =item $value The value to test. =item $min The minimum length of the string (inclusive). =item $max The maximum length of the string (inclusive). =back =item I Returns $value. Note that the return can be 0, so always check with defined(). The value is not automatically untainted. =back =cut sub length_is_between{ my $self = shift if ref($_[0]); my $value = shift; my $min = shift; my $max = shift; return unless defined($value); if(defined($min)){ return unless length($value) >= $min; } if(defined($max)){ return unless length($value) <= $max; } return $value; } =pod =back =head1 AUTHOR Richard Sonnen >. =head1 COPYRIGHT Copyright (c) 2004 Richard Sonnen. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Data-Validate-0.09/META.yml0000664000076400007640000000105712364755676017765 0ustar richard.sonnenrichard.sonnen--- #YAML:1.0 name: Data-Validate version: 0.09 abstract: ~ author: - Richard Sonnen (sonnen@richardsonnen.com) license: unknown distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: ExtUtils::MakeMaker: 0 requires: Math::BigInt: 1.77 POSIX: 0 no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.55_02 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 Data-Validate-0.09/Changes0000644000076400007640000000142312364755340017766 0ustar richard.sonnenrichard.sonnenRevision history for Perl extension Data::Validate. 0.9 20140426 - Added fix for longdouble bug (RT 63213) provided by Mark Hedges 0.8 20070310 - added version prereq for Math::BigInt 0.7 20070309 - added missing prerequisite for Math::BigInt 0.06 20060723 - started converting some numeric functions to handle very large integers. 0.05 20060419 - Fixed a typo in the synopsis documentation. Thanks to Peter Beckman for spotting it. 0.04 20050509 - added is_hex and is_oct functions provided by Neil Neely (neil@frii.com) 0.03 20041222 - fixed overflow bug in is_integer() that was causing it to fail on long (but valid) integers. 0.02 20041213 - added OO interface and updated tests 0.01 Fri Nov 5 15:48:26 2004 - original version; created by h2xs 1.19 Data-Validate-0.09/README0000644000076400007640000002274210237722004017346 0ustar richard.sonnenrichard.sonnenNAME Data::Validate - common data validation methods SYNOPSIS use Data::Validate wq(:math); if(defined(is_integer($suspect))){ print "Looks like an integer\n"; } my $name = is_alphanumeric($suspect); if(defined($name)){ print "$name is alphanumeric, and has been untainted\n"; } else { print "$suspect was not alphanumeric" } # or as an object my $v = Data::Validate->new(); die "'foo' is not an integer" unless defined($v->is_integer('foo')); DESCRIPTION This module collects common validation routines to make input validation, and untainting easier and more readable. Most of the functions are not much shorter than their direct perl equivalent (and are much longer in some cases), but their names make it clear what you're trying to test for. Almost all functions return an untainted value if the test passes, and undef if it fails. This means that you should always check for a defined status explicitly. Don't assume the return will be true. (e.g. is_integer(0)) The value to test is always the first (and often only) argument. FUNCTIONS new - constructor for OO usage new(); *Description* Returns a Data::Validator object. This lets you access all the validator function calls as methods without importing them into your namespace or using the clumsy Data::Validate::function_name() format. *Arguments* None *Returns* Returns a Data::Validate object is_integer - is the value an integer? is_integer($value); *Description* Returns the untainted number if the test value is an integer, or can be cast to one without a loss of precision. (i.e. 1.0 is considered an integer, but 1.0001 is not.) *Arguments* $value The potential integer to test. *Returns* Returns the untainted integer on success, undef on failure. Note that the return can be 0, so always check with defined() *Notes, Exceptions, & Bugs* Number translation is done by POSIX casting tools (strtol). is_numeric - is the value numeric? is_numeric($value); *Description* Returns the untainted number if the test value is numeric, or can be cast to a number without a any bits being left over. (i.e. 1.0 is considered a number, 1.0hello is not.) *Arguments* $value The potential number to test. *Returns* Returns the untainted number on success, undef on failure. Note that the return can be 0, so always check with defined() *Notes, Exceptions, & Bugs* Number translation is done by POSIX casting tools (strtol). is_hex - is the value a hex number? is_hex($value); *Description* Returns the untainted number if the test value is a hex number. *Arguments* $value The potential number to test. *Returns* Returns the untainted number on success, undef on failure. Note that the return can be 0, so always check with defined() *Notes, Exceptions, & Bugs* None is_oct - is the value an octal number? is_oct($value); *Description* Returns the untainted number if the test value is a octal number. *Arguments* $value The potential number to test. *Returns* Returns the untainted number on success, undef on failure. Note that the return can be 0, so always check with defined() *Notes, Exceptions, & Bugs* None is_between - is the value between to numbers? is_between($value, $min, $max); *Description* Returns the untainted number if the test value is numeric, and falls between $min and $max inclusive. Note that either $min or $max can be undef, which means 'unlimited'. i.e. is_between($val, 0, undef) would pass for any number zero or larger. *Arguments* $value The potential number to test. $min The minimum valid value. Unlimited if set to undef $max The maximum valid value. Unlimited if set to undef *Returns* Returns the untainted number on success, undef on failure. Note that the return can be 0, so always check with defined() is_greater_than - is the value greater than a threshold? is_greater_than($value, $threshold); *Description* Returns the untainted number if the test value is numeric, and is greater than $threshold. (not inclusive) *Arguments* $value The potential number to test. $threshold The minimum value (non-inclusive) *Returns* Returns the untainted number on success, undef on failure. Note that the return can be 0, so always check with defined() is_less_than - is the value less than a threshold? is_less_than($value, $threshold); *Description* Returns the untainted number if the test value is numeric, and is less than $threshold. (not inclusive) *Arguments* $value The potential number to test. $threshold The maximum value (non-inclusive) *Returns* Returns the untainted number on success, undef on failure. Note that the return can be 0, so always check with defined() is_equal_to - do a string/number neutral == is_equal_to($value, $target); *Description* Returns the target if $value is equal to it. Does a math comparison if both $value and $target are numeric, or a string comparison otherwise. Both the $value and $target must be defined to get a true return. (i.e. undef != undef) *Arguments* $value The value to test. $target The value to test against *Returns* Unlike most validator routines, this one does not necessarily untaint its return value, it just returns $target. This has the effect of untainting if the target is a constant or other clean value. (i.e. is_equal_to($bar, 'foo')). Note that the return can be 0, so always check with defined() is_even - is a number even? is_even($value); *Description* Returns the untainted $value if it's numeric, an integer, and even. *Arguments* $value The value to test. *Returns* Returns $value (untainted). Note that the return can be 0, so always check with defined(). is_odd - is a number odd? is_odd($value); *Description* Returns the untainted $value if it's numeric, an integer, and odd. *Arguments* $value The value to test. *Returns* Returns $value (untainted). Note that the return can be 0, so always check with defined(). is_alphanumeric - does it only contain letters and numbers? is_alphanumeric($value); *Description* Returns the untainted $value if it is defined and only contains letters (upper or lower case) and numbers. Also allows an empty string - ''. *Arguments* $value The value to test. *Returns* Returns $value (untainted). Note that the return can be 0, so always check with defined(). is_printable - does it only contain printable characters? is_alphanumeric($value); *Description* Returns the untainted $value if it is defined and only contains printable characters as defined by the composite POSIX character class [[:print:][:space:]]. Also allows an empty string - ''. *Arguments* $value The value to test. *Returns* Returns $value (untainted). Note that the return can be 0, so always check with defined(). length_is_between - is the string length between two limits? length_is_between($value, $min, $max); *Description* Returns $value if it is defined and its length is between $min and $max inclusive. Note that this function does not untaint the value. If either $min or $max are undefined they are treated as no-limit. *Arguments* $value The value to test. $min The minimum length of the string (inclusive). $max The maximum length of the string (inclusive). *Returns* Returns $value. Note that the return can be 0, so always check with defined(). The value is not automatically untainted. AUTHOR Richard Sonnen . COPYRIGHT Copyright (c) 2004 Richard Sonnen. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Data-Validate-0.09/t/0000755000076400007640000000000012364755676016752 5ustar richard.sonnenrichard.sonnenData-Validate-0.09/t/is_greater_than.t0000644000076400007640000000200510157355301022245 0ustar richard.sonnenrichard.sonnen#!/usr/bin/perl # ------------------------------------------------------------------------------- # test harness for Data::Validate::is_greater_than # # Author: Richard Sonnen (http://www.richardsonnen.com/) # ------------------------------------------------------------------------------- use lib './t'; use ExtUtils::TBone; use lib './blib'; use Data::Validate qw(is_greater_than); my $t = ExtUtils::TBone->typical(); $t->begin(6); $t->msg("testing is_greater_than..."); # normal integer $t->ok(defined(is_greater_than(5, 1)), "5 is greater than 1"); # normal float $t->ok(defined(is_greater_than(5.5, 1)), "5.5 is greater than 1"); # below bound $t->ok(!defined(is_greater_than(5, 10)), "5 is less than 10"); # non-numeric $t->ok(!defined(is_greater_than('foo', 1)), "'foo' is non-numeric"); # as an object my $v = Data::Validate->new(); $t->ok(defined($v->is_greater_than(5, 1)), "5 is greater than 1 (object)"); $t->ok(!defined($v->is_greater_than(5, 10)), "5 is less than 10 (object)"); # we're done $t->end(); Data-Validate-0.09/t/is_odd.t0000644000076400007640000000165410157356300020361 0ustar richard.sonnenrichard.sonnen#!/usr/bin/perl # ------------------------------------------------------------------------------- # test harness for Data::Validate::is_odd # # Author: Richard Sonnen (http://www.richardsonnen.com/) # ------------------------------------------------------------------------------- use lib './t'; use ExtUtils::TBone; use lib './blib'; use Data::Validate qw(is_odd); my $t = ExtUtils::TBone->typical(); $t->begin(8); $t->msg("testing is_odd..."); # integers $t->ok(!defined(is_odd(0)), "0 is even"); $t->ok(!defined(is_odd(2)), "2 is even"); $t->ok(defined(is_odd(1)), "1 is odd"); $t->ok(defined(is_odd(5)), "5 is odd"); # non-integers $t->ok(!defined(is_odd(0.1)), "0.1 is not an integer"); $t->ok(!defined(is_odd('foo')), "'foo' is not an integer"); # as an object my $v = Data::Validate->new(); $t->ok(defined($v->is_odd(1)), "1 is odd (object)"); $t->ok(!defined($v->is_odd(0)), "0 is even (object)"); # we're done $t->end(); Data-Validate-0.09/t/is_less_than.t0000644000076400007640000000175110157355444021601 0ustar richard.sonnenrichard.sonnen#!/usr/bin/perl # ------------------------------------------------------------------------------- # test harness for Data::Validate::is_less_than # # Author: Richard Sonnen (http://www.richardsonnen.com/) # ------------------------------------------------------------------------------- use lib './t'; use ExtUtils::TBone; use lib './blib'; use Data::Validate qw(is_less_than); my $t = ExtUtils::TBone->typical(); $t->begin(6); $t->msg("testing is_less_than..."); # normal integer $t->ok(defined(is_less_than(5, 10)), "5 is less than 10"); # normal float $t->ok(defined(is_less_than(5.5, 10)), "5.5 is less than 10"); # above bound $t->ok(!defined(is_less_than(5, 1)), "5 is greater than 1"); # non-numeric $t->ok(!defined(is_less_than('foo', 1)), "'foo' is non-numeric"); # as an object my $v = Data::Validate->new(); $t->ok(defined($v->is_less_than(5, 10)), "5 is less than 10 (object)"); $t->ok(!defined($v->is_less_than(5, 1)), "5 is greater than 1 (object)"); # we're done $t->end(); Data-Validate-0.09/t/is_hex.t0000644000076400007640000000215010237735135020375 0ustar richard.sonnenrichard.sonnen#!/usr/bin/perl # ------------------------------------------------------------------------------- # test harness for Data::Validate::is_hex # # Author: Richard Sonnen (http://www.richardsonnen.com/) # ------------------------------------------------------------------------------- use lib './t'; use ExtUtils::TBone; use lib './blib'; use Data::Validate qw(is_hex); my $t = ExtUtils::TBone->typical(); $t->begin(9); $t->msg("testing is_hex..."); # normal integer $t->ok(defined(is_hex(5)), "5 should pass"); # normal integer $t->ok(defined(is_hex(0)), "0 should pass"); # normal integer $t->ok(defined(is_hex('a')), "a should pass"); # normal integer $t->ok(defined(is_hex('ffffff')), "ffffff should pass"); # normal integer $t->ok(defined(is_hex('FFFFFF')), "FFFFFF should pass"); # non-numeric $t->ok(!defined(is_hex('hi')), "'hi' should fail"); # non-numeric $t->ok(!defined(is_hex('1.0hi')), "'1.0hi' should fail"); # as an object my $v = Data::Validate->new(); $t->ok(defined($v->is_hex(5)), "5 should pass (object)"); $t->ok(!defined($v->is_hex('hi')), "'hi' should fail (object)"); # we're done $t->end(); Data-Validate-0.09/t/is_oct.t0000644000076400007640000000172410237734460020404 0ustar richard.sonnenrichard.sonnen#!/usr/bin/perl # ------------------------------------------------------------------------------- # test harness for Data::Validate::is_oct # # Author: Richard Sonnen (http://www.richardsonnen.com/) # ------------------------------------------------------------------------------- use lib './t'; use ExtUtils::TBone; use lib './blib'; use Data::Validate qw(is_oct); my $t = ExtUtils::TBone->typical(); $t->begin(7); $t->msg("testing is_oct..."); # normal integer $t->ok(defined(is_oct(5)), "5 should pass"); # normal integer $t->ok(defined(is_oct(0)), "0 should pass"); # normal integer $t->ok(defined(is_oct('777777')), "777777 should pass"); # non-numeric $t->ok(!defined(is_oct('hi')), "'hi' should fail"); # non-numeric $t->ok(!defined(is_oct('8')), "'8' should fail"); # as an object my $v = Data::Validate->new(); $t->ok(defined($v->is_oct(5)), "5 should pass (object)"); $t->ok(!defined($v->is_oct('hi')), "'hi' should fail (object)"); # we're done $t->end(); Data-Validate-0.09/t/is_equal_to.t0000644000076400007640000000176310157355536021437 0ustar richard.sonnenrichard.sonnen#!/usr/bin/perl # ------------------------------------------------------------------------------- # test harness for Data::Validate::is_equal_to # # Author: Richard Sonnen (http://www.richardsonnen.com/) # ------------------------------------------------------------------------------- use lib './t'; use ExtUtils::TBone; use lib './blib'; use Data::Validate qw(is_equal_to); my $t = ExtUtils::TBone->typical(); $t->begin(8); $t->msg("testing is_equal_to..."); # integer $t->ok(defined(is_equal_to(5, 5)), "5 == 5"); $t->ok(!defined(is_equal_to(5, 10)), "5 != 10"); # float $t->ok(defined(is_equal_to(5.5, 5.5)), "5.5 == 5.5"); $t->ok(!defined(is_equal_to(5.5, 5.6)), "5.5 != 5.6"); # string $t->ok(defined(is_equal_to('foo', 'foo')), "foo eq foo"); $t->ok(!defined(is_equal_to('foo', 'bar')), "foo ne bar"); # as an object my $v = Data::Validate->new(); $t->ok(defined($v->is_equal_to(5, 5)), "5 == 5 (object)"); $t->ok(!defined($v->is_equal_to(5, 10)), "5 != 10 (object)"); # we're done $t->end(); Data-Validate-0.09/t/ExtUtils/0000755000076400007640000000000012364755676020533 5ustar richard.sonnenrichard.sonnenData-Validate-0.09/t/ExtUtils/TBone.pm0000444000076400007640000003044410155426114022055 0ustar richard.sonnenrichard.sonnenpackage ExtUtils::TBone; =head1 NAME ExtUtils::TBone - a "skeleton" for writing "t/*.t" test files. =head1 SYNOPSIS Include a copy of this module in your t directory (as t/ExtUtils/TBone.pm), and then write your t/*.t files like this: use lib "./t"; # to pick up a ExtUtils::TBone use ExtUtils::TBone; # Make a tester... here are 3 different alternatives: my $T = typical ExtUtils::TBone; # standard log my $T = new ExtUtils::TBone; # no log my $T = new ExtUtils::TBone "testout/Foo.tlog"; # explicit log # Begin testing, and expect 3 tests in all: $T->begin(3); # expect 3 tests $T->msg("Something for the log file"); # message for the log # Run some tests: $T->ok($this); # test 1: no real info logged $T->ok($that, # test 2: logs a comment "Is that ok, or isn't it?"); $T->ok(($this eq $that), # test 3: logs comment + vars "Do they match?", This => $this, That => $that); # That last one could have also been written... $T->ok_eq($this, $that); # does 'eq' and logs operands $T->ok_eqnum($this, $that); # does '==' and logs operands # End testing: $T->end; =head1 DESCRIPTION This module is intended for folks who release CPAN modules with "t/*.t" tests. It makes it easy for you to output syntactically correct test-output while at the same time logging all test activity to a log file. Hopefully, bug reports which include the contents of this file will be easier for you to investigate. =head1 OUTPUT =head2 Standard output Pretty much as described by C, with a special "# END" comment placed at the very end: 1..3 ok 1 not ok 2 ok 3 # END =head1 Log file A typical log file output by this module looks like this: 1..3 ** A message logged with msg(). ** Another one. 1: My first test, using test(): how'd I do? 1: ok 1 ** Yet another message. 2: My second test, using test_eq()... 2: A: The first string 2: B: The second string 2: not ok 2 3: My third test. 3: ok 3 # END Each test() is logged with the test name and results, and the test-number prefixes each line. This allows you to scan a large file easily with "grep" (or, ahem, "perl"). A blank line follows each test's record, for clarity. =head1 PUBLIC INTERFACE =cut # Globals: use strict; use vars qw($VERSION); use FileHandle; use File::Basename; # The package version, both in 1.23 style *and* usable by MakeMaker: $VERSION = substr q$Revision: 1.124 $, 10; #------------------------------ =head2 Construction =over 4 =cut #------------------------------ =item new [ARGS...] I Create a new tester. Any arguments are sent to log_open(). =cut sub new { my $self = bless { OUT =>\*STDOUT, Begin=>0, End =>0, Count=>0, }, shift; $self->log_open(@_) if @_; $self; } #------------------------------ =item typical I Create a typical tester. Use this instead of new() for most applicaitons. The directory "testout" is created for you automatically, to hold the output log file, and log_warnings() is invoked. =cut sub typical { my $class = shift; my ($tfile) = basename $0; unless (-d "testout") { mkdir "testout", 0755 or die "Couldn't create a 'testout' subdirectory: $!\n"; ### warn "$class: created 'testout' directory\n"; } my $self = $class->new($class->catfile('.', 'testout', "${tfile}log")); $self->log_warnings; $self; } #------------------------------ # DESTROY #------------------------------ # Class method, destructor. # Automatically closes the log. # sub DESTROY { $_[0]->log_close; } #------------------------------ =back =head2 Doing tests =over 4 =cut #------------------------------ =item begin NUMTESTS I Start testing. This outputs the 1..NUMTESTS line to the standard output. =cut sub begin { my ($self, $n) = @_; return if $self->{Begin}++; $self->l_print("1..$n\n\n"); print {$self->{OUT}} "1..$n\n"; } #------------------------------ =item end I Indicate the end of testing. This outputs a "# END" line to the standard output. =cut sub end { my ($self) = @_; return if $self->{End}++; $self->l_print("# END\n"); print {$self->{OUT}} "# END\n"; } #------------------------------ =item ok BOOL, [TESTNAME], [PARAMHASH...] I Do a test, and log some information connected with it. This outputs the test result lines to the standard output: ok 12 not ok 13 Use it like this: $T->ok(-e $dotforward); Or better yet, like this: $T->ok((-e $dotforward), "Does the user have a .forward file?"); Or even better, like this: $T->ok((-e $dotforward), "Does the user have a .forward file?", User => $ENV{USER}, Path => $dotforward, Fwd => $ENV{FWD}); That last one, if it were test #3, would be logged as: 3: Does the user have a .forward file? 3: User: "alice" 3: Path: "/home/alice/.forward" 3: Fwd: undef 3: ok You get the idea. Note that defined quantities are logged with delimiters and with all nongraphical characters suitably escaped, so you can see evidence of unexpected whitespace and other badnasties. Had "Fwd" been the string "this\nand\nthat", you'd have seen: 3: Fwd: "this\nand\nthat" And unblessed array refs like ["this", "and", "that"] are treated as multiple values: 3: Fwd: "this" 3: Fwd: "and" 3: Fwd: "that" =cut sub ok { my ($self, $ok, $test, @ps) = @_; ++($self->{Count}); # next test # Report to harness: my $status = ($ok ? "ok " : "not ok ") . $self->{Count}; print {$self->{OUT}} $status, "\n"; # Log: $self->ln_print($test, "\n") if $test; while (@ps) { my ($k, $v) = (shift @ps, shift @ps); my @vs = ((ref($v) and (ref($v) eq 'ARRAY'))? @$v : ($v)); foreach (@vs) { if (!defined($_)) { # value not defined: output keyword $self->ln_print(qq{ $k: undef\n}); } else { # value defined: output quoted, encoded form s{([\n\t\x00-\x1F\x7F-\xFF\\\"])} {'\\'.sprintf("%02X",ord($1)) }exg; s{\\0A}{\\n}g; $self->ln_print(qq{ $k: "$_"\n}); } } } $self->ln_print($status, "\n"); $self->l_print("\n"); 1; } #------------------------------ =item ok_eq ASTRING, BSTRING, [TESTNAME], [PARAMHASH...] I Convenience front end to ok(): test whether C, and logs the operands as 'A' and 'B'. =cut sub ok_eq { my ($self, $this, $that, $test, @ps) = @_; $self->ok(($this eq $that), ($test || "(Is 'A' string-equal to 'B'?)"), A => $this, B => $that, @ps); } #------------------------------ =item ok_eqnum ANUM, BNUM, [TESTNAME], [PARAMHASH...] I Convenience front end to ok(): test whether C, and logs the operands as 'A' and 'B'. =cut sub ok_eqnum { my ($self, $this, $that, $test, @ps) = @_; $self->ok(($this == $that), ($test || "(Is 'A' numerically-equal to 'B'?)"), A => $this, B => $that, @ps); } #------------------------------ =back =head2 Logging messages =over 4 =cut #------------------------------ =item log_open PATH I Open a log file for messages to be output to. This is invoked for you automatically by C and C. =cut sub log_open { my ($self, $path) = @_; $self->{LogPath} = $path; $self->{LOG} = FileHandle->new(">$path") || die "open $path: $!"; $self; } #------------------------------ =item log_close I Close the log file and stop logging. You shouldn't need to invoke this directly; the destructor does it. =cut sub log_close { my $self = shift; close(delete $self->{LOG}) if $self->{LOG}; } #------------------------------ =item log_warnings I Invoking this redefines $SIG{__WARN__} to log to STDERR and to the tester's log. This is automatically invoked when using the C constructor. =cut sub log_warnings { my ($self) = @_; $SIG{__WARN__} = sub { print STDERR $_[0]; $self->log("warning: ", $_[0]); }; } #------------------------------ =item log MESSAGE... I Log a message to the log file. No alterations are made on the text of the message. See msg() for an alternative. =cut sub log { my $self = shift; print {$self->{LOG}} @_ if $self->{LOG}; } #------------------------------ =item msg MESSAGE... I Log a message to the log file. Lines are prefixed with "** " for clarity, and a terminating newline is forced. =cut sub msg { my $self = shift; my $text = join '', @_; chomp $text; $text =~ s{^}{** }gm; $self->l_print($text, "\n"); } #------------------------------ # # l_print MESSAGE... # # Instance method, private. # Print to the log file if there is one. # sub l_print { my $self = shift; print { $self->{LOG} } @_ if $self->{LOG}; } #------------------------------ # # ln_print MESSAGE... # # Instance method, private. # Print to the log file, prefixed by message number. # sub ln_print { my $self = shift; foreach (split /\n/, join('', @_)) { $self->l_print("$self->{Count}: $_\n"); } } #------------------------------ =back =head2 Utilities =over 4 =cut #------------------------------ =item catdir DIR, ..., DIR I Concatenate several directories into a path ending in a directory. Lightweight version of the one in C; this method dates back to a more-innocent time when File::Spec was younger and less ubiquitous. Paths are assumed to be absolute. To signify a relative path, the first DIR must be ".", which is processed specially. On Mac, the path I end in a ':'. On Unix, the path I end in a '/'. =cut sub catdir { my $self = shift; my $relative = shift @_ if ($_[0] eq '.'); if ($^O eq 'Mac') { return ($relative ? ':' : '') . (join ':', @_) . ':'; } else { return ($relative ? './' : '/') . join '/', @_; } } #------------------------------ =item catfile DIR, ..., DIR, FILE I Like catdir(), but last element is assumed to be a file. Note that, at a minimum, you must supply at least a single DIR. =cut sub catfile { my $self = shift; my $file = pop; if ($^O eq 'Mac') { return $self->catdir(@_) . $file; } else { return $self->catdir(@_) . "/$file"; } } #------------------------------ =back =head1 VERSION $Id: TBone.pm,v 1.124 2001/08/20 20:30:07 eryq Exp $ =head1 CHANGE LOG =over 4 =item Version 1.124 (2001/08/20) The terms-of-use have been placed in the distribution file "COPYING". Also, small documentation tweaks were made. =item Version 1.122 (2001/08/20) Changed output of C<"END"> to C<"# END">; apparently, "END" is not a directive. Maybe it never was. I The storyteller need not say "the end" aloud; Silence is enough. Automatically invoke C when constructing via C. =item Version 1.120 (2001/08/17) Added log_warnings() to support the logging of SIG{__WARN__} messages to the log file (if any). =item Version 1.116 (2000/03/23) Cosmetic improvements only. =item Version 1.112 (1999/05/12) Added lightweight catdir() and catfile() (a la File::Spec) to enhance portability to Mac environment. =item Version 1.111 (1999/04/18) Now uses File::Basename to create "typical" logfile name, for portability. =item Version 1.110 (1999/04/17) Fixed bug in constructor that surfaced if no log was being used. =back Created: Friday-the-13th of February, 1998. =head1 AUTHOR Eryq (F). President, ZeeGee Software Inc. (F). Go to F for the latest downloads and on-line documentation for this module. Enjoy. Yell if it breaks. =cut #------------------------------ 1; __END__ my $T = new ExtUtils::TBone "testout/foo.tlog"; $T->begin(3); $T->msg("before 1\nor 2"); $T->ok(1, "one"); $T->ok(2, "Two"); $T->ok(3, "Three", Roman=>'III', Arabic=>[3, '03'], Misc=>"3\nor 3"); $T->end; 1; Data-Validate-0.09/t/is_numeric.t0000644000076400007640000000213310460762574021261 0ustar richard.sonnenrichard.sonnen#!/usr/bin/perl # ------------------------------------------------------------------------------- # test harness for Data::Validate::is_numeric # # Author: Richard Sonnen (http://www.richardsonnen.com/) # ------------------------------------------------------------------------------- use lib './t'; use ExtUtils::TBone; use lib './blib'; use Data::Validate qw(is_numeric); my $t = ExtUtils::TBone->typical(); $t->begin(8); $t->msg("testing is_numeric..."); # normal integer $t->ok(defined(is_numeric(5)), "5 should pass"); # normal integer $t->ok(defined(is_numeric(0)), "0 should pass"); # big integer $t->ok(defined(is_numeric(-9223372036854775808)), "-9223372036854775808 should pass"); # float $t->ok(defined(is_numeric(1.01)), "1.01 should pass"); # non-numeric $t->ok(!defined(is_numeric('hi')), "'hi' should fail"); # non-numeric $t->ok(!defined(is_numeric('1.0hi')), "'1.0hi' should fail"); # as an object my $v = Data::Validate->new(); $t->ok(defined($v->is_numeric(5)), "5 should pass (object)"); $t->ok(!defined($v->is_numeric('hi')), "'hi' should fail (object)"); # we're done $t->end(); Data-Validate-0.09/t/is_alphanumeric.t0000644000076400007640000000226710157356010022262 0ustar richard.sonnenrichard.sonnen#!/usr/bin/perl # ------------------------------------------------------------------------------- # test harness for Data::Validate::is_alphanumeric # # Author: Richard Sonnen (http://www.richardsonnen.com/) # ------------------------------------------------------------------------------- use lib './t'; use ExtUtils::TBone; use lib './blib'; use Data::Validate qw(is_alphanumeric); my $t = ExtUtils::TBone->typical(); $t->begin(10); $t->msg("testing is_alphanumeric..."); # valid strings $t->ok(defined(is_alphanumeric('')), "'' is valid"); $t->ok(defined(is_alphanumeric('foo')), "'foo' is valid"); $t->ok(defined(is_alphanumeric('FOO')), "'FOO' is valid"); $t->ok(defined(is_alphanumeric('0')), "'0' is valid"); # invalid strings $t->ok(!defined(is_alphanumeric('&')), "'&' is invalid"); $t->ok(!defined(is_alphanumeric("\t")), '"\t" is invalid'); $t->ok(!defined(is_alphanumeric("\n")), '"\n" is invalid'); $t->ok(!defined(is_alphanumeric('hello world')), "'hello world' is invalid"); # as an object my $v = Data::Validate->new(); $t->ok(defined($v->is_alphanumeric('')), "'' is valid (object)"); $t->ok(!defined($v->is_alphanumeric('&')), "'&' is invalid (object)"); # we're done $t->end(); Data-Validate-0.09/t/is_printable.t0000644000076400007640000000213310157356132021567 0ustar richard.sonnenrichard.sonnen#!/usr/bin/perl # ------------------------------------------------------------------------------- # test harness for Data::Validate::is_printable # # Author: Richard Sonnen (http://www.richardsonnen.com/) # ------------------------------------------------------------------------------- use lib './t'; use ExtUtils::TBone; use lib './blib'; use Data::Validate qw(is_printable); my $t = ExtUtils::TBone->typical(); $t->begin(8); $t->msg("testing is_printable..."); # valid strings $t->ok(defined(is_printable('')), "'' is valid"); $t->ok(defined(is_printable('the fat cat sat on a mat')), "'the fat cat sat on a mat' is valid"); $t->ok(defined(is_printable("foo\tbar\nbaz")), "strings with tabs and newlines are valid"); $t->ok(defined(is_printable('0')), "'0' is valid"); # invalid strings $t->ok(!defined(is_printable("\a")), '\a is invalid'); $t->ok(!defined(is_printable("\0x0")), '\0x0 is invalid'); # as an object my $v = Data::Validate->new(); $t->ok(defined($v->is_printable('')), "'' is valid (object)"); $t->ok(!defined($v->is_printable("\a")), '\a is invalid (object)'); # we're done $t->end(); Data-Validate-0.09/t/is_integer.t0000644000076400007640000000216210461154764021253 0ustar richard.sonnenrichard.sonnen#!/usr/bin/perl # ------------------------------------------------------------------------------- # test harness for Data::Validate::is_integer # # Author: Richard Sonnen (http://www.richardsonnen.com/) # ------------------------------------------------------------------------------- use lib './t'; use ExtUtils::TBone; use lib './blib'; use Data::Validate qw(is_integer); my $t = ExtUtils::TBone->typical(); $t->begin(8); $t->msg("testing is_integer..."); # normal integer $t->ok(defined(is_integer(5)), "5 should pass"); # normal integer $t->ok(defined(is_integer(0)), "0 should pass"); # long integer $t->ok(defined(is_integer(20041222113730)), "20041222113730 should pass"); # very long integer $t->ok(defined(is_integer('-9223372036854775808')), "-9223372036854775808 should pass"); # float $t->ok(!defined(is_integer(1.01)), "1.01 should fail"); # non-numeric $t->ok(!defined(is_integer('hi')), "'hi' should fail"); # as an object my $v = Data::Validate->new(); $t->ok(defined($v->is_integer(0)), "0 should pass (object)"); $t->ok(!defined($v->is_integer('hi')), "'hi' should fail (object)"); # we're done $t->end(); Data-Validate-0.09/t/length_is_between.t0000644000076400007640000000262210157356335022611 0ustar richard.sonnenrichard.sonnen#!/usr/bin/perl # ------------------------------------------------------------------------------- # test harness for Data::Validate::length_is_between # # Author: Richard Sonnen (http://www.richardsonnen.com/) # ------------------------------------------------------------------------------- use lib './t'; use ExtUtils::TBone; use lib './blib'; use Data::Validate qw(length_is_between); my $t = ExtUtils::TBone->typical(); $t->begin(10); $t->msg("testing length_is_between..."); # valid strings $t->ok(defined(length_is_between('', 0, 1)), "'' is between 0 and 1"); $t->ok(defined(length_is_between('foo', 0, 3)), "'foo' is between 0 and 3"); $t->ok(defined(length_is_between('foo', 3, 10)), "'foo' is between 3 and 10"); $t->ok(defined(length_is_between('foobar', 3, undef)), "'foobar'is between 3 and infinity"); $t->ok(defined(length_is_between('foobar', undef, 10)), "'foobar'is between infinity and 10"); # invalid strings $t->ok(!defined(length_is_between('', 1, 10)), "'' is not between 1 and 10"); $t->ok(!defined(length_is_between('foo', 4, 10)), "'foo'is not between 4 and 10"); $t->ok(!defined(length_is_between('foo', 0, 1)), "'foo'is not between 0 and 1"); # as an object my $v = Data::Validate->new(); $t->ok(defined($v->length_is_between('', 0, 1)), "'' is between 0 and 1 (object)"); $t->ok(!defined($v->length_is_between('', 1, 10)), "'' is not between 1 and 10 (object)"); # we're done $t->end(); Data-Validate-0.09/t/is_even.t0000644000076400007640000000166710157356257020567 0ustar richard.sonnenrichard.sonnen#!/usr/bin/perl # ------------------------------------------------------------------------------- # test harness for Data::Validate::is_even # # Author: Richard Sonnen (http://www.richardsonnen.com/) # ------------------------------------------------------------------------------- use lib './t'; use ExtUtils::TBone; use lib './blib'; use Data::Validate qw(is_even); my $t = ExtUtils::TBone->typical(); $t->begin(8); $t->msg("testing is_even..."); # integers $t->ok(defined(is_even(0)), "0 is even"); $t->ok(defined(is_even(2)), "2 is even"); $t->ok(!defined(is_even(1)), "1 is odd"); $t->ok(!defined(is_even(5)), "5 is odd"); # non-integers $t->ok(!defined(is_even(0.1)), "0.1 is not an integer"); $t->ok(!defined(is_even('foo')), "'foo' is not an integer"); # as an object my $v = Data::Validate->new(); $t->ok(defined($v->is_even(0)), "0 is even (object)"); $t->ok(!defined($v->is_even(1)), "1 is odd (object)"); # we're done $t->end(); Data-Validate-0.09/t/is_between.t0000644000076400007640000000327010461154675021251 0ustar richard.sonnenrichard.sonnen#!/usr/bin/perl # ------------------------------------------------------------------------------- # test harness for Data::Validate::is_between # # Author: Richard Sonnen (http://www.richardsonnen.com/) # ------------------------------------------------------------------------------- use lib './t'; use ExtUtils::TBone; use lib './blib'; use Data::Validate qw(is_between); my $t = ExtUtils::TBone->typical(); $t->begin(10); $t->msg("testing is_between..."); # normal integer $t->ok(defined(is_between(5, 0,10)), "5 should be between 0 and 10"); # normal float $t->ok(defined(is_between(5.5, 0, 10)), "5.5 should be between 0 and 10"); # very long integer $t->ok(defined(is_between('9223372036854775808', '9223372036854775807', '9223372036854775809')), "9223372036854775808 should be between 9223372036854775807 and 9223372036854775809"); # very long integer $t->ok(!defined(is_between('9223372036854775810', '9223372036854775807', '9223372036854775809')), "9223372036854775810 is not between 9223372036854775807 and 9223372036854775809"); # out of range positive $t->ok(!defined(is_between(500, 0,10)), "500 should not be between 0 and 10"); # out of range negative $t->ok(!defined(is_between(-500, 0,10)), "-500 should not be between 0 and 10"); # undefined positive range $t->ok(defined(is_between(500, 0)), "500 should be between 0 and undef"); # undefined negative range $t->ok(defined(is_between(-500, undef, 1)), "-500 should be between undef and 1"); # as an object my $v = Data::Validate->new(); $t->ok(defined($v->is_between(5, 0,10)), "5 should be between 0 and 10 (object)"); $t->ok(!defined($v->is_between(500, 0,10)), "500 should not be between 0 and 10 (object)"); # we're done $t->end();