View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Николаев Роман > Mojolicious-Plugin-Vparam-0.6 > Mojolicious::Plugin::Vparam



Annotate this POD


View/Report Bugs
Module Version: 0.6   Source   Latest Release: Mojolicious-Plugin-Vparam-2.04


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.

regexp $mojo, $regexp

Valudator regexp by $regexp.

pre $mojo, &sub

Incoming filter sub. Used for primary filtration: string length and trim, etc. Result will be used as new param value.

valid $mojo, &sub

Validation sub. Return 1 if valid, else 0.

post $mojo, &sub

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.

date_parse $str

Get a string and return DateTime or undef. Have a hack for parse Russian data and time.

clean_phone $phone, $country, $region

Clear phones. Fix first local digit 8 problem.

Return <undef> if phome not correct


Dmitry E. Oboukhov <>, Roman V. Nikolaev <>


Copyright (C) 2011 Dmitry E. Oboukhov <> Copyright (C) 2011 Roman V. Nikolaev <>

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.

syntax highlighting: