| 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
MC/DC100%1/1
$bits || 32
$bits
Truth table100%2/2
A
A= $bits
| |||||||||||||
| 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
| |||||||||||||
| 31 | 4 | local $_ = shift @t; | |||||||||||
| 32 | "($_->{mask} == $unpack_code" . | ||||||||||||
| 33 | 4 | ▶ | ($_->{bits} ? " >> $_->{bits}" : "") . ")" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 38 | 1 | qq!do { my $var = $unpack_code; $cond }! | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | ]gsex; | ||||||||||||
| 42 | 1 | ▶ | print if $::debug; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | 2 | }; | |||||||||||
| 44 | 2 | 1; | |||||||||||
| 45 | |||||||||||||
| 46 | |||||||||||||
| 47 | __END__ | ||||||||||||