Mojolicious-Plugin-InputValidation
view release on metacpan or search on metacpan
# Mojolicious::Plugin::InputValidation - Validate incoming requests
# SYNOPSIS
```perl
use Mojolicious::Lite;
plugin 'InputValidation';
# This needs to be done where one wants to use the iv_* routines.
use Mojolicious::Plugin::InputValidation;
post '/books' => sub {
my $c = shift;
# Validate incoming requests against our data model.
if (my $error = $c->validate_json_request({
title => iv_any,
abstract => iv_any(optional => 1, empty => 1),
author => {
firstname => iv_word,
lastname => iv_word,
},
published => iv_datetime,
price => iv_float,
revision => iv_int,
isbn => iv_any(pattern => qr/^[0-9\-]{10,13}$/),
advertise => iv_bool,
})) {
return $c->render(status => 400, text => $error);
}
# Now the payload is safe to use.
my $payload = $c->req->json;
...
};
```
# INSTALLATION
To install this module, run the following commands:
```sh
perl Makefile.PL
make
make test
make install
```
# SUPPORT AND DOCUMENTATION
After installing, you can find documentation for this module with the
perldoc command.
```sh
perldoc Mojolicious::Plugin::InputValidation
```
You can also look for information at:
RT, CPAN's request tracker (report bugs here)
https://rt.cpan.org/NoAuth/Bugs.html?Dist=Mojolicious-Plugin-InputValidation
AnnoCPAN, Annotated CPAN documentation
http://annocpan.org/dist/Mojolicious-Plugin-InputValidation
CPAN Ratings
https://cpanratings.perl.org/d/Mojolicious-Plugin-InputValidation
Search CPAN
https://metacpan.org/release/Mojolicious-Plugin-InputValidation
# LICENSE AND COPYRIGHT
Copyright (C) 2018 Tobias Leich
( run in 1.888 second using v1.01-cache-2.11-cpan-437f7b0c052 )