NAME

Data::Compare::Type - Validation module for nested array ,hash ,scalar like FormValidator::Simple

VERSION

This document describes Data::Compare::Type version 0.01.

SYNOPSIS

use Data::Compare::Type;
$v = Data::Compare::Type->new();
$parameters = { id => 100};
$rule = {id => 'INT'};
$v->check($parameters , $rule)

if($v->has_error){
    for my $error(@{$v->get_error}){
        die($error->{param_name} . ' is not ' . $error->{error});
    }
}

DESCRIPTION

You can check some value types in Scalar , Arrayref , Hashref.

Functions

check

$v = Data::Compare::Type->new();
$v->check(111 , "INT"); # return true
$v->check(111 , "STRING"); # return false and $v->has_error is true 
$v->check([111 , 1222, 333] , ["INT"]);# return true
$v->check({ hoge => 'fuga'},{hoge => "ASCII"});# return true
$v->check([{id => 111,id2=> 22.2 },{id=> 1222 , id2=> 1.11},{id=> 333 , id2=> 44.44}] , [{id =>"INT",id2 => "DECIMAL"}]);# return true

has_error

$v->check({hoge =>  "hogehogehogehoge" },{hoge=> ["ASCII","NOT_BLANK" , ['LENGTH' , 1 , 15]]});
if($v->has_error){
    # error handling routine
}

get_error

$v->check({hoge =>  "hogehogehogehoge" },{hoge=> ["ASCII","NOT_BLANK" , ['LENGTH' , 1 , 15]]});
if($v->has_error){
    use Data::Dumper;
    warn Dumper $v->get_error;
    #$VAR1 = [
    #  {
    #    'min_value' => 1,
    #    'error' => 'LENGTH',
    #    'position' => '$param->{hoge}',
    #    'max_value' => 15,
    #    'param_name' => 'hoge',
    #    'message' => 'LENGTH IS WRONG'
    #  }
    #];
}

Check Methods

INT

allow integer ; 10 , 0 , -10

STRING

allow Strings

ASCII

allow alphabet and ascii symbols

DECIMAL

allow integer and decimals ; 10 1,0 , 0 , -10 , -1.0

URL

allow ^http|^https

EMAIL

used Email::Valid;

DATETIME

'%Y-%m-%d %H:%M:%S'
'%Y/%m/%d %H:%M:%S'
'%Y-%m-%d %H-%M-%S'
'%Y/%m/%d %H-%M-%S'

DATE

'%Y-%m-%d'
'%Y/%m/%d'

TIME

'%H-%M-%S'
'%H-%M-%S'

LENGTH

check value length $rule = ["ASCII","NOT_BLANK" , ['LENGTH' , 1 , 8]]} # a , $v->check(['a'] , $rule) # true $v->check(['abcdefghi'] , $rule) # false

$rule = ["ASCII","NOT_BLANK" , ['LENGTH' , 4]]} # a , 
$v->check(['abc'] , $rule) # false 
$v->check(['abcd'] , $rule) # true
$v->check(['abcde'] , $rule) # false 

BETWEEN

check value $rule = ["INT",['BETWEEN' , 1 , 8]]} # a , $v->check([1] , $rule) # true $v->check([3.1] , $rule) # true $v->check([5] , $rule) # true $v->check([7.9] , $rule) # true $v->check([8] , $rule) # true $v->check([9] , $rule) # false $v->check([0] , $rule) # false

DEPENDENCIES

Perl 5.8.1 or later.

BUGS

All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.

SEE ALSO

perl

AUTHOR

S2 <s2otsa@hotmail.com>

LICENSE AND COPYRIGHT

Copyright (c) 2012, S2. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.