NAME
Mojolicious::Validator::Validation - Perform validations
SYNOPSIS
use Mojolicious::Validator;
use Mojolicious::Validator::Validation;
my $validator = Mojolicious::Validator->new;
my $validation
= Mojolicious::Validator::Validation->new(validator => $validator);
$validation->input({foo => 'bar'});
$validation->required('foo')->in(qw(bar baz));
say $validation->param('foo');
DESCRIPTION
Mojolicious::Validator::Validation performs validations. Note that this module is EXPERIMENTAL and might change without warning!
ATTRIBUTES
Mojolicious::Validator::Validation implements the following attributes.
input
my $input = $validation->input;
$validation = $validation->input({});
Data to be validated.
output
my $output = $validation->output;
$validation = $validation->output({});
Validated data.
topic
my $topic = $validation->topic;
$validation = $validation->topic('foo');
Current validation topic.
validator
my $validator = $validation->validator;
$validation = $validation->validator(Mojolicious::Validator->new);
Mojolicious::Validator object this validation belongs to.
METHODS
Mojolicious::Validator::Validation inherits all methods from Mojo::Base and implements the following new ones.
check
$validation = $validation->check('size', 2, 7);
Perform validation check.
error
my $err = $validation->error('foo');
Return details about failed validation check.
my ($check, $result, @args) = @{$validation->error('foo')};
has_data
my $bool = $validation->has_data;
Check if input
is available for validation.
has_error
my $bool = $validation->has_error;
my $bool = $validation->has_error('foo');
Check if validation resulted in errors, defaults to checking all fields.
is_valid
my $bool = $validation->is_valid;
my $bool = $validation->is_valid('foo');
Check if validation was successful and field has a value, defaults to checking the current topic
.
optional
$validation = $validation->optional('foo');
Change validation topic
.
param
my @names = $c->param;
my $foo = $c->param('foo');
my @foo = $c->param('foo');
my ($foo, $bar) = $c->param(['foo', 'bar']);
Access validated parameters, similar to "param" in Mojolicious::Controller.
required
$validation = $validation->required('foo');
Change validation topic
and make sure a value is present.
CHECKS
In addition to the methods above, you can also call validation checks provided by Mojolicious::Validator on Mojolicious::Validator::Validation objects, similar to check
.
$validation->required('foo')->size(2, 5)->like(qr/^[A-Z]/);
$validation->optional('bar')->equal_to('foo');
$validation->optional('baz')->in(qw(test 123));