Mojolicious-Plugin-Vparam
view release on metacpan or search on metacpan
Revision history for Mojolicious-Plugin-Vparam
3.06 14-03-2018
- Address lonlat via number parser
3.05 23-02-2018
- Add opath extension to validate objects
3.04 23-02-2018
- Add new type "object"
3.03 15-11-2017
- No error for hash params if optional and value not set
3.02 14-11-2017
- Add "json?" type
Manage validation errors
=item *
Full Mojolicious::Validator::Validation integration
=back
This module use simple parameters types B<str>, B<int>, B<email>, B<bool>,
etc. to validate.
Instead of many other modules you mostly not need add specific validation
subs or rules.
Just set parameter type. But if you want sub or regexp you can do it too.
=head1 SYNOPSIS
# Add plugin in startup
$self->plugin('Vparam');
# Use in controller
Get raw input value after validation. Return I<$default> value or empty
string before validation.
# Form example:
<input name="myparam" value="<%= vvalue 'myparam' %>">
# Return next code if user just open form without submit and validation:
# <input name="myparam" value="">
# Then user submit form and you validate id. For example user submit "abc":
# <input name="myparam" value="abc">
=head2 vtype $name, %opts
Set new type $name if defined %opts. Else return type $name definition.
# Get type
$self->vtype('mytype');
# Set type
Keep and return blessed object for parsed parameters if available.
Vparam always return scalars if disabled.
Note: if defined I<date>, I<time>, I<datetime> then always return
formatted scalar.
=head2 jpath
If you POST data not form but raw JSON you can use JSON Pointer selectors
from L<Mojo::JSON::Pointer> to get and validate parameters.
# POST data contains:
# {"point":{"address":"some", "lon": 45.123456, "lat": 38.23452}}
%opts = $self->vparams(
address => { type => 'str', jpath => '/point/address' },
lon => { type => 'lon', jpath => '/point/lon' },
lat => { type => 'lat', jpath => '/point/lat' },
);
lib/Mojolicious/Plugin/Vparam.pm view on Meta::CPAN
Manage validation errors
=item *
Full Mojolicious::Validator::Validation integration
=back
This module use simple parameters types B<str>, B<int>, B<email>, B<bool>,
etc. to validate.
Instead of many other modules you mostly not need add specific validation
subs or rules.
Just set parameter type. But if you want sub or regexp you can do it too.
=head1 SYNOPSIS
# Add plugin in startup
$self->plugin('Vparam');
# Use in controller
lib/Mojolicious/Plugin/Vparam.pm view on Meta::CPAN
Get raw input value after validation. Return I<$default> value or empty
string before validation.
# Form example:
<input name="myparam" value="<%= vvalue 'myparam' %>">
# Return next code if user just open form without submit and validation:
# <input name="myparam" value="">
# Then user submit form and you validate id. For example user submit "abc":
# <input name="myparam" value="abc">
=head2 vtype $name, %opts
Set new type $name if defined %opts. Else return type $name definition.
# Get type
$self->vtype('mytype');
# Set type
lib/Mojolicious/Plugin/Vparam.pm view on Meta::CPAN
RU: Code of reason for registration
=head2 object
Simple objects via parameters (without validation!). Example:
# {foo => [ {bar => 1, baz => 2} ]}
?param1[foo][0][bar]=1¶m1[foo][0][baz]=2
This is experimental feature. We think how to validate parameters.
=head1 ATTRIBUTES
You can set a simple mode as in example or full mode. Full mode keys:
=head2 default
Default value. Default: undef.
lib/Mojolicious/Plugin/Vparam.pm view on Meta::CPAN
Keep and return blessed object for parsed parameters if available.
Vparam always return scalars if disabled.
Note: if defined I<date>, I<time>, I<datetime> then always return
formatted scalar.
=head2 jpath or jpath?
If you POST data not form but raw JSON you can use JSON Pointer selectors
from L<Mojo::JSON::Pointer> to get and validate parameters.
# POST data contains:
# {"point":{"address":"some", "lon": 45.123456, "lat": 38.23452}}
%opts = $self->vparams(
address => { type => 'str', jpath => '/point/address' },
lon => { type => 'lon', jpath => '/point/lon' },
lat => { type => 'lat', jpath => '/point/lat' },
);
( run in 0.975 second using v1.01-cache-2.11-cpan-437f7b0c052 )