Dancer::Plugin::DataFormValidator - Easy access to Data::FormValidator from within Dancer applications
version 0.002
use Dancer; use Dancer::Plugin::DataFormValidator; post '/foo' => sub { if (my $results = dfv ('foo')) { # Do some stuff } else { # Report some failure } }
Provides an easy way to validate user input based on an input profile (specified as per Data::FormValidator) using a dfv() keyword within your Dancer application.
dfv()
In the simplest case you can use Dancer::Plugin::DataFormValidator without any configuration at all, passing validation profiles each time you call dfv().
Dancer::Plugin::DataFormValidator
To reduce visual clutter when dealing with complex validation profiles, you may optionally specify a profile in the dancer configuration that will be loaded on first use, and which contains multiple validation profiles you can then refer to by name:
plugins: DataFormValidator: profile: 'profiles'
The dfv() routine can be called several different ways. In all cases it must include either a validation profile name (which must be present in the file loaded via the profile configuration parameter), or a hashref containing the validation profile to be used (see Data::FormValidator for details on what that profile may contain).
If nothing else is included, the parameters Dancer found for the handler will be used. Otherwise, you may hand it a hashref of whatever data you wish it to check.
It will return a Data::FormValidator::Results object you can use however you please.
post '/jazz' => sub { if (my $results = dfv ({required => [qw{Name}]}, {Name => 'HorseFeathers'})) { do_something ($results->valid) } else { messages = $results->msgs; } };
post '/contact/form' => sub { if (my $results = dfv ('contact')) { do_something ($results->valid) } else { messages = $results->msgs; } };
This module is developed on Github at:
http://github.com/mdorman/Dancer-Plugin-DataFormValidator
Feel free to fork the repo and submit pull requests.
Derived, in intent if not actual code, from Dancer::Plugin::FormValidator by Natal Ngétal, <hobbestigrou@erakis.im>
<hobbestigrou@erakis.im>
Dancer Data::FormValidator
Michael Alan Dorman <mdorman@ironicdesign.com>
This software is copyright (c) 2011 by Ironic Design, Inc..
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::DataFormValidator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Plugin::DataFormValidator
CPAN shell
perl -MCPAN -e shell install Dancer::Plugin::DataFormValidator
For more information on module installation, please visit the detailed CPAN module installation guide.