NAME
Dancer::Plugin::ValidateTiny - Validate::Tiny dancer plugin.
VERSION
Version 0.01
SYNOPSIS
Easy and pretty cool validating data with Validate::Tiny module:
use Dancer::Plugin::ValidateTiny;
post '/' => sub {
my $params = params;
my $data_valid = 0;
# Validating params with rule file
my $data = validator($params, 'form.pl');
if($data->{valid}) { ... }
};
Rule file is pretty too:
{
# Fields for validating
fields => [qw/login email password password2/],
filters => [
# Remove spaces from all
qr/.+/ => filter(qw/trim strip/),
# Lowercase email
email => filter('lc'),
],
checks => [
[qw/login email password password2/] => is_required("Field required!"),
login => is_long_between( 2, 25, 'Your login should have between 2 and 25 characters.' ),
email => sub {
# Note, that @_ contains value to be checked
# and a reference to the filtered input hash
check_email($_[0], "Please enter a valid email address.");
},
password => is_long_between( 4, 40, 'Your password should have between 4 and 40 characters.' ),
password2 => is_equal("password", "Passwords don't match"),
],
}
DESCRIPTION
Dancer::Plugin::ValidateTiny - is a simple wrapper for use Validate::Tiny module.
CONFIG
In your config you can use there options:
plugins:
ValidateTiny:
rules_dir: validation
error_prefix: err_
is_full: 0
Config options
- rules_dir
-
Directory, where you can store your rule files with .pl extension.
- error_prefix
-
Prefix, that used to separate error fields from normal values in resulting hash
- is_full
-
If this option is set to 1, call of
validator
returning an object, that you can use as standart Validate::Tiny object.
AUTHOR
Alexey Kolganov, <akalgan at gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2011 by Alexey Kolganov
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.