1Validation::Class::DireUcsteirveC(o3n)tributed Perl DocuVmaelnitdaattiioonn::Class::Directive(3)
2
3
4

NAME

6       Validation::Class::Directive - Base Class for Validation Class
7       Directives
8

VERSION

10       version 7.900057
11

SYNOPSIS

13           package Validation::Class::Directive::CheckBlacklist;
14
15           use base 'Validation::Class::Directive';
16
17           use strict;
18           use warnings;
19           use Validation::Class::Util;
20           use File::Slurp;
21
22           has 'mixin'     => 0;
23           has 'field'     => 1;
24           has 'multi'     => 0;
25           has 'message'   => '%s has been blacklisted';
26
27           sub validate {
28
29               my $self = shift;
30
31               my ($proto, $field, $param) = @_;
32
33               if (defined $field->{check_blacklist} && $param) {
34
35                   # is the parameter value blacklisted?
36                   my @blacklist = read_file('/blacklist.txt');
37
38                   $self->error if grep { $param =~ /^$_$/ } @blacklist;
39
40               }
41
42           }
43
44           1;
45
46       ... in your validation class:
47
48           package MyApp::Person;
49
50           use Validation::Class;
51
52           field ip_address => {
53               required        => 1,
54               check_blacklist => 1
55           };
56
57           1;
58
59       ... in your application:
60
61           package main;
62
63           use MyApp::Person;
64
65           my $person = MyApp::Person->new(ip_address => '0.0.0.0');
66
67           unless ($person->validates('ip_address')) {
68               # handle validation error
69           }
70

DESCRIPTION

72       You can extend Validation::Class by creating your own validation rules
73       (directives). Validation::Class::Directive provides a base-class for
74       you to use when creating new directive classes. Please see
75       Validation::Class::Directives for a complete list of core directives.
76

AUTHOR

78       Al Newkirk <anewkirk@ana.io>
79
81       This software is copyright (c) 2011 by Al Newkirk.
82
83       This is free software; you can redistribute it and/or modify it under
84       the same terms as the Perl 5 programming language system itself.
85
86
87
88perl v5.34.0                      2021-07-27   Validation::Class::Directive(3)
Impressum