NAME
Validator::Custom::Rules - Rules (EXPERIMENTAL)
SYNOPSYS
# Rules object
my $rules = Validator::Custom::Rules->new;
# Add rule
$rules->add(user => [
id => [
'not_blank',
'ascii'
],
name => [
'not_blank',
{length => [1, 30]}
],
age => [
'uint'
]
]);
# Get rule
my $rule_user = $rules->get('user');
# Filter
$rules->filter('user' => {
insert => ['name', 'age'],
update => ['id', 'name', 'age'],
delete => ['id']
});
# Get rule with filtering
my $rule_user_insert = $rules->get('user', 'insert');
my $rule_user_update = $rules->get('user', 'update');
my $rule_user_delete = $rules->get('user', 'delete');
DESCRIPTION
Validation::Custom::Rules is class to store and retreive rule and provide filter.
ATTRIBUTES
rules
my $content = $rules->rules;
$rules = $rules->rules($content);
Content of rules object.
METHODS
add
$rules = $rules->add($name => $rule);
Add rule.
You can add rule or rule object.
# Rule
my $rule = [
id => [
'not_blank',
'ascii'
],
name => [
'not_blank',
{length => [1, 30]}
],
age => [
'uint'
]
]
$rules->add(user => $rule);
# Rule object
my $rule_obj = Validator::Custom::Rule->new;
$rule_obj->parse($rule);
$rules->add(user => $rule_obj);
filter
$rules = $rules->filter($name => $filtering);
Resister filtering.
# Filter
$rules->filter('user' => {
insert => ['name', 'age'],
update => ['id', 'name', 'age'],
delete => ['id']
});
get
method use these filtering.
my $rule_user_insert = $rules->get('user', 'insert');
get
$rules = $rules->get($name);
$rules = $rules->get($name, $filter_name);
Get rule.
# Get rule
my $rule_user = $rules->get('user');
You can specify filtering.
# Get rule with filtering
my $rule_user_insert = $rules->get('user', 'insert');
my $rule_user_update = $rules->get('user', 'update');
my $rule_user_delete = $rules->get('user', 'delete');