-
-
05 Jun 2013 08:47:12 UTC
- Distribution: MojoX-Validator
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues (3)
- Testers (224 / 56 / 1)
- Kwalitee
Bus factor: 1- 100.00% Coverage
- License: artistic_2
- Perl: v5.8.7
- Activity
24 month- Tools
- Download (4.51KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- Input::Validator
- Mojolicious
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Mojolicious::Plugin::Validator - Plugin for MojoX::Validator
SYNOPSIS
# Mojolicious $self->plugin('validator'); # Mojolicious::Lite plugin 'validator' => { messages => { REQUIRED => 'This field is required', LENGTH_CONSTRAINT_FAILED => 'Too big' } }; sub action { my $self = shift; my $validator = $self->create_validator; $validator->field('username')->required(1)->length(3, 20); return unless $self->validate($validator); # Create a user for example ... } 1; __DATA__ @@ user.html.ep % if (validator_has_errors) { <div class="error">Please, correct the errors below.</div> % } %= form_for 'user' => begin <label for="username">Username</label><br /> <%= input_tag 'username' %><br /> <%= validator_error 'username' %><br /> <%= submit_button %> % end
DESCRIPTION
Mojolicious::Plugin::Validator is a plugin for MojoX::Validator that simplifies parameters validation.
Options
- messages
-
# Mojolicious::Lite plugin 'validator' => { messages => { REQUIRED => 'This field is required', LENGTH_CONSTRAINT_FAILED => 'Too big' } };
Replace default errors.
Helpers
- create_validator
-
my $validator = $self->create_validator; $validator->field('username')->required(1)->length(3, 20);
Create MojoX::Validator.
$self->create_validator('will-be_decamelized'); $self->create_validator('Custom::Class');
Create a validator from a class derived from MojoX::Validator. This way preconfigured validators can be used.
- validate
-
$self->validate($validator);
Validate parameters with provided validator and automatically set errors.
- validator_has_errors
-
% if (validator_has_errors) { <div class="error">Please, correct the errors below.</div> % }
Check if there are any errors.
- validator_error
-
<%= validator_error 'username' %>
Render the appropriate error.
- validator_has_unknown_params
-
% if (validator_has_unknown_params) { <div class="error">Unspecified parameters were detected.</div> % }
Returns true if unspecified parameters were passed
METHODS
Mojolicious::Plugin::Validator inherits all methods from Mojolicious::Plugin and implements the following new ones.
register
$plugin->register;
Register helpers in Mojolicious application.
SEE ALSO
Module Install Instructions
To install MojoX::Validator, copy and paste the appropriate command in to your terminal.
cpanm MojoX::Validator
perl -MCPAN -e shell install MojoX::Validator
For more information on module installation, please visit the detailed CPAN module installation guide.