Release the Validator :: Custom 0.27 - improvement of grammar, handling of a multiple values, improvement of the OR validation

Validator::Custom 0.27 is release. This is a form validation module made of Perl. I was released it on CPAN.

Validator::Custom 0.27 Release

In the recent changes, while it keep backword compatibility, it is an effort to get the Mojolicious::Validator grammar. Validator::Custom is more customizable than Mojolicious::Validator yet now.

use Validator::Custom;

my $vc = Validator::Custom->new;

# my $data = {
  name => 'kimoto',
  age => '   19   '

# Create rule
my $rule = $vc->create_rule;

# Check

We introduce some of the features of the Validator :: Custom 0.27.

Easily verification of multiple elements

In HTML form, it is quite boring to validate multiple values because we think abount the following patterns and handle each element.

1. the value does not exist
2. an empty string
3. the value is one
4. the value is more than one

We get array rerefence which don't contain empty string.
In Validator :: Custom 0.27, you can write the following way.

  ->check({selected_at_least => 1})

"to_array_remove_blank" filter is added. You can convert data to non-empty strings array reference. after this, check selected at least 1. and you can check each element by "each" option. and call check method.

"each" option is prepared as an improvement of "@int'. it is recommended to use the each option.

You can also do the following. This case allow that there are no values.

  ->check({selected_at_least => 1})
  ->default(sub { [] });

You can set the default value, but in the case of non-string and numeric values, it must be surrounded by "sub {}".

Additional check_or for "or" validation

You can use "check_or" method for "or" validation.

$rule->require('age')->check_or('blank', 'int');

"check_or" method is prepared as an improvement of "blank || int".

Leave a comment

About Yuki Kimoto

user-pic I'm Yuki Kimoto, Japanese Perl programmer.I create Perl modules and applications. GitPrep, SPVM, DBIx::Custom, Validator::Custom, Test::Mojo, Mojolicious::Plugin::AutoRoute, etc.