Zonemaster/Engine/Validation.pm

filter: Statementstmt 69.2% 27 / 39 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 80.0% 8 / 10 Podpod 100% 2 / 2 totaltotal 44.5% 37 / 83 CC 11 SCAR 32.4
CC
11
Cov
43%
validate_ipv4
42.0
validate_ipv6
42.0
BEGIN
1.0
CRAP 25.6
« Zonemaster/Engine/Nameserver/Cache/RedisCache.pm ↑ Summary Zonemaster/Engine/NameserverSet.pm »
1 package Zonemaster::Engine::Validation;
2  
3 1 ▶use v5.16.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use version; our $VERSION = version->declare("v1.0.0");
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 our @EXPORT_OK = qw[
11 validate_ipv4
12 validate_ipv6
13 ];
14 1 our %EXPORT_TAGS = ( all => \@EXPORT_OK );
15  
16 ## no critic (Modules::ProhibitAutomaticExportation)
17 1 our @EXPORT = qw[
18 validate_ipv4
19 validate_ipv6
20 ];
21 }
22  
23 1 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Net::IP::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 1 ▶use Zonemaster::Engine::Constants qw[:ip];
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 1 Readonly our $IPV4_RE => qr/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/;
29 1 Readonly our $IPV6_RE => qr/^[0-9a-f:]*:[0-9a-f:]+(:[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})?$/i;
30  
31 0 ▶sub validate_ipv4 {
Subroutine validate_ipv4: not called CC=6 SCAR=37.4
Pod documented
32 0 my ( $ip ) = @_;
33  
34 0 ▶ if ( defined $ip and $ip ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ip and $ip ne "") 0 0 0
Condition0%0/3
defined $ip and $ip ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ip and $ip ne ""
defined $ip $ip ne ""
Truth table0%0/3
A and B
A= defined $ipB= $ip ne ""
ABresult
0X0
100
111
35 0 ▶ if ( Net::IP::XS->new( $ip ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Net::IP::XS"->new($ip)) 0 0 0
36 0 ▶ if ( Net::IP::XS::ip_is_ipv4( $ip ) and $ip =~ /($IPV4_RE)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Net::IP::XS::ip_is_ipv4($ip) and $ip =~ /($Zonemaster::Engine::Validation::IPV4_RE)/u) 0 0 0
Condition0%0/3
&Net::IP::XS::ip_is_ipv4($ip) and $ip =~ /($Zonemaster::Engine::Validation::IPV4_RE)/u
!ll&&!rl&&r
000
MC/DC0%0/2
&Net::IP::XS::ip_is_ipv4($ip) and $ip =~ /($Zonemaster::Engine::Validation::IPV4_RE)/u
&Net::IP::XS::ip_is_ipv4($ip) $ip =~ /($Zonemaster::Engine::Validation::IPV4_RE)/u
Truth table0%0/3
A and B
A= &Net::IP::XS::ip_is_ipv4($ip)B= $ip =~ /($Zonemaster::Engine::Validation::IPV4_RE)/u
ABresult
0X0
100
111
37 0 return 1;
38 }
39 }
40 }
41  
42 0 return 0;
43 }
44  
45 0 ▶sub validate_ipv6 {
Subroutine validate_ipv6: not called CC=6 SCAR=37.4
Pod documented
46 0 my ( $ip ) = @_;
47  
48 0 ▶ if ( defined $ip and $ip ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ip and $ip ne "") 0 0 0
Condition0%0/3
defined $ip and $ip ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ip and $ip ne ""
defined $ip $ip ne ""
Truth table0%0/3
A and B
A= defined $ipB= $ip ne ""
ABresult
0X0
100
111
49 0 ▶ if ( Net::IP::XS->new( $ip ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Net::IP::XS"->new($ip)) 0 0 0
50 0 ▶ if ( Net::IP::XS::ip_is_ipv6( $ip ) and $ip =~ /($IPV6_RE)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Net::IP::XS::ip_is_ipv6($ip) and $ip =~ /($Zonemaster::Engine::Validation::IPV6_RE)/u) 0 0 0
Condition0%0/3
&Net::IP::XS::ip_is_ipv6($ip) and $ip =~ /($Zonemaster::Engine::Validation::IPV6_RE)/u
!ll&&!rl&&r
000
MC/DC0%0/2
&Net::IP::XS::ip_is_ipv6($ip) and $ip =~ /($Zonemaster::Engine::Validation::IPV6_RE)/u
&Net::IP::XS::ip_is_ipv6($ip) $ip =~ /($Zonemaster::Engine::Validation::IPV6_RE)/u
Truth table0%0/3
A and B
A= &Net::IP::XS::ip_is_ipv6($ip)B= $ip =~ /($Zonemaster::Engine::Validation::IPV6_RE)/u
ABresult
0X0
100
111
51 0 return 1;
52 }
53 }
54 }
55  
56 0 return 0;
57 }
58  
59 1 1;
60  
61 =head1 NAME
62  
63 Zonemaster::Engine::Validation - validation functions for other Zonemaster modules
64  
65 =head1 SYNOPSIS
66  
67 use Zonemaster::Engine::Validation qw( validate_ipv4 validate_ipv6 );
68 my $ip_is_valid = validate_ipv4( $ip_address );
69  
70 =head1 EXPORTED FUNCTIONS
71  
72 =over
73  
74 =item validate_ipv4
75  
76 my $ip_is_valid = validate_ipv4( $ip_address );
77  
78 Checks if the given IP address is a valid IPv4 address.
79  
80 Takes a string (IP address).
81  
82 Returns a boolean.
83  
84 =item validate_ipv6
85  
86 my $ip_is_valid = validate_ipv6( $ip_address );
87  
88 Checks if the given IP address is a valid IPv6 address.
89  
90 Takes a string (IP address).
91  
92 Returns a boolean.
93  
94 =back
« Zonemaster/Engine/Nameserver/Cache/RedisCache.pm ↑ Summary Zonemaster/Engine/NameserverSet.pm »