Alien-wxWidgets
view release on metacpan or search on metacpan
inc/inc_IPC-Cmd/IPC/Cmd.pm view on Meta::CPAN
my($verbose,$cmd,$buffer);
my $tmpl = {
verbose => { default => $VERBOSE, store => \$verbose },
buffer => { default => \$def_buf, store => \$buffer },
command => { required => 1, store => \$cmd,
allow => sub { !ref($_[0]) or ref($_[0]) eq 'ARRAY' }
},
};
unless( check( $tmpl, \%hash, $VERBOSE ) ) {
Carp::carp(loc("Could not validate input: %1", Params::Check->last_error));
return;
};
print loc("Running [%1]...\n", (ref $cmd ? "@$cmd" : $cmd)) if $verbose;
### did the user pass us a buffer to fill or not? if so, set this
### flag so we know what is expected of us
### XXX this is now being ignored. in the future, we could add diagnostic
### messages based on this logic
#my $user_provided_buffer = $buffer == \$def_buf ? 0 : 1;
inc/inc_Params-Check/Params/Check.pm view on Meta::CPAN
my $ok = allow( $colour, [qw|blue green yellow|] );
my $error = Params::Check::last_error();
=head1 DESCRIPTION
Params::Check is a generic input parsing/checking mechanism.
It allows you to validate input via a template. The only requirement
is that the arguments must be named.
Params::Check can do the following things for you:
=over 4
=item *
Convert all keys to lowercase
inc/inc_Params-Check/Params/Check.pm view on Meta::CPAN
Enforce type integrity if required
=back
Most of Params::Check's power comes from its template, which we'll
discuss below:
=head1 Template
As you can see in the synopsis, based on your template, the arguments
provided will be validated.
The template can take a different set of rules per key that is used.
The following rules are available:
=over 4
=item default
This is the default value if none was provided by the user.
inc/inc_Params-Check/Params/Check.pm view on Meta::CPAN
my $args = check( { foo => { default => 1 }, $input );
my $x = $args->{foo};
You can alter the global variable $Params::Check::NO_DUPLICATES to
control whether the C<store>'d key will still be present in your
result set. See the L<Global Variables> section below.
=item allow
A set of criteria used to validate a particular piece of data if it
has to adhere to particular rules.
See the C<allow()> function for details.
=back
=head1 Functions
=head2 check( \%tmpl, \%args, [$verbose] );
inc/inc_Params-Check/Params/Check.pm view on Meta::CPAN
### check if they should be of a strict type, and if it is ###
if( ($tmpl{'strict_type'} || $STRICT_TYPE) and
(ref $args{$key} ne ref $tmpl{'default'})
) {
_store_error(loc(q|Key '%1' needs to be of type '%2'|,
$key, ref $tmpl{'default'} || 'SCALAR'), $verbose );
$wrong ||= 1;
next;
}
### check if we have an allow handler, to validate against ###
### allow() will report its own errors ###
if( exists $tmpl{'allow'} and
not allow($args{$key}, $tmpl{'allow'})
) {
### stringify the value in the error report -- we don't want dumps
### of objects, but we do want to see *roughly* what we passed
_store_error(loc(q|Key '%1' (%2) is of invalid type for '%3' |.
q|provided by %4|,
$key, "$args{$key}", _who_was_it(),
_who_was_it(1)), $verbose);
( run in 0.505 second using v1.01-cache-2.11-cpan-a5abf4f5562 )