Yes. Put it in a helper:

$app->helper("validate.page" => sub { 
shift->validaton->optional('page')->num(1, 100) })

and use it as:

$c->validate->page;

Or you could also route condition or a "under route" where you add the 
validation before your action is called:

* http://mojolicious.org/perldoc/Mojolicious/Guides/Routing#Under
* http://mojolicious.org/perldoc/Mojolicious/Guides/Routing#Conditions
* http://mojolicious.org/perldoc/Mojolicious/Guides/Routing#Adding-conditions

On Tuesday, February 27, 2018 at 5:08:23 AM UTC+1, Michael Fung wrote:
>
> Hi All,
>
> I am trying out Mojolicious::Validator. It is very elegant. But, if many 
> actions take a optional "page" parameter, then I need to include something 
> like the following for all these actions.
>
> sub action1 {
>   ...
>
>   $validation->optional('page')->num(1,100);
>
>
> Is there a way to avoid this repetition while using Mojolicious::Validator?
>
>
> Thanks,
> Michael
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to