Mojolicious::Plugin::ValidateMoose - Can validate using Moose objects
0.02
This module is handy if you want to validate POST/GET parameters using Moose classes.
package MyApp; use Mojo::Base 'Mojolicious'; sub startup { my $self = shift; $self->plugin('Mojolicious::Plugin::ValidateMoose'); # ... } package MyApp::Root; use Mojo::Base 'Mojolicious::Controller'; sub foo { my $self = shift; if($self->req->method eq 'POST') { if(my $obj = $self->validate_moose('My::Moose::Class')) { # input validate, and $obj created from My::Moose::Class # with the params set as attributes } } }
$obj = $controller->validate_moose($moose_class, \%args); $obj = $controller->validate_moose($moose_obj, \%args);
Will either update an existing or create a new Moose object, if all the attributes gets validated. If any of the attributes is not updated with the right value from param(), this method will set invalid_form_elements in the stash to a datastructure like this:
param()
invalid_form_elements
{ $param_name_a => 'required', # fixed $param_name_b => 'moose exception message', # custom }
Example moose exception message:
Validation failed for 'Int' with value "asd"
The method will return empty list if it fail to validate the input.
Will register the methods undef "HELPERS" as Mojolicious helpers.
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
Jan Henning Thorsen - jhthorsen at cpan.org
To install Mojolicious::Plugin::ValidateMoose, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::ValidateMoose
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::ValidateMoose
For more information on module installation, please visit the detailed CPAN module installation guide.