QBit::Validator - It is used for validation of input parameters.
https://github.com/QBitFramework/QBit-Validator
cpanm QBit::Validator
apt-get install libqbit-validator-perl (http://perlhub.ru/)
create object QBit::Validator and check data using template
Arguments:
data - checking data
template - template for check
pre_run - function is executed before checking
app - model using in check
throw - throw (boolean type, throw exception if an error has occurred)
Example:
my $data = { hello => 'hi, qbit-validator' }; my $qv = QBit::Validator->new( data => $data, template => { type => 'hash', fields => { hello => { max_len => 5, }, }, }, );
get or set template
my $template = $qv->template; $qv->template($template);
return boolean result (TRUE if an error has occurred or FALSE)
if ($qv->has_errors) { ... }
return data
$self->db->table->edit($qv->data) unless $qv->has_errors;
return list name of fields with error
if ($qv->has_errors) { my @fields = $qv->get_wrong_fields; ldump(\@fields); # ['hello'] # [''] - error in root }
return list fields with error
if ($qv->has_errors) { my @fields = $qv->get_fields_with_error; ldump(\@fields); # [ # { # msgs => ['Error'], # path => ['hello'] # } # ] # # path => [''] - error in root }
return error by path
if ($qv->has_errors) { my $error = $qv->get_error('hello'); # or ['hello'] print $error; # 'Error' }
return all errors join "\n"
if ($qv->has_errors) { my $errors = $qv->get_all_errors(); print $errors; # 'Error' }
throw Exception::Validator with error message from get_all_errors
$qv->throw_exception if $qv->has_errors;
optional
eq
regexp
min
max
len_min
len
len_max
in
For more information see tests
size_min
size
size_max
all
contents
deps
fields
extra
one_of
any_of
To install Exception::Validator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Exception::Validator
CPAN shell
perl -MCPAN -e shell install Exception::Validator
For more information on module installation, please visit the detailed CPAN module installation guide.