NAME

Data::Validate::WithYAML - Validation framework that can be configured with YAML files

VERSION

version 0.13

SYNOPSIS

Perhaps a little code snippet.

use Data::Validate::WithYAML;

my $foo = Data::Validate::WithYAML->new( 'test.yml' );
my %map = (
    name     => 'Test Person',
    password => 'xasdfjakslr453$',
    plz      => 64569,
    word     => 'Herr',
    age      => 55,
);

for my $field ( keys %map ){
    print "ok: ",$map{$field},"\n" if $foo->check( $field, $map{$field} );
}

data.yml

---
step1:
    name:
        type: required
        length: 8,122
    password:
        type: required
        length: 10,
    plz:
        regex: ^\d{4,5}$
        type: optional
    word:
        enum:
            - Herr
            - Frau
            - Firma
    age:
        type: required
        min: 18
        max: 65

METHODS

new

my $foo = Data::Validate::WithYAML->new( 'filename' );
my $foo = Data::Validate::WithYAML->new(
    'filename',
    allow_subs => 1,
    no_steps   => 1,
);

creates a new object.

set_optional

This method makes a field optional if it was required

set_required

This method makes a field required if it was optional

validate

This subroutine validates one form. You have to pass the form name (key in the config file), a hash with fieldnames and its values

my %fields = (
    username => $cgi->param('user'),
    passwort => $password,
);
$foo->validate( 'step1', %fields );

fieldnames

errstr

message

returns the message if specified in YAML

$obj->message( 'fieldname' );

check_list

$obj->check_list('fieldname',['value','value2']);

Checks if the values match the validation criteria. Returns an arrayref with checkresults:

[
    1,
    0,
] 

check

$obj->check('fieldname','value');

checks if a value is valid. returns 1 if the value is valid, otherwise it returns 0.

fieldinfo

Returns the config for the given field.

Your test.yml:

---
age:
  type: required
  min: 18
  max: 65

Your script:

my $info = $validator->fieldinfo( 'age' );

$info is a hashreference then:

{
    type => 'required',
    min  => 18,
    max  => 65,
}

AUTHOR

Renee Baecker <module@renee-baecker.de>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2012 by Renee Baecker.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)