 | Params::Validate
use Params::Validate qw(:all);
sub foo { validate( @_, { foo => { type => ARRAYREF }, # specify a type bar => { type => SCALAR, # a scalar ... regex => qr/^\d+$/, callbacks => # ... that is a plain integer ... { 'numbers only' => sub { shift() =~ /^\d+$/ }, # ... and smaller than 90 'less than 90' => sub { shift() < 90 }, }, } } ); }
sub foo2 { validate( @_, { foo => 1, # required # $p{bar} will be 99 if foo is not # given. bar is now optional. bar => { default => 99 } } ); }
sub sets_options_on_call { my %p = validate_with( params => \@_, spec => { foo => { type SCALAR, default => 2 } }, ignore_case => 1, strip_leading => '-', ); }
|
|