Dry/Types/Number.pm

filter: Statementstmt 100% 24 / 24 Branchbran 100% 12 / 12 Conditioncond 90.0% 27 / 30 MC/DCmcdc 81.2% 13 / 16 Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 93.4% 86 / 92 CC 17 SCAR 17.9
CC
17
Cov
95%
Float
9.0
Int
6.0
Bool
4.0
CRAP 6.0
« Dry.pm ↑ Summary Dry/Types.pm »
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
BranchTrueFalseTotal
ref $_[0] || !($_[0] =~ /^[+\-]?(\d+)$/) and return 0 6 9 15
Condition100%3/3
ref $_[0] or not $_[0] =~ /^[+\-]?(\d+)$/
l!l&&r!l&&!r
339
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+)$/
ABresult
1X1
011
000
31 9 ▶ $_[1] and $1 and length $1 > $_[1] and return FAIL;
Branch: 1 branch
BranchTrueFalseTotal
$_[1] and $1 and length $1 > $_[1] and return 0 2 7 9
Condition83%5/6
$_[1] and $1 and length $1 > $_[1]
!ll&&!rl&&r
432
$_[1] and $1
!ll&&!rl&&r
405
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]
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
ref $_[0] || !($_[0] =~ /^[+\-]?(\d+(\.\d+)?)$/) and return 0 2 11 13
Condition100%3/3
ref $_[0] or not $_[0] =~ /^[+\-]?(\d+(\.\d+)?)$/
l!l&&r!l&&!r
1111
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+)?)$/
ABresult
1X1
011
000
42 11 ▶ $_[1] and $1 and length $1 > $_[1] and return FAIL;
Branch: 1 branch
BranchTrueFalseTotal
$_[1] and $1 and length $1 > $_[1] and return 0 2 9 11
Condition83%5/6
$_[1] and $1 and length $1 > $_[1]
!ll&&!rl&&r
542
$_[1] and $1
!ll&&!rl&&r
506
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]
ABCresult
0XX0
10X0
1100
1111
43 9 ▶ $_[2] and $2 and length $2 > $_[2] + 1 and return FAIL;
Branch: 1 branch
BranchTrueFalseTotal
$_[2] and $2 and length $2 > $_[2] + 1 and return 0 1 8 9
Condition83%5/6
$_[2] and $2 and length $2 > $_[2] + 1
!ll&&!rl&&r
711
$_[2] and $2
!ll&&!rl&&r
702
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
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if not ref $_[0] and "$_[0]" eq 0 || "$_[0]" eq 1 3 2 5
Condition100%6/6
not ref $_[0] and "$_[0]" eq 0 || "$_[0]" eq 1
!ll&&!rl&&r
113
"$_[0]" eq 0 or "$_[0]" eq 1
l!l&&r!l&&!r
121
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
ABCresult
0XX0
1000
11X1
1011
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__
« Dry.pm ↑ Summary Dry/Types.pm »