Params::Util#
Check parameters: each function returns its argument if it is a value of the kind the name says, and undef if not.
_STRING is a defined, non-empty, non-reference value; _NUMBER one that is or looks like a number. _SCALAR, _ARRAY, _HASH and _CODE are unblessed references to such a thing, the plain names non-empty, the 0 forms (_SCALAR0, _ARRAY0, _HASH0) empty too. _ARRAYLIKE, _HASHLIKE and _CODELIKE also accept objects that overload @{}, %{} or &{}. _REGEX is a compiled regex, _INSTANCE($obj, $class) an object that isa $class.
These are the compiled functions of Params::Util 1.102; its Params/Util.pm and Params/Util/PP.pm are used unchanged, and the functions it has no compiled form of (_IDENTIFIER, _CLASS, _POSINT, _SET, _HANDLE, …) come from Params::Util::PP.
Synopsis#
use Params::Util qw(_STRING _HASH _INSTANCE);
sub new {
my $class = shift;
my $name = _STRING(shift) or die "no name";
my $opts = _HASH(shift) // {};
my $log = _INSTANCE(shift, 'Log') or die "no logger";
...
}
Differences from upstream#
None.
Modules#
Params::Util::PP- PurePerl Params::Util routines
Functions#
Value checks#
_STRING#
The value itself if it is a defined, non-reference string of at least one character (a number counts, in its string form), else undef.
Synopsis
my $name = _STRING($in) or die "need a name";
_NUMBER#
The value itself if it is a number, or a non-empty string that looks like one (looks_like_number), else undef.
Synopsis
my $n = _NUMBER($in) // die "not a number";
Reference checks#
_SCALAR0#
An unblessed reference to a scalar, whatever it holds, else undef.
_SCALAR#
An unblessed reference to a scalar holding a non-empty string, else undef.
Synopsis
my $text = _SCALAR($ref) or die "need a reference to some text";
_REGEX#
A compiled regex (qr//), else undef.
_ARRAY0#
An unblessed array reference, empty or not, else undef.
_ARRAY#
An array reference with at least one element, else undef.
Synopsis
my $list = _ARRAY($in) or die "need a non-empty list";
_ARRAYLIKE#
An array reference, or an object that overloads @{}, else undef.
_HASH0#
A hash reference, empty or not, else undef.
_HASH#
A hash reference with at least one key, else undef.
Synopsis
my $opts = _HASH($in) || {};
_HASHLIKE#
A hash reference, or an object that overloads %{}, else undef.
_CODE#
A code reference, else undef.
_CODELIKE#
A code reference, or an object that overloads &{}, else undef.
_INSTANCE#
An object that isa the class given (its own isa method decides), else undef; an empty class name is never matched.
Synopsis
my $dbh = _INSTANCE($in, 'DBI::db') or die "need a database handle";