Dancer::Plugin::Validation - Simple data validation for Dancer applications using Oogly!
version 0.01
use Dancer; use Dancer::Plugin::Validation; # Call the validation keyword and pass it an arrayref of params to validate post '/login' => sub { if ( validate [qw/login password/] ) { redirect '...'; } else { # errors are stored as an arrayref at vars->{validation}->errors # see cpan module Oogly for more insight template '...' => { errors => vars->{validation}->errors }; } }
Provides an easy way of validating data via the Oogly data validation framework. This plugin allows you to define data validation rules and filters in your Dancer YAML configuration file, then validate parameters against those specifications easily.
Connection details will be taken from your Dancer application config file, and should be specified as, for example:
plugins: Validation: mixins: default: required: 1 min_length: 1 max_length: 255 filters: - trim - strip - lowercase fields: login: mixin: default label: 'user login' validation: sub { $_[0]->error($_[1], "user login is required bitch") if $value !~ /[a-zA-Z]/ && $value !~ /[0-9]/ } password: mixin_field: login label: 'user password'
Important Note! When using the validation directive of a field, its must be an anonymous subroutine and due to the YAML specification, it must all appear on a single line. This is not optimal for complex routines but its all we got right now :(
Al Newkirk <awncorp@cpan.org>
This software is copyright (c) 2010 by awncorp.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Dancer::Plugin::Validation, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Plugin::Validation
CPAN shell
perl -MCPAN -e shell install Dancer::Plugin::Validation
For more information on module installation, please visit the detailed CPAN module installation guide.