| 1 | package Validator::LIVR::Rules::Numeric; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Scalar::Util qw/looks_like_number/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | our $VERSION = '2.22'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 20 | ▶ | sub integer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
integer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 17 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 17 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 17 | ▶ | return if !defined($value) || $value eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $value or $value eq ""
MC/DC100%2/2
not defined $value or $value eq ""
not defined $value
$value eq ""
Truth table100%3/3
not(A) or B
A= not defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 13 | ▶ | return 'FORMAT_ERROR' if ref($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 9 | ▶ | return 'NOT_INTEGER' unless looks_like_number($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | ▶ | return 'NOT_INTEGER' unless $value =~ /^\-?\d+$/ && looks_like_number($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$value =~ /^\-?\d+$/ and &looks_like_number($value)
MC/DC50%1/2
$value =~ /^\-?\d+$/ and &looks_like_number($value)
$value =~ /^\-?\d+$/
&looks_like_number($value)
Truth table66%2/3
A and B
A= $value =~ /^\-?\d+$/B= &looks_like_number($value)
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 20 | }; | |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 174 | ▶ | sub positive_integer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
positive_integer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 170 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 170 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 170 | ▶ | return if !defined($value) || $value eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $value or $value eq ""
MC/DC100%2/2
not defined $value or $value eq ""
not defined $value
$value eq ""
Truth table100%3/3
not(A) or B
A= not defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 156 | ▶ | return 'FORMAT_ERROR' if ref($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 152 | ▶ | return 'NOT_POSITIVE_INTEGER' unless looks_like_number($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 133 | ▶ | return 'NOT_POSITIVE_INTEGER' unless $value =~ /^\d+$/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$value =~ /^\d+$/ and &looks_like_number($value) and $value > 0
$value =~ /^\d+$/ and &looks_like_number($value)
MC/DC66%2/3
$value =~ /^\d+$/ and &looks_like_number($value) and $value > 0
$value =~ /^\d+$/
&looks_like_number($value)
$value > 0
Truth table75%3/4
A and B and C
A= $value =~ /^\d+$/B= &looks_like_number($value)C= $value > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | && looks_like_number($value) | ||||||||||||||||||||||||||||||||||||||||||
| 32 | && $value > 0; | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 113 | return; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 174 | }; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 37 | ▶ | sub decimal { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decimal: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 44 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 44 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 44 | ▶ | return if !defined($value) || $value eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $value or $value eq ""
MC/DC100%2/2
not defined $value or $value eq ""
not defined $value
$value eq ""
Truth table100%3/3
not(A) or B
A= not defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 41 | ▶ | return 'FORMAT_ERROR' if ref($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 37 | ▶ | return 'NOT_DECIMAL' unless looks_like_number($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 32 | ▶ | return 'NOT_DECIMAL' unless $value =~ /^\-?[\d.]+$/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$value =~ /^\-?[\d.]+$/ and &looks_like_number($value)
MC/DC0%0/2
$value =~ /^\-?[\d.]+$/ and &looks_like_number($value)
$value =~ /^\-?[\d.]+$/
&looks_like_number($value)
Truth table33%1/3
A and B
A= $value =~ /^\-?[\d.]+$/B= &looks_like_number($value)
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | && looks_like_number($value); | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 32 | return; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 37 | }; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 16 | ▶ | sub positive_decimal { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
positive_decimal: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 16 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 16 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 16 | ▶ | return if !defined($value) || $value eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $value or $value eq ""
MC/DC50%1/2
not defined $value or $value eq ""
not defined $value
$value eq ""
Truth table66%2/3
not(A) or B
A= not defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 14 | ▶ | return 'FORMAT_ERROR' if ref($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 10 | ▶ | return 'NOT_POSITIVE_DECIMAL' unless looks_like_number($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 8 | ▶ | return 'NOT_POSITIVE_DECIMAL' unless $value =~ /^\-?[\d.]+$/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$value =~ /^\-?[\d.]+$/ and &looks_like_number($value) and $value > 0
$value =~ /^\-?[\d.]+$/ and &looks_like_number($value)
MC/DC33%1/3
$value =~ /^\-?[\d.]+$/ and &looks_like_number($value) and $value > 0
$value =~ /^\-?[\d.]+$/
&looks_like_number($value)
$value > 0
Truth table50%2/4
A and B and C
A= $value =~ /^\-?[\d.]+$/B= &looks_like_number($value)C= $value > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | && looks_like_number($value) | ||||||||||||||||||||||||||||||||||||||||||
| 63 | && $value > 0; | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 16 | }; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 16 | ▶ | sub max_number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_number: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 16 | my $max_number = shift; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 24 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 24 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 24 | ▶ | return if !defined($value) || $value eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $value or $value eq ""
MC/DC50%1/2
not defined $value or $value eq ""
not defined $value
$value eq ""
Truth table66%2/3
not(A) or B
A= not defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 22 | ▶ | return 'FORMAT_ERROR' if ref($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 18 | ▶ | return 'NOT_NUMBER' unless looks_like_number($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 17 | ▶ | return 'TOO_HIGH' if $value > $max_number; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 13 | return; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 16 | }; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 52 | ▶ | sub min_number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
min_number: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 52 | my $min_number = shift; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 46 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 46 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 46 | ▶ | return if !defined($value) || $value eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $value or $value eq ""
MC/DC100%2/2
not defined $value or $value eq ""
not defined $value
$value eq ""
Truth table100%3/3
not(A) or B
A= not defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 42 | ▶ | return 'FORMAT_ERROR' if ref($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 38 | ▶ | return 'NOT_NUMBER' unless looks_like_number($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 37 | ▶ | return 'TOO_LOW' if $value < $min_number; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 28 | return; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 52 | }; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 27 | ▶ | sub number_between { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
number_between: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 27 | my ($min_number, $max_number) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 28 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 28 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 28 | ▶ | return if !defined($value) || $value eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $value or $value eq ""
MC/DC50%1/2
not defined $value or $value eq ""
not defined $value
$value eq ""
Truth table66%2/3
not(A) or B
A= not defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 26 | ▶ | return 'FORMAT_ERROR' if ref($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 22 | ▶ | return 'NOT_NUMBER' unless looks_like_number($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 21 | ▶ | return 'TOO_LOW' if $value < $min_number; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 18 | ▶ | return 'TOO_HIGH' if $value > $max_number; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 15 | return; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 27 | }; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | Validator::LIVR::Rules::Numeric - Numeric rules of Validator::LIVR: integer, positive_integer, decimal, positive_decimal, min_number, max_number and number_between | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | This module has the code of the numeric rules, which are documented in | ||||||||||||||||||||||||||||||||||||||||||
| 124 | L<Validator::LIVR/Numeric rules>. | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | Each sub is the builder of the rule with the same name. The code is a good | ||||||||||||||||||||||||||||||||||||||||||
| 127 | example for L<writing your own rules|Validator::LIVR/WRITING RULES IN PERL>. | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | =cut | ||||||||||||||||||||||||||||||||||||||||||