Net/IPAddress/IPv4.pm

filter: Statementstmt 100% 31 / 31 Branchbran 70.0% 7 / 10 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 88.5% 54 / 61 CC 7 SCAR 8.1
CC
7
Cov
89%
is_internal
3.1
is_valid_normalized_value
3.0
normalize
3.0
CRAP 2.2
↑ Summary Net/IPAddress/IPv6.pm »
1 2 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Data::Semantic::Net::IPAddress::IPv4;
6 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 $Data::Semantic::Net::IPAddress::IPv4::VERSION = '1.101760';
8 }
9 # ABSTRACT: Semantic data class for IPv4 addresses
10 2 ▶use Net::IP qw(ip_is_ipv4 ip_iptype ip_iptobin);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use parent qw(Data::Semantic::Net::IPAddress);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # update RESERVED IPv4 ranges according to RFC 5737
14 2 my @ranges = qw(198.51.100.0/24 203.0.113.0/24);
15 2 for my $range (@ranges) {
16 4 ▶ my $ip = Net::IP->new($range) or die Net::IP::Error();
Branch: 1 branch
BranchTrueFalseTotal
my $ip = "Net::IP"->new($range) or die Net::IP::Error() 4 0 4
17 4 my $prefix = substr $ip->binip, 0, $ip->prefixlen;
18 4 $Net::IP::IPv4ranges{ $prefix } = 'RESERVED';
19 }
20  
21 26 ▶sub is_valid_normalized_value {
Subroutine is_valid_normalized_value: called CC=3 SCAR=11.1
Pod documented
22 26 my ($self, $value) = @_;
23  
24 # Net::IP has a "nice" DWIM feature which
25 # autocompletes IPs with less than 4 octets, so check for that
26 26 ▶ $self->SUPER::is_valid_normalized_value($value)
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::is_valid_normalized_value($value) and ip_is_ipv4($value) and (my @dummy = split(/\./, $value, 0)) == 4 14 12 26
Condition66%2/3
$self->SUPER::is_valid_normalized_value($value) and ip_is_ipv4($value)
!ll&&!rl&&r
12014
MC/DC50%1/2
$self->SUPER::is_valid_normalized_value($value) and ip_is_ipv4($value)
$self->SUPER::is_valid_normalized_value($value) ip_is_ipv4($value)
Truth table66%2/3
A and B
A= $self->SUPER::is_valid_normalized_value($value)B= ip_is_ipv4($value)
ABresult
0X0
100
111
27 && ip_is_ipv4($value)
28 && (my @dummy = split(/\./, $value)) == 4;
29 }
30  
31 13 ▶sub is_internal {
Subroutine is_internal: called CC=3 SCAR=11.4
Pod documented
32 13 my ($self, $value) = @_;
33 13 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 13 13
34  
35 # Net::IP::ip_iptype needs the IP in binary, although this is not
36 # documented.
37 13 ▶ my $type = ip_iptype(ip_iptobin($value, 4), 4) || 'PUBLIC';
Condition50%1/2
ip_iptype(ip_iptobin($value, 4), 4) || 'PUBLIC'
l!l
130
MC/DC0%0/1
ip_iptype(ip_iptobin($value, 4), 4) || 'PUBLIC'
ip_iptype(ip_iptobin($value, 4), 4)
Truth table50%1/2
A
A= ip_iptype(ip_iptobin($value, 4), 4)
Aresult
11
00
38 13 $type ne 'PUBLIC';
39 }
40  
41 30 ▶sub normalize {
Subroutine normalize: called CC=3 SCAR=11.0
Pod documented
42 30 my ($self, $value) = @_;
43 30 ▶ return undef unless (my @dummy = split(/\./, $value)) == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless (my @dummy = split(/\./, $value, 0)) == 4 3 27 30
44 # omit leading zeroes in octets, e.g., 213.160.065.064 -> 213.160.65.64
45 27 ▶ my $ip = Net::IP->new($value) or die Net::IP::Error();
Branch: 1 branch
BranchTrueFalseTotal
my $ip = "Net::IP"->new($value) or die Net::IP::Error() 27 0 27
46 27 $ip->ip;
47 }
48  
49 2 1;
50  
51  
52 __END__
↑ Summary Net/IPAddress/IPv6.pm »