The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Validator::Custom::Rule - Rule object

SYNOPSYS

  use Validator::Custom;
  my $vc = Validator::Custom->new;
  
  # Create rule object
  my $rule = $vc->create_rule;
  $rule->require('id')->check(
    'ascii'
  );
  $rule->optional('name')->check(
   'not_blank'
  );
  
  # Validate
  my $data = {id => '001', name => 'kimoto'};
  my $result = $vc->validate($data, $rule);
  
  # Option
  $rule->require('id')->default(4)->copy(0)->message('Error')->check(
    'not_blank'
  );

DESCRIPTION

Validator::Custom::Rule is the class to parse rule and store it as object.

ATTRIBUTES

rule

  my $content = $rule_obj->rule;
  $rule_obj = $rule->rule($content);

Content of rule object.

METHODS

check

  $rule->check(
    'not_blank',
    'ascii'
  );

Set constraints.

copy

  $rule->copy(0);

Set copy option

default

  $rule->default(0);

Set default option

message

  $rule->message('Error');

Set message option

name

  $rule->name('key1');

Set result key name

optional

  $rule->optional('id');

Set key and set require option to 0.

require

  $rule->require('id');
  $rule->require(['id1', 'id2']);

Set key.

parse

  $rule_obj = $rule_obj->parse($rule);

Parse rule and store it to rule attribute.