Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /proc/thread-self/root/usr/share/perl5/vendor_perl/Declare/Constraints/Simple/Library/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/thread-self/root/usr/share/perl5/vendor_perl/Declare/Constraints/Simple/Library/Numerical.pm
=head1 NAME

Declare::Constraints::Simple::Library::Numerical - Numerical Constraints

=cut

package Declare::Constraints::Simple::Library::Numerical;
use warnings;
use strict;

use Declare::Constraints::Simple-Library;

use Scalar::Util ();

=head1 SYNOPSIS

  # test for number-conformity
  my $looks_like_number = IsNumber;

  # only integers
  my $is_int = IsInt;

=head1 DESCRIPTIONS

This library contains the constraints needed to validate numerical values.

=head1 CONSTRAINTS

=head2 IsNumber()

True if the value is a number according to L<Scalar::Util>s 
C<looks_like_number>. 

=cut

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');
        };
    };

=head2 IsInt()

True if the value is an integer.

=cut

constraint 'IsInt',
    sub {
        return sub {
            return _false('Undefined Value') unless defined $_[0];
            return _result(scalar($_[0] =~ /^-?\d+$/), 'Not an Integer');
        };
    };

=head1 SEE ALSO

L<Declare::Constraints::Simple>, L<Declare::Constraints::Simple::Library>

=head1 AUTHOR

Robert 'phaylon' Sedlacek C<E<lt>phaylon@dunkelheit.atE<gt>>

=head1 LICENSE AND COPYRIGHT

This module is free software, you can redistribute it and/or modify it 
under the same terms as perl itself.

=cut

1;

Hry