| Declare-Constraints-Simple documentation | Contained in the Declare-Constraints-Simple distribution. |
Declare::Constraints::Simple::Library::Numerical - Numerical Constraints
# test for number-conformity my $looks_like_number = IsNumber; # only integers my $is_int = IsInt;
This library contains the constraints needed to validate numerical values.
True if the value is a number according to Scalar::Utils
looks_like_number.
True if the value is an integer.
Robert 'phaylon' Sedlacek <phaylon@dunkelheit.at>
This module is free software, you can redistribute it and/or modify it under the same terms as perl itself.
| Declare-Constraints-Simple documentation | Contained in the Declare-Constraints-Simple distribution. |
package Declare::Constraints::Simple::Library::Numerical; use warnings; use strict; use Declare::Constraints::Simple-Library; use Scalar::Util ();
constraint 'IsNumber', sub { return sub { return _false('Undefined Value') unless defined $_[0]; return _result(Scalar::Util::looks_like_number($_[0]), 'Does not look like Number'); }; };
constraint 'IsInt', sub { return sub { return _false('Undefined Value') unless defined $_[0]; return _result(scalar($_[0] =~ /^-?\d+$/), 'Not an Integer'); }; };
1;