blib/lib/JCM/Net/Patricia.pm

filter: Statementstmt 76.7% 178 / 232 Branchbran 36.9% 65 / 176 Conditioncond 20.0% 13 / 65 MC/DCmcdc 2.3% 1 / 43 Subroutinesub 78.7% 37 / 47 Podpod 77.7% 7 / 9 totaltotal 52.6% 301 / 572 CC 112 SCAR 26.4
CC
112
Cov
54%
add_integer
56.0
add_integer
56.0
exact
30.0
CRAP 14.0
↑ Summary Patricia.xs »
1 # JCM::Net::Patricia - Patricia Trie perl module for fast IP address lookups
2 # Copyright (C) 2000-2005 Dave Plonka
3 # Copyright (C) 2009 Dave Plonka & Philip Prindeville
4 # Parts Copyright(C) 2016 Joelle Maslak
5 # Parts Copyright(C) 2021 Joelle Maslak
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 # MA 02110-1301, USA.
21  
22 # Joelle Maslak <jmaslak@antelope.net>
23 # Dave Plonka <plonka@doit.wisc.edu>
24 # Philip Prindeville <philipp@redfish-solutions.com>
25 # Anton Berezin <tobez@tobez.org>
26  
27 package JCM::Net::Patricia;
28  
29 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 3 require 5.008;
33  
34 3 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 3 ▶use vars qw($VERSION @ISA @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
37 3 ▶use Socket qw(AF_INET AF_INET6);
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
40 3 require Exporter;
41 3 require DynaLoader;
42 3 @ISA = qw(Exporter DynaLoader);
43 3 @EXPORT = qw(AF_INET AF_INET6);
44 }
45  
46 3 ▶'$Revision: 1.05 $' =~ m/(\d+)\.(\d+)((_\d+)|)/ && ( $VERSION = "$1.$2$3");
Branch: 1 branch
BranchTrueFalseTotal
"\$Revision: 1.05 \$" =~ /(\d+)\.(\d+)((_\d+)|)/ and $JCM::Net::Patricia::VERSION = "$1.$2$3" 3 0 3
47  
48 3 bootstrap JCM::Net::Patricia $VERSION;
49  
50 7 ▶sub new {
Subroutine new: called CC=5 SCAR=16.7
Pod documented
51 7 my ($class, $type) = @_;
52  
53 7 ▶ $type ||= AF_INET;
Condition100%2/2
$type ||= 2
l!l
34
MC/DC100%1/1
$type ||= 2
$type
Truth table100%2/2
A
A= $type
Aresult
11
00
54  
55 7 ▶ if ($type == AF_INET) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 2) 4 3 7
56 4 return bless _new(32), 'JCM::Net::Patricia::AF_INET';
57 }
58  
59 3 ▶ if ($type == AF_INET6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 10) 3 0 3
60 3 ▶ if (JCM::Net::Patricia::have_ipv6()) {
Branch: 1 branch
BranchTrueFalseTotal
if (&have_ipv6()) { } 3 0 3
61 3 return bless _new(128), 'JCM::Net::Patricia::AF_INET6';
62 } else {
63 0 croak('IPv6 is not available on this platform');
64 }
65 }
66  
67 0 croak "new: unimplemented type";
68 }
69  
70 ##
71 ## Compat functions
72 ##
73  
74 69 ▶sub _ip_bits {
Subroutine _ip_bits: called CC=4 SCAR=13.9
75 69 my ($self, $str) = @_;
76 69 my $bits;
77  
78 69 ▶ if (ref ($self) eq 'JCM::Net::Patricia::AF_INET6') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self eq 'JCM::Net::Patricia::AF_INET6') { } 15 54 69
79 15 ▶ $bits = ($str =~ s|/(\d+)$||) ? $1 : 128;
Branch: 1 branch
BranchTrueFalseTotal
$str =~ s[/(\d+)$][] ? : 11 4 15
80 } else {
81 54 ▶ $bits = ($str =~ s|/(\d+)$||) ? $1 : 32;
Branch: 1 branch
BranchTrueFalseTotal
$str =~ s[/(\d+)$][] ? : 38 16 54
82 }
83 69 ($str,$bits);
84 }
85  
86 38 ▶sub add_string {
Subroutine add_string: called CC=4 SCAR=14.6
Pod documented
87 38 ▶ croak "add_string: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 38 38
Condition33%1/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
0038
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
88 38 my ($self,$str,$data) = @_;
89 38 ▶ $data = $str unless @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 2 8 30 38
90 38 $self->add($self->_ip_bits($str),$data);
91 }
92  
93 17 ▶sub match_string {
Subroutine match_string: called CC=2 SCAR=7.1
Pod documented
94 17 ▶ croak "match_string: wrong number of args" if (@_ != 2);
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 17 17
95 17 my ($self,$str) = @_;
96 17 $self->match($self->_ip_bits($str))
97 }
98  
99 8 ▶sub matching_prefix_string {
Subroutine matching_prefix_string: called CC=2 SCAR=7.1
Pod documented
100 8 ▶ croak "matching_prefix_string: wrong number of args" if (@_ != 2);
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 8 8
101 8 my ($self,$str) = @_;
102 8 $self->matching_prefix($self->_ip_bits($str))
103 }
104  
105 2 ▶sub match_exact_string {
Subroutine match_exact_string: called CC=2 SCAR=7.1
Pod documented
106 2 ▶ croak "match_exact_string: wrong number of args" if (@_ != 2);
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 2 2
107 2 my ($self,$str) = @_;
108 2 $self->exact($self->_ip_bits($str))
109 }
110  
111 6 ▶sub match_exact_integer {
Subroutine match_exact_integer: called CC=1 SCAR=0.0
Pod documented
112 6 shift->exact_integer(@_)
113 }
114  
115 4 ▶sub remove_string {
Subroutine remove_string: called CC=2 SCAR=7.1
Pod documented
116 4 ▶ croak "remove_string: wrong number of args" if (@_ != 2);
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 4 4
117 4 my ($self,$str) = @_;
118 4 $self->remove($self->_ip_bits($str))
119 }
120  
121 3 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
122 3 eval {
123 3 my $class = 'Net::CIDR::Lite';
124 3 eval "require $class";
125 };
126 3 ▶ last if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 3 3
127  
128 1 ▶ sub add_cidr {
Subroutine add_cidr: called CC=4 SCAR=14.0
Pod undocumented
129 1 ▶ croak "add_cidr: wrong number of args" if (@_ != 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 3 0 1 1
130 1 my ($self, $range, $data) = @_;
131 1 my $cidr = Net::CIDR::Lite->new();
132 1 $cidr->add_range($range);
133  
134 1 my @list = ();
135 1 for ($cidr->list()) {
136 2 ▶ push(@list, $_) if ($self->add_string($_, $data));
Branch: 1 branch
BranchTrueFalseTotal
if $self->add_string($_, $data) 2 0 2
137 }
138 1 @list;
139 }
140  
141 1 ▶ sub remove_cidr {
Subroutine remove_cidr: called CC=4 SCAR=14.0
Pod undocumented
142 1 ▶ croak "remove_cidr: wrong number of args" if (@_ != 2);
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 1 1
143 1 my ($self, $range) = @_;
144 1 my $cidr = Net::CIDR::Lite->new();
145 1 $cidr->add_range($range);
146  
147 1 my @list = ();
148 1 for ($cidr->list()) {
149 2 ▶ push(@list, $_) if ($self->remove_string($_));
Branch: 1 branch
BranchTrueFalseTotal
if $self->remove_string($_) 2 0 2
150 }
151 1 @list;
152 }
153 }
154  
155 ##
156 ## AF_INET
157 ##
158  
159 package JCM::Net::Patricia::AF_INET;
160  
161 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
162 3 ▶use Socket qw(AF_INET inet_aton inet_ntoa);
Subroutine BEGIN: called CC=1 SCAR=0.0
163 3 ▶use vars qw(@ISA @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
164  
165 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
166 3 require Exporter;
167 3 require DynaLoader;
168 3 @ISA = qw(Exporter DynaLoader JCM::Net::Patricia);
169 3 @EXPORT = qw(AF_INET);
170 }
171  
172 29 ▶sub add {
Subroutine add: called CC=9 SCAR=24.8
173 29 ▶ croak "add: wrong number of args" if (@_ < 2 || @_ > 4);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 4 0 29 29
Condition33%1/3
@_ < 2 or @_ > 4
l!l&&r!l&&!r
0029
MC/DC0%0/2
@_ < 2 or @_ > 4
@_ < 2 @_ > 4
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 4
ABresult
1X1
011
000
174 29 my ($self, $ip, $bits, $data) = @_;
175 29 ▶ croak("invalid key") if ( scalar(split( /[\/.]/, $ip )) != 4);
Branch: 1 branch
BranchTrueFalseTotal
if scalar split(m[[/.]], $ip, 0) != 4 1 28 29
176 28 ▶ croak("invalid key") if ( grep { /^0[0-9]/ } split( /[\/.]/, $ip ) );
Branch: 1 branch
BranchTrueFalseTotal
if grep {/^0[0-9]/;} split(m[[/.]], $ip, 0) 0 28 28
177 28 ▶ $data = (defined $bits ? "$ip/$bits" : $ip) if (@_ < 4);
Branch: 2 branches
BranchTrueFalseTotal
if @_ < 4 0 28 28
defined $bits ? : 0 0 0
178 28 my $packed = inet_aton($ip);
179 28 ▶ croak("invalid key") unless (defined $packed);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packed 0 28 28
180 28 ▶ $bits = 32 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 28 28
181 28 $self->SUPER::_add(AF_INET, $packed, $bits, $data);
182 }
183  
184 0 ▶sub add_integer {
Subroutine add_integer: not called CC=7 SCAR=40.3
185 0 ▶ croak "add_integer: wrong number of args" if (@_ < 2 || @_ > 4);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 4 0 0 0
Condition0%0/3
@_ < 2 or @_ > 4
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ < 2 or @_ > 4
@_ < 2 @_ > 4
Truth table0%0/3
A or B
A= @_ < 2B= @_ > 4
ABresult
1X1
011
000
186 0 my ($self, $num, $bits, $data) = @_;
187 0 my $packed = pack("N", $num);
188 0 my $ip = inet_ntoa($packed);
189 0 ▶ croak("invalid address") unless (defined $ip);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ip 0 0 0
190 0 ▶ $data = (defined $bits ? "$ip/$bits" : $ip) if (@_ < 4);
Branch: 2 branches
BranchTrueFalseTotal
if @_ < 4 0 0 0
defined $bits ? : 0 0 0
191 0 ▶ $bits = 32 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 0 0
192 0 $self->SUPER::_add(AF_INET, $packed, $bits, $data);
193 }
194  
195 6 ▶sub match_integer {
Subroutine match_integer: called CC=4 SCAR=15.6
196 6 ▶ croak "match_integer: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 6 6
Condition33%1/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
006
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
197 6 my ($self, $num, $bits) = @_;
198 6 ▶ $bits = 32 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 6 0 6
199 6 $self->SUPER::_match(AF_INET, pack("N",$num), $bits);
200 }
201  
202 0 ▶sub matching_prefix_integer {
Subroutine matching_prefix_integer: not called CC=4 SCAR=30.0
203 0 ▶ croak "matching_integer: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 0 0
Condition0%0/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table0%0/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
204 0 my ($self, $num, $bits) = @_;
205 0 ▶ $bits = 32 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 0 0
206 0 $self->SUPER::_matching_prefix(AF_INET, pack("N",$num), $bits);
207 }
208  
209 6 ▶sub exact_integer {
Subroutine exact_integer: called CC=4 SCAR=14.6
210 6 ▶ croak "exact_integer: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 6 6
Condition33%1/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
006
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
211 6 my ($self, $num, $bits) = @_;
212 6 ▶ $bits = 32 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 2 4 6
213 6 $self->SUPER::_exact(AF_INET, pack("N",$num), $bits);
214 }
215  
216 15 ▶sub match {
Subroutine match: called CC=7 SCAR=21.5
217 15 ▶ croak "match: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 15 15
Condition33%1/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
0015
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
218 15 my ($self, $ip, $bits) = @_;
219 15 ▶ croak("invalid key") if ( scalar(split( /[\/.]/, $ip )) != 4);
Branch: 1 branch
BranchTrueFalseTotal
if scalar split(m[[/.]], $ip, 0) != 4 0 15 15
220 15 ▶ croak("invalid key") if ( grep { /^0[0-9]/ } split( /[\/.]/, $ip ) );
Branch: 1 branch
BranchTrueFalseTotal
if grep {/^0[0-9]/;} split(m[[/.]], $ip, 0) 0 15 15
221 15 my $packed = inet_aton($ip);
222 15 ▶ croak("invalid key") unless (defined $packed);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packed 0 15 15
223 15 ▶ $bits = 32 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 15 15
224 15 $self->SUPER::_match(AF_INET, $packed, $bits);
225 }
226  
227 4 ▶sub matching_prefix {
Subroutine matching_prefix: called CC=7 SCAR=21.5
228 4 ▶ croak "matching_prefix: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 4 4
Condition33%1/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
004
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
229 4 my ($self, $ip, $bits) = @_;
230 4 ▶ croak("invalid key") if ( scalar(split( /[\/.]/, $ip )) != 4);
Branch: 1 branch
BranchTrueFalseTotal
if scalar split(m[[/.]], $ip, 0) != 4 0 4 4
231 4 ▶ croak("invalid key") if ( grep { /^0[0-9]/ } split( /[\/.]/, $ip ) );
Branch: 1 branch
BranchTrueFalseTotal
if grep {/^0[0-9]/;} split(m[[/.]], $ip, 0) 0 4 4
232 4 my $packed = inet_aton($ip);
233 4 ▶ croak("invalid key") unless (defined $packed);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packed 0 4 4
234 4 ▶ $bits = 32 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 4 4
235 4 $self->SUPER::_matching_prefix(AF_INET, $packed, $bits);
236 }
237  
238 2 ▶sub exact {
Subroutine exact: called CC=7 SCAR=21.5
239 2 ▶ croak "exact: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 2 2
Condition33%1/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
002
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
240 2 my ($self, $ip, $bits) = @_;
241 2 ▶ croak("invalid key") if ( scalar(split( /[\/.]/, $ip )) != 4);
Branch: 1 branch
BranchTrueFalseTotal
if scalar split(m[[/.]], $ip, 0) != 4 0 2 2
242 2 ▶ croak("invalid key") if ( grep { /^0[0-9]/ } split( /[\/.]/, $ip ) );
Branch: 1 branch
BranchTrueFalseTotal
if grep {/^0[0-9]/;} split(m[[/.]], $ip, 0) 0 2 2
243 2 my $packed = inet_aton($ip);
244 2 ▶ croak("invalid key") unless (defined $packed);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packed 0 2 2
245 2 ▶ $bits = 32 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 2 2
246 2 $self->SUPER::_exact(AF_INET, $packed, $bits);
247 }
248  
249 4 ▶sub remove {
Subroutine remove: called CC=7 SCAR=21.5
250 4 ▶ croak "remove: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 4 4
Condition33%1/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
004
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
251 4 my ($self, $ip, $bits) = @_;
252 4 ▶ croak("invalid key") if ( scalar(split( /[\/.]/, $ip )) != 4);
Branch: 1 branch
BranchTrueFalseTotal
if scalar split(m[[/.]], $ip, 0) != 4 0 4 4
253 4 ▶ croak("invalid key") if ( grep { /^0[0-9]/ } split( /[\/.]/, $ip ) );
Branch: 1 branch
BranchTrueFalseTotal
if grep {/^0[0-9]/;} split(m[[/.]], $ip, 0) 0 4 4
254 4 my $packed = inet_aton($ip);
255 4 ▶ croak("invalid key") unless (defined $packed);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packed 0 4 4
256 4 ▶ $bits = 32 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 4 4
257 4 $self->SUPER::_remove(AF_INET, $packed, $bits);
258 }
259  
260 0 ▶sub remove_integer {
Subroutine remove_integer: not called CC=4 SCAR=30.0
261 0 ▶ croak "remote_integer: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 0 0
Condition0%0/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table0%0/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
262 0 my ($self, $num, $bits) = @_;
263 0 ▶ $bits = 32 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 0 0
264 0 $self->SUPER::_remove(AF_INET, pack("N",$num), $bits);
265 }
266  
267 ##
268 ## AF_INET6
269 ##
270  
271 package JCM::Net::Patricia::AF_INET6;
272  
273 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
274 3 ▶use Socket qw(AF_INET6);
Subroutine BEGIN: called CC=1 SCAR=0.0
275 3 ▶use Socket6 qw(inet_pton inet_ntop);
Subroutine BEGIN: called CC=1 SCAR=0.0
276 3 ▶use vars qw(@ISA @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
277  
278 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
279 3 require Exporter;
280 3 require DynaLoader;
281 3 @ISA = qw(Exporter DynaLoader JCM::Net::Patricia);
282 3 @EXPORT = qw(AF_INET6);
283 }
284  
285 9 ▶sub add {
Subroutine add: called CC=7 SCAR=23.2
286 9 ▶ croak "add: wrong number of args" if (@_ < 2 || @_ > 4);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 4 0 9 9
Condition33%1/3
@_ < 2 or @_ > 4
l!l&&r!l&&!r
009
MC/DC0%0/2
@_ < 2 or @_ > 4
@_ < 2 @_ > 4
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 4
ABresult
1X1
011
000
287 9 my ($self, $ip, $bits, $data) = @_;
288 9 ▶ $data = (defined $bits ? "$ip/$bits" : $ip) if (@_ < 3);
Branch: 2 branches
BranchTrueFalseTotal
if @_ < 3 0 9 9
defined $bits ? : 0 0 0
289 9 my $packed = inet_pton(AF_INET6, $ip);
290 9 ▶ croak("invalid key") unless (defined $packed);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packed 0 9 9
291 9 ▶ $bits = 128 if (@_ < 4);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 4 0 9 9
292 9 $self->SUPER::_add(AF_INET6, $packed, $bits, $data);
293 }
294  
295 0 ▶sub add_integer {
Subroutine add_integer: not called CC=7 SCAR=40.3
296 0 ▶ croak "add_integer: wrong number of args" if (@_ < 2 || @_ > 4);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 4 0 0 0
Condition0%0/3
@_ < 2 or @_ > 4
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ < 2 or @_ > 4
@_ < 2 @_ > 4
Truth table0%0/3
A or B
A= @_ < 2B= @_ > 4
ABresult
1X1
011
000
297 0 my ($self, $num, $bits, $data) = @_;
298 0 my $packed = pack("N", $num);
299 0 my $ip = inet_ntop(AF_INET6, $packed);
300 0 ▶ croak("invalid address") unless (defined $ip);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ip 0 0 0
301 0 ▶ $data = (defined $bits ? "$ip/$bits" : $ip) if (@_ < 3);
Branch: 2 branches
BranchTrueFalseTotal
if @_ < 3 0 0 0
defined $bits ? : 0 0 0
302 0 ▶ $bits = 128 if (@_ < 4);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 4 0 0 0
303 0 $self->SUPER::_add(AF_INET6, $packed, $bits, $data);
304 }
305  
306 0 ▶sub match_integer {
Subroutine match_integer: not called CC=4 SCAR=30.0
307 0 ▶ croak "match_integer: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 0 0
Condition0%0/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table0%0/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
308 0 my ($self, $num, $bits) = @_;
309 0 ▶ $bits = 128 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 0 0
310 0 $self->SUPER::_match(AF_INET6, pack("N",$num), $bits);
311 }
312  
313 0 ▶sub matching_prefix_integer {
Subroutine matching_prefix_integer: not called CC=4 SCAR=30.0
314 0 ▶ croak "matching_prefix_integer: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 0 0
Condition0%0/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table0%0/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
315 0 my ($self, $num, $bits) = @_;
316 0 ▶ $bits = 128 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 0 0
317 0 $self->SUPER::_matching_prefix(AF_INET6, pack("N",$num), $bits);
318 }
319  
320 0 ▶sub exact_integer {
Subroutine exact_integer: not called CC=4 SCAR=30.0
321 0 ▶ croak "exact_integer: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 0 0
Condition0%0/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table0%0/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
322 0 my ($self, $num, $bits) = @_;
323 0 ▶ $bits = 128 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 0 0
324 0 $self->SUPER::_exact(AF_INET6, pack("N",$num), $bits);
325 }
326  
327 2 ▶sub match {
Subroutine match: called CC=5 SCAR=17.8
328 2 ▶ croak "match: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 2 2
Condition33%1/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
002
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
329 2 my ($self, $ip, $bits) = @_;
330 2 my $packed = inet_pton(AF_INET6, $ip);
331 2 ▶ croak("invalid key") unless (defined $packed);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packed 0 2 2
332 2 ▶ $bits = 128 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 2 2
333 2 $self->SUPER::_match(AF_INET6, $packed, $bits);
334 }
335  
336 4 ▶sub matching_prefix {
Subroutine matching_prefix: called CC=5 SCAR=17.8
337 4 ▶ croak "matching_prefix: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 4 4
Condition33%1/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
004
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
338 4 my ($self, $ip, $bits) = @_;
339 4 my $packed = inet_pton(AF_INET6, $ip);
340 4 ▶ croak("invalid key") unless (defined $packed);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packed 0 4 4
341 4 ▶ $bits = 128 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 4 4
342 4 $self->SUPER::_matching_prefix(AF_INET6, $packed, $bits);
343 }
344  
345 0 ▶sub exact {
Subroutine exact: not called CC=5 SCAR=34.0
346 0 ▶ croak "exact: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 0 0
Condition0%0/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table0%0/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
347 0 my ($self, $ip, $bits) = @_;
348 0 my $packed = inet_pton(AF_INET6, $ip);
349 0 ▶ croak("invalid key") unless (defined $packed);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packed 0 0 0
350 0 ▶ $bits = 128 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 0 0
351 0 $self->SUPER::_exact(AF_INET6, $packed, $bits);
352 }
353  
354 0 ▶sub remove {
Subroutine remove: not called CC=5 SCAR=34.0
355 0 ▶ croak "remove: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 0 0
Condition0%0/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table0%0/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
356 0 my ($self, $ip, $bits) = @_;
357 0 my $packed = inet_pton(AF_INET6, $ip);
358 0 ▶ croak("invalid key") unless (defined $packed);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packed 0 0 0
359 0 ▶ $bits = 128 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 0 0
360 0 $self->SUPER::_remove(AF_INET6, $packed, $bits);
361 }
362  
363 0 ▶sub remove_integer {
Subroutine remove_integer: not called CC=4 SCAR=30.0
364 0 ▶ croak "remote_integer: wrong number of args" if (@_ < 2 || @_ > 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 0 0
Condition0%0/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table0%0/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
365 0 my ($self, $num, $bits) = @_;
366 0 ▶ $bits = 128 if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 0 0
367 0 $self->SUPER::_remove(AF_INET6, pack("N",$num), $bits);
368 }
369  
370 3 1;
371 __END__
↑ Summary Patricia.xs »