<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># NAME

FormValidator::Simple::Struct - Validation module for nested array ,hash ,scalar  like FormValidator::Simple

# VERSION

This document describes FormValidator::Simple::Struct version 0.15.

# SYNOPSIS

    use FormValidator::Simple::Struct;
    $v = FormValidator::Simple::Struct-&gt;new();
    $parameters = { id =&gt; 100};
    $rule = {id =&gt; 'INT'};
    $v-&gt;check($parameters , $rule)
    

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

# DESCRIPTION

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

# Functions

## check

    $v = FormValidator::Simple::Struct-&gt;new();
    $v-&gt;check(111 , "INT"); # return true
    $v-&gt;check(111 , "STRING"); # return false and $v-&gt;has_error is true 
    $v-&gt;check([111 , 1222, 333] , ["INT"]);# return true
    $v-&gt;check({ key  =&gt; 'value'},{key=&gt; "ASCII"});# return true
    $v-&gt;check([{id =&gt; 111,id2=&gt; 22.2 },{id=&gt; 1222 , id2=&gt; 1.11},{id=&gt; 333 , id2=&gt; 44.44}] , [{id =&gt;"INT",id2 =&gt; "DECIMAL"}]);# return true

## has\_error

    $v-&gt;check(
      {key =&gt;  "abcdefghijklmnop" },
      {key =&gt; ["ASCII","NOT_BLANK" , ['LENGTH' , 1 , 15]]});
    if($v-&gt;has_error){
        # error handling routine
    }

## get\_error

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

## INT

    # allow integer ; 10 , 0 , -10
    ok $v-&gt;check(
       {key =&gt;  "1" },
       {key =&gt; "INT"});

## STRING

    # allow all Strings
    ok $v-&gt;check(
       ["111" , "abcde"],
       ["STRING"]);

## ASCII

    # allow Arabic number and alphabet and ascii symbols
    ok $v-&gt;check(
       ["111" , 'abcde!"#$%%()'],
       ["ASCII"]);
    

    # not allow multi bytes characters
    ng $v-&gt;check(
       ["縺�" , "貍｢蟄�"],
       ["ASCII"]);

## DECIMAL

    # allow integer and decimals ; 10 1,0 , 0 , -10 , -1.0
    ok $v-&gt;check(
       ["111" , "11.1" , "-11" , '0' , '-1.15'],
       ["DECIMAL"]);

## URL

    # allow ^http|^https
    ok $v-&gt;check(
       ["http://google.com" , 'https://www.google.com/'],
       ["URL"]);

    ng $v-&gt;check(
       ["git://google.com" , 'smb://www.google.com/'],
       ["URL"]);

## EMAIL

    this is base on Email::Valid;

## DATETIME

    # The following examples are followed. 
    ok $v-&gt;check([
        '%Y-%m-%d %H:%M:%S',
        '%Y/%m/%d %H:%M:%S',
        '%Y-%m-%d %H-%M-%S',
        '%Y/%m/%d %H-%M-%S',],
    ['DATETIME']);

## DATE

    # The following examples are followed. 
    ok $v-&gt;check([
       '%Y-%m-%d',
       '%Y/%m/%d'],
    ['DATE']);

## TIME

    # The following examples are followed. 
    ok $v-&gt;check([
       '%H-%M-%S',
       '%H-%M-%S'],
    ['TIME']);

## LENGTH

    # check value length
    $rule = ["ASCII","NOT_BLANK" , ['LENGTH' , 1 , 8]];
    ok $v-&gt;check(['a'] , $rule);
    ng $v-&gt;check(['abcdefghi'] , $rule);

    $rule = ["ASCII","NOT_BLANK" , ['LENGTH' , 4]];
    ng $v-&gt;check(['abc'] , $rule) # false 
    ok $v-&gt;check(['abcd'] , $rule) # true
    ng $v-&gt;check(['abcde'] , $rule) # false 

## BETWEEN

    # check value 
    $rule = ["INT",['BETWEEN' , 1 , 8]];
    ok $v-&gt;check([1] , $rule) # true
    ng $v-&gt;check([3.1] , $rule) # false not INT
    ok $v-&gt;check([5] , $rule) # true
    ng $v-&gt;check([7.9] , $rule) # false not INT 
    ok $v-&gt;check([8] , $rule) # true
    ng $v-&gt;check([9] , $rule) # false, input is over 8
    ng $v-&gt;check([0] , $rule) # false, input is under 1

# 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](http://search.cpan.org/perldoc?perl)

# AUTHOR

S2 &lt;s2otsa59@gmail.com&gt;

# 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.
</pre></body></html>