Try Params::Validate for all your parameter validation needs.
You can do something like this:
my $nonempty = sub { shift() ne '' }; my $check_params = { client1 => sub { validate( @_, { var1 => { type => SCALAR, # a scalar ... callbacks => { # and is non-empty 'not empty' => $nonempty, }, }, var2 => { type => SCALAR, # a scalar ... callbacks => { # and is non-empty 'not empty' => $nonempty, }, }, } ); }, client2 => sub { # more of the same }, }; my %vars; my @varnames = $q->param; @vars{@varnames} = map { $q->param($_) } @varnames; $check_params->{$client}->(%vars);
With this approach you can check for type, regex matching or require that an arbitrary subroutine(s) return true. You may want to consider generating the hash of functions, instead of having it hard coded.
Params::Validate is very nice.
TGI says moo
In reply to Re: Validating the contents of scalars using an array based list
by TGI
in thread Validating the contents of scalars using an array based list
by JPaul
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |