Mojolicious::Plugin::Vparam - Mojolicious plugin validator for GET/POST data.
# Get one parameter my $param1 = $self->vparam('date' => 'datetime'); # Or more syntax my $param2 = $self->vparam('page' => {type => 'int', default => 1}); # Or more simple syntax my $param2 = $self->vparam('page' => 'int', default => 1); # Get many parameters my %params = $self->vparams( # Simple syntax name => 'str', password => qr{^\w{,32}$}, myparam => sub { my ($self, $param) = @_; return ($param eq 'ok') ?1 :0; }, # More syntax from => { type => 'date', default => '' }, to => { type => 'date', default => '' }, id => { type => 'int' }, money => { regexp => qr{^\d+(?:\.\d{2})?$} }, myparam => { post => sub { my ($self, $param) = @_; return ($param eq 'ok') ?1 :0; } }, isa => { type => 'bool', default => 0 }, ); # Same as vparams but auto add some more params for table sorting/paging my %filters = $self->vsort( -sort => ['name', 'date', ...], ... ); # Get a errors hash by params name my %errors = $self->verrors;
This module use simple paramters types str, int, email, bool, etc. to validate. Instead of many other modules you not need add specific validation subs or rules. Just set parameter type. But if you want sub or rule you can do it too.
Method vsort automatically add some keys.
Page number $PARAM_PAGE. Default: 1.
Column number for sorting $PARAM_ORDER_BY. Default: 1.
Sort order $PARAM_ORDER_DEST. Default: ASC.
Rows on page
You can set a simple mode as in exapmple or full mode. Full mode keys:
Default value. Default: undef.
Valudator regexp by $regexp.
Incoming filter sub. Used for primary filtration: string length and trim, etc. Result will be used as new param value.
Validation sub. Return 1 if valid, else 0.
Out filter sub. Used to modify value for use in you program. Usually used to bless in some object. Result will be used as new param value.
Parameter type. If set then some filters will be apply.
int str date time datetime money bool email url phone
After apply all type filters, regexp and post filters will be apply too if set.
Arrayref for sort column names. Usually not all columns visible for users and you need convert column numbers in names. This also protect you SQL queries from set too much or too low column number.
Get a string and return DateTime or undef. Have a hack for parse Russian data and time.
Clear phones. Fix first local digit 8 problem.
Return <undef> if phome not correct
Dmitry E. Oboukhov <unera@debian.org>, Roman V. Nikolaev <rshadow@rambler.ru>
Copyright (C) 2011 Dmitry E. Oboukhov <unera@debian.org> Copyright (C) 2011 Roman V. Nikolaev <rshadow@rambler.ru>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
To install Mojolicious::Plugin::Vparam, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::Vparam
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::Vparam
For more information on module installation, please visit the detailed CPAN module installation guide.