Validator::Checker::HOWTO - how to develop checkers for Validator::Var
This HOWTO describes how to develop custom checkers for use with Validator::Var objects. Generally speaking there is no built-in and custom checkers, all of them are simply checkers.
As an example you can look at package Validator::Checker::MostWanted. As you can see - it's very simple. Now let's try to develop your own checkers.
package Your::Custom::Checker; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw( Your_Checker Your_Another_Checker ); sub Your_Checker {[ \&_your_checker, # ref to checker subroutine 'Your_Checker', # checker name 'corresponds to Your_Checker' # description ]} sub Your_Another_Checker {[ \&_your_another_checker, 'Your_Another_Checker', 'corresponds to Your_Another_Checker' ]}; # checker without arguments # sub _your_checker { my $var = shift; my $bool; # checkers code # ... return $bool; } # checker with arguments # sub _your_another_checker { my ($var, @args) = @_; my $bool; # checkers code # ... return $bool; } 1;
You can use your newly created checker in standard manner:
use Your::Custom::Checker qw( Your_Checker Your_Another_Checker ); my $foo = Validator::Var->new(); $foo->checker(Your_Checker); unless ( $foo->is_valid( $var ) ) { warn "variable does not passed Your_Chacker"; } my $bar = Validator::Var->new(); $bar->checker(Your_Another_Checker, $arg0, $arg1, $arg2 ); unless ( $bar->is_valid( $var ) ) { warn "variable does not passed Your_Another_Checker"; }
Fedor Semenov, <fedor.v.semenov at gmail.com>
<fedor.v.semenov at gmail.com>
To install Validator::Var, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Validator::Var
CPAN shell
perl -MCPAN -e shell install Validator::Var
For more information on module installation, please visit the detailed CPAN module installation guide.