| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | #* | ||||||||||||||||||||||||||||||||||||||||||
| 3 | #* Info: Number types definitions module | ||||||||||||||||||||||||||||||||||||||||||
| 4 | #* Author: Pawel Guspiel (neo77) <neo@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 5 | #* | ||||||||||||||||||||||||||||||||||||||||||
| 6 | #* This module keeps validation functions. You can of course add your modules which uses this and will add additional checks | ||||||||||||||||||||||||||||||||||||||||||
| 7 | #* Build in types for Params::Dry | ||||||||||||||||||||||||||||||||||||||||||
| 8 | #* | ||||||||||||||||||||||||||||||||||||||||||
| 9 | package Params::Dry::Types::Number; | ||||||||||||||||||||||||||||||||||||||||||
| 10 | { | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | # --- version --- | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | our $VERSION = 1.20_03; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | #=------------------------------------------------------------------------ { use, constants } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 4 | ▶ | use Params::Dry::Types qw(:const); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | #=------------------------------------------------------------------------ { module public functions } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | #=------ | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # Int | ||||||||||||||||||||||||||||||||||||||||||
| 26 | #=------ | ||||||||||||||||||||||||||||||||||||||||||
| 27 | #* int type check Int[3] - no more than 999 | ||||||||||||||||||||||||||||||||||||||||||
| 28 | #* RETURN: PASS if test pass otherwise FAIL | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 15 | ▶ | sub Int { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Int: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 15 | ▶ | ( ref( $_[0] ) or $_[0] !~ /^[+\-]?(\d+)$/ ) and return FAIL; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $_[0] or not $_[0] =~ /^[+\-]?(\d+)$/
MC/DC100%2/2
ref $_[0] or not $_[0] =~ /^[+\-]?(\d+)$/
ref $_[0]
not $_[0] =~ /^[+\-]?(\d+)$/
Truth table100%3/3
A or not(B)
A= ref $_[0]B= not $_[0] =~ /^[+\-]?(\d+)$/
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 9 | ▶ | $_[1] and $1 and length $1 > $_[1] and return FAIL; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$_[1] and $1 and length $1 > $_[1]
$_[1] and $1
MC/DC66%2/3
$_[1] and $1 and length $1 > $_[1]
$_[1]
$1
length $1 > $_[1]
Truth table75%3/4
A and B and C
A= $_[1]B= $1C= length $1 > $_[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 7 | PASS; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } #+ end of: sub Int | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | #=-------- | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # Float | ||||||||||||||||||||||||||||||||||||||||||
| 37 | #=-------- | ||||||||||||||||||||||||||||||||||||||||||
| 38 | #* float type check | ||||||||||||||||||||||||||||||||||||||||||
| 39 | #* RETURN: PASS if test pass otherwise FAIL | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 13 | ▶ | sub Float { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Float: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 13 | ▶ | ( ref( $_[0] ) or $_[0] !~ /^[+\-]?(\d+(\.\d+)?)$/ ) and return FAIL; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $_[0] or not $_[0] =~ /^[+\-]?(\d+(\.\d+)?)$/
MC/DC100%2/2
ref $_[0] or not $_[0] =~ /^[+\-]?(\d+(\.\d+)?)$/
ref $_[0]
not $_[0] =~ /^[+\-]?(\d+(\.\d+)?)$/
Truth table100%3/3
A or not(B)
A= ref $_[0]B= not $_[0] =~ /^[+\-]?(\d+(\.\d+)?)$/
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 11 | ▶ | $_[1] and $1 and length $1 > $_[1] and return FAIL; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$_[1] and $1 and length $1 > $_[1]
$_[1] and $1
MC/DC66%2/3
$_[1] and $1 and length $1 > $_[1]
$_[1]
$1
length $1 > $_[1]
Truth table75%3/4
A and B and C
A= $_[1]B= $1C= length $1 > $_[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 9 | ▶ | $_[2] and $2 and length $2 > $_[2] + 1 and return FAIL; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$_[2] and $2 and length $2 > $_[2] + 1
$_[2] and $2
MC/DC66%2/3
$_[2] and $2 and length $2 > $_[2] + 1
$_[2]
$2
length $2 > $_[2] + 1
Truth table75%3/4
A and B and C
A= $_[2]B= $2C= length $2 > $_[2] + 1
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 8 | PASS; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } #+ end of: sub Float | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | #=------- | ||||||||||||||||||||||||||||||||||||||||||
| 48 | # Bool | ||||||||||||||||||||||||||||||||||||||||||
| 49 | #=------- | ||||||||||||||||||||||||||||||||||||||||||
| 50 | #* Bool type check | ||||||||||||||||||||||||||||||||||||||||||
| 51 | #* RETURN: PASS if test pass otherwise FAIL | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 5 | ▶ | sub Bool { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Bool: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 5 | ▶ | return PASS if !ref( $_[0] ) and ( "$_[0]" eq '0' or "$_[0]" eq 1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not ref $_[0] and "$_[0]" eq 0 || "$_[0]" eq 1
"$_[0]" eq 0 or "$_[0]" eq 1
MC/DC100%3/3
not ref $_[0] and "$_[0]" eq 0 || "$_[0]" eq 1
not ref $_[0]
"$_[0]" eq 0
"$_[0]" eq 1
Truth table100%4/4
not(A) and B or C
A= not ref $_[0]B= "$_[0]" eq 0C= "$_[0]" eq 1
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | FAIL; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } #+ end of: sub Bool | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | 0115 && 0x4d; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | #+ End of Params::Dry::Types::Number | ||||||||||||||||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||||||||||||||||