Params::Validate

Params::Validate is a Perl module to validate method/function parameters.
Download

Params::Validate Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Dave Rolsky and Ilya Martynov
  • Publisher web site:
  • http://search.cpan.org/~drolsky/

Params::Validate Tags


Params::Validate Description

Params::Validate is a Perl module to validate method/function parameters. Params::Validate is a Perl module to validate method/function parameters.SYNOPSIS use Params::Validate qw(:all); # takes named params (hash or hashref) sub foo { validate( @_, { foo => 1, # mandatory bar => 0, # optional } ); } # takes positional params sub bar { # first two are mandatory, third is optional validate_pos( @_, 1, 1, 0 ); } sub foo2 { validate( @_, { foo => # specify a type { type => ARRAYREF }, bar => # specify an interface { can => }, baz => { type => SCALAR, # a scalar ... # ... that is a plain integer ... regex => qr/^d+$/, callbacks => { # ... and smaller than 90 'less than 90' => sub { shift() < 90 }, }, } } ); } sub with_defaults { my %p = validate( @_, { foo => 1, # required # $p{bar} will be 99 if bar is not # given. bar is now optional. bar => { default => 99 } } ); } sub pos_with_defaults { my @p = validate_pos( @_, 1, { default => 99 } ); } sub sets_options_on_call { my %p = validate_with ( params => @_, spec => { foo => { type SCALAR, default => 2 } }, normalize_keys => sub { $_ =~ s/^-//; lc $_ }, ); }The Params::Validate module allows you to validate method or function call parameters to an arbitrary level of specificity. At the simplest level, it is capable of validating the required parameters were given and that no unspecified additional parameters were passed in.It is also capable of determining that a parameter is of a specific type, that it is an object of a certain class hierarchy, that it possesses certain methods, or applying validation callbacks to arguments.Requirements:· Perl Requirements: · Perl


Params::Validate Related Software