| 1 | =head1 NAME | ||||||||||
| 2 | |||||||||||
| 3 | Declare::Constraints::Simple::Library::Numerical - Numerical Constraints | ||||||||||
| 4 | |||||||||||
| 5 | =cut | ||||||||||
| 6 | |||||||||||
| 7 | package Declare::Constraints::Simple::Library::Numerical; | ||||||||||
| 8 | 13 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 13 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 13 | ▶ | use Declare::Constraints::Simple-Library; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 13 | ▶ | use Scalar::Util (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||
| 16 | |||||||||||
| 17 | # test for number-conformity | ||||||||||
| 18 | my $looks_like_number = IsNumber; | ||||||||||
| 19 | |||||||||||
| 20 | # only integers | ||||||||||
| 21 | my $is_int = IsInt; | ||||||||||
| 22 | |||||||||||
| 23 | =head1 DESCRIPTIONS | ||||||||||
| 24 | |||||||||||
| 25 | This library contains the constraints needed to validate numerical values. | ||||||||||
| 26 | |||||||||||
| 27 | =head1 CONSTRAINTS | ||||||||||
| 28 | |||||||||||
| 29 | =head2 IsNumber() | ||||||||||
| 30 | |||||||||||
| 31 | True if the value is a number according to L<Scalar::Util>s | ||||||||||
| 32 | C<looks_like_number>. | ||||||||||
| 33 | |||||||||||
| 34 | =cut | ||||||||||
| 35 | |||||||||||
| 36 | constraint 'IsNumber', | ||||||||||
| 37 | 6 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 6 | ▶ | return sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 39 | 6 | ▶ | return _false('Undefined Value') unless defined $_[0]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 5 | return _result(Scalar::Util::looks_like_number($_[0]), | |||||||||
| 41 | 'Does not look like Number'); | ||||||||||
| 42 | 6 | }; | |||||||||
| 43 | 13 | }; | |||||||||
| 44 | |||||||||||
| 45 | =head2 IsInt() | ||||||||||
| 46 | |||||||||||
| 47 | True if the value is an integer. | ||||||||||
| 48 | |||||||||||
| 49 | =cut | ||||||||||
| 50 | |||||||||||
| 51 | constraint 'IsInt', | ||||||||||
| 52 | 81 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 53 | 120 | ▶ | return sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 54 | 120 | ▶ | return _false('Undefined Value') unless defined $_[0]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 114 | return _result(scalar($_[0] =~ /^-?\d+$/), 'Not an Integer'); | |||||||||
| 56 | 81 | }; | |||||||||
| 57 | 13 | }; | |||||||||
| 58 | |||||||||||
| 59 | =head1 SEE ALSO | ||||||||||
| 60 | |||||||||||
| 61 | L<Declare::Constraints::Simple>, L<Declare::Constraints::Simple::Library> | ||||||||||
| 62 | |||||||||||
| 63 | =head1 AUTHOR | ||||||||||
| 64 | |||||||||||
| 65 | Robert 'phaylon' Sedlacek C<E<lt>phaylon@dunkelheit.atE<gt>> | ||||||||||
| 66 | |||||||||||
| 67 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 68 | |||||||||||
| 69 | This module is free software, you can redistribute it and/or modify it | ||||||||||
| 70 | under the same terms as perl itself. | ||||||||||
| 71 | |||||||||||
| 72 | =cut | ||||||||||
| 73 | |||||||||||
| 74 | 13 | 1; | |||||||||