Mojolicious::Plugin::Data::Validate::WithYAML - validate form input with Data::Validate::WithYAML
version 0.06
In your startup
method:
sub startup {
my $self = shift;
# more Mojolicious stuff
$self->plugin(
'Data::Validate::WithYAML',
{
error_prefix => 'ERROR_', # optional
conf_path => '/opt/app/conf', # path to the dir where all the .ymls are (optional)
}
);
}
In your controller:
sub register {
my $self = shift;
# might be (age => 'You are too young', name => 'name is required')
# or with error_prefix (ERROR_age => 'You are too young', ERROR_name => 'name is required')
my %errors = $self->validate( 'registration' );
if ( %errors ) {
$self->stash( %errors );
$self->render;
return;
}
# create new user
}
Your registration.yml
---
age:
type: required
message: You are too young
min: 18
name:
type: required
message: name is required
password:
type: required
plugin: PasswordPolicy
website:
type: optional
plugin: URL
my %errors = $controller->validate( $yaml_name );
Validates the parameters. Optional parameter is $yaml_name. If $yaml_name is ommitted, the subroutine name (e.g. "register") is used.
The distribution is contained in a Git repository, so simply clone the repository
$ git clone git://github.com/perlservices/Mojolicious-Plugin-Data-Validate-WithYAML.git
and change into the newly-created directory.
$ cd Mojolicious-Plugin-Data-Validate-WithYAML
The project uses Dist::Zilla
to
build the distribution, hence this will need to be installed before
continuing:
$ cpanm Dist::Zilla
To install the required prequisite packages, run the following set of commands:
$ dzil authordeps --missing | cpanm
$ dzil listdeps --author --missing | cpanm
The distribution can be tested like so:
$ dzil test
To run the full set of tests (including author and release-process tests),
add the --author
and --release
options:
$ dzil test --author --release
Renee Baecker reneeb@cpan.org
This software is Copyright (c) 2013 by Renee Baecker.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)