Dios
view release on metacpan or search on metacpan
lib/Dios/Types.pm view on Meta::CPAN
warn "$VALUE not of type $TYPE. Proceeding anyway.";
}
use Dios::Types 'validator_for';
# Same, but prebuild validator for faster checking...
my $check = validator_for($TYPE, $DESC, @CONSTRAINTS);
for my $VALUE (@MANY_VALUES) {
$check->($VALUE);
}
=head1 DESCRIPTION
=head2 Standard types
This module implements type-checking for all of the following
types...
=head3 C<< Any >>
Accepts any Perl value.
=head3 C<< Bool >>
Accepts any Perl value that can be used as a boolean.
So effectively: any Perl value (just like C<Any>).
This type exists mainly to allow you to be more specific about
using a value as a boolean.
=head3 C<< Undef >>
Accepts any value that is undefined.
In other words, only the value C<undef>.
=head3 C<< Def >>
Accepts any value that is defined.
That is, any value except C<undef>.
=head3 C<< Value >>
Accepts any value is defined...but not a reference.
For example: C<7> or C<0x093FA3D7> or C<'word'>.
=head3 C<< Num >>
Accepts any value that is defined and also something for which
C<Scalar::Util::looks_like_number()> returns true.
However, unlike C<looks_like_number()>, this type does B<not> accept the
special value C<'NaN'>. (I mean, what part of "I<not> a number" does
that function not understand???)
Note that this type B<does> accept other special values like
"Inf"/"Infinity", as well as objects with numeric overloadings.
=head3 C<< Int >>
Accepts any value for which C<Scalar::Util::looks_like_number()> returns
true I<and> which also matches the regex:
/
\A
\s* # optional leading space
[+-]? # optional sign
(?: # either...
\d++ # digits
(\.0*)? # plus optional decimal zeroes
| # or...
(?i) inf(?:inity)? # some "infinity" variant
) #
\s* # optional trailing space
\Z
/x
Note that this type also accepts objects with numeric overloadings that
produce integers.
=head3 C<< Str >>
Accepts any value that is a string, or a non-reference that can be
converted to a string (e.g. a number), or any objects with a
stringification overloading.
=head3 C<< Empty >>
Accepts any value that is a string, or a non-reference that can be
converted to a string (e.g. a number), or any objects with a
stringification overloading, provided the resulting string in
each case is of zero length.
Also accepts empty arrays and hashes (see below).
=head3 C<< Class >>
Accepts any value that's a string that is the name of a symbol-table
entry containing at least one of: C<$VERSION>, C<@ISA>, or some
C<CODE> entry.
In other words, the value must be the name of a package that is
plausibly also a class...either because it has a version number, or
because it inherits from some other class, or because it has at least
one method defined.
=head3 C<< Ref >> and C<< Ref[T] >>
( run in 1.568 second using v1.01-cache-2.11-cpan-39bf76dae61 )