blib/lib/Net/IP/Match.pm

filter: Statementstmt 100% 32 / 32 Branchbran 75.0% 6 / 8 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 95.9% 47 / 49 CC 7 SCAR 15.1
CC
7
Cov
95%
__ANON__
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.5
↑ Summary
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 Net::IP::Match;
6 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 $Net::IP::Match::VERSION = '1.101700';
8 }
9  
10 # ABSTRACT: Efficiently match IP addresses against IP ranges
11 2 ▶use Filter::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶FILTER sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
13 1 s[\b __MATCH_IP \s* \( (.*?) \s* , \s* (.*?) \s* \) ]
14 [
15 5 my @n = eval $2;
16 5 my @t;
17 5 for (@n) {
18 8 my ($quad, $bits) = m!^(\d+\.\d+\.\d+\.\d+)(?:/(\d+))?!g;
19 8 ▶ my $matchbits = 32 - ($bits || 32);
Condition100%2/2
$bits || 32
l!l
71
MC/DC100%1/1
$bits || 32
$bits
Truth table100%2/2
A
A= $bits
Aresult
11
00
20 8 my $int = unpack("N", pack("C4", split(/\./, $quad)));
21 8 my $mask = $int >> $matchbits;
22 8 push @t => { mask => $mask, bits => $matchbits };
23 }
24  
25 5 my $unpack_code = qq!unpack("N", pack("C4", split(/\\./, $1)))!;
26  
27 # if there's only one ip range to match against, we don't need
28 # the temp variable and the do-block, so it's even faster
29  
30 5 ▶ if (@t == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@t == 1) { } 4 1 5
31 4 local $_ = shift @t;
32 "($_->{mask} == $unpack_code" .
33 4 ▶ ($_->{bits} ? " >> $_->{bits}" : "") . ")"
Branch: 1 branch
BranchTrueFalseTotal
$_->{'bits'} ? : 4 0 4
34 } else {
35 1 my $var = '$__tmp_match_ip';
36 1 my $cond = join ' || ' => map { "$_->{mask} == $var" .
37 4 ▶ ($_->{bits} ? " >> $_->{bits}" : "") } @t;
Branch: 1 branch
BranchTrueFalseTotal
$_->{'bits'} ? : 3 1 4
38 1 qq!do { my $var = $unpack_code; $cond }!
39 }
40  
41 ]gsex;
42 1 ▶ print if $::debug;
Branch: 1 branch
BranchTrueFalseTotal
if $main::debug 0 1 1
43 2 };
44 2 1;
45  
46  
47 __END__
↑ Summary