Works/Network.pm

filter: Statementstmt 98.4% 194 / 197 Branchbran 87.9% 51 / 58 Conditioncond 79.4% 31 / 39 MC/DCmcdc 59.0% 13 / 22 Subroutinesub 94.8% 37 / 39 Podpod 78.5% 11 / 14 totaltotal 91.3% 337 / 369 CC 45 SCAR 14.0
CC
45
Cov
94%
_compare_overload
9.4
new_from_string
7.0
_remove_reserved_subnets_from_range
7.0
CRAP 4.0
↑ Summary Works/Util.pm »
1 package Net::Works::Network;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = '0.22';
7  
8 3 ▶use Carp qw( confess );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use List::AllUtils qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Math::Int128 qw( uint128 );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Net::Works::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Net::Works::Types qw( IPInt PrefixLength NetWorksAddress Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 use Net::Works::Util
14 3 ▶ qw( _integer_address_to_string _string_address_to_integer );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Socket 1.99 qw( inet_pton AF_INET AF_INET6 );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # Using this currently breaks overloading - see
21 # https://rt.cpan.org/Ticket/Display.html?id=50938
22 #
23 #use namespace::autoclean;
24  
25 3 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
26 3 q{""} => '_overloaded_as_string',
27 '<=>' => '_compare_overload',
28 'cmp' => '_compare_overload',
29 3 );
30  
31 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 3 with 'Net::Works::Role::IP';
34  
35 3 has first => (
36 is => 'ro',
37 isa => NetWorksAddress,
38 init_arg => undef,
39 lazy => 1,
40 builder => '_build_first',
41 );
42  
43 3 has last => (
44 is => 'ro',
45 isa => NetWorksAddress,
46 init_arg => undef,
47 lazy => 1,
48 builder => '_build_last',
49 );
50  
51 3 has prefix_length => (
52 is => 'ro',
53 isa => PrefixLength,
54 required => 1,
55 );
56  
57 3 has _address_string => (
58 is => 'ro',
59 isa => Str,
60 init_arg => undef,
61 lazy => 1,
62 builder => '_build_address_string',
63 );
64  
65 3 has _subnet_integer => (
66 is => 'ro',
67 isa => IPInt,
68 init_arg => undef,
69 lazy => 1,
70 builder => '_build_subnet_integer',
71 );
72  
73 1182 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
74 1182 my $orig = shift;
75 1182 my $class = shift;
76  
77 1182 my $p = $class->$orig(@_);
78 $p->{prefix_length} = delete $p->{mask_length}
79 1182 ▶ if exists $p->{mask_length};
Branch: 1 branch
BranchTrueFalseTotal
if exists $p->{"mask_length"} 0 1182 1182
80  
81 1182 return $p;
82 3 };
83  
84 0 ▶sub mask_length { $_[0]->prefix_length() }
Subroutine mask_length: not called CC=1 SCAR=6.9
Pod undocumented
85  
86 1160 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
87 1160 my $self = shift;
88  
89 1160 $self->_validate_ip_integer();
90  
91 1159 my $max = $self->bits();
92 1159 ▶ if ( $self->prefix_length() > $max ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->prefix_length > $max) 1 1158 1159
93 1 confess $self->prefix_length()
94 . ' is not a valid IP network prefix length';
95 }
96  
97 1158 return;
98 }
99  
100 794 ▶sub new_from_string {
Subroutine new_from_string: called CC=7 SCAR=19.5
Pod documented
101 794 my $class = shift;
102 794 my %p = @_;
103  
104 794 ▶ die 'undef is not a valid IP network' unless defined $p{string};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p{"string"} 4 790 794
105  
106 790 my ( $address, $prefix_length ) = split /\//, $p{string}, 2;
107  
108 my $version
109 = $p{version} ? $p{version}
110 790 ▶ : inet_pton( AF_INET6, $address ) ? 6
Branch: 2 branches
BranchTrueFalseTotal
$p{'version'} ? : 446 344 790
inet_pton(10, $address) ? : 256 88 344
111 : 4;
112  
113 790 ▶ if ( $version == 6 && inet_pton( AF_INET, $address ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version == 6 and inet_pton(2, $address)) 45 745 790
Condition100%3/3
$version == 6 and inet_pton(2, $address)
!ll&&!rl&&r
14859745
MC/DC100%2/2
$version == 6 and inet_pton(2, $address)
$version == 6 inet_pton(2, $address)
Truth table100%3/3
A and B
A= $version == 6B= inet_pton(2, $address)
ABresult
0X0
100
111
114 45 $prefix_length += 96;
115 45 $address = '::' . $address;
116 }
117  
118 790 my $integer = _string_address_to_integer( $address, $version );
119  
120 790 ▶ confess "$p{string} is not a valid IP network"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $integer 18 772 790
121 unless defined $integer;
122  
123 772 return $class->new(
124 _integer => $integer,
125 prefix_length => $prefix_length,
126 version => $version,
127 );
128 }
129  
130 410 ▶sub new_from_integer {
Subroutine new_from_integer: called CC=3 SCAR=11.0
Pod documented
131 410 my $class = shift;
132 410 my %p = @_;
133  
134 410 my $integer = delete $p{integer};
135 410 my $version = delete $p{version};
136  
137 410 ▶ $version ||= ref $integer ? 6 : 4;
Branch: 1 branch
BranchTrueFalseTotal
ref $integer ? : 38 32 70
Condition66%2/3
$version ||= ref $integer ? 6 : 4
l!l&&r!l&&!r
340700
MC/DC0%0/2
$version ||= ref $integer ? 6 : 4
$version ref $integer ? 6 : 4
Truth table66%2/3
A ||= B
A= $versionB= ref $integer ? 6 : 4
ABresult
1X1
011
000
138  
139 410 return $class->new(
140 _integer => $integer,
141 version => $version,
142 %p,
143 );
144 }
145  
146 728 ▶sub _build_address_string {
Subroutine _build_address_string: called CC=1 SCAR=0.0
147 728 _integer_address_to_string( $_[0]->first_as_integer );
148 }
149  
150 1112 ▶sub _build_subnet_integer {
Subroutine _build_subnet_integer: called CC=1 SCAR=0.0
151 1112 my $self = shift;
152  
153 1112 return $self->_prefix_length_to_mask( $self->prefix_length() );
154 }
155  
156 13559 ▶sub _prefix_length_to_mask {
Subroutine _prefix_length_to_mask: called CC=2 SCAR=6.9
157 13559 my $self = shift;
158 13559 my $prefix_length = shift;
159  
160 # We need to special case 0 because left shifting a 128-bit integer by 128
161 # bits does not produce 0.
162 13559 ▶ return $self->prefix_length() == 0
Branch: 1 branch
BranchTrueFalseTotal
$self->prefix_length == 0 ? : 3 13556 13559
163 ? 0
164 : $self->_max()
165 & ( $self->_max() << ( $self->bits - $prefix_length ) );
166 }
167  
168 250 ▶sub max_prefix_length {
Subroutine max_prefix_length: called CC=3 SCAR=11.0
Pod documented
169 250 my $self = shift;
170  
171 250 my $base = $self->first()->as_integer();
172  
173 250 my $prefix_length = $self->prefix_length();
174  
175 250 my $bits = $self->bits;
176 250 ▶ while ($prefix_length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix_length) 12447 0 12447
177 12447 my $mask = $self->_prefix_length_to_mask($prefix_length);
178  
179 12447 ▶ last if ( $base & $mask ) != $base;
Branch: 1 branch
BranchTrueFalseTotal
if ($base & $mask) != $base 250 12197 12447
180  
181 12197 $prefix_length--;
182 }
183  
184 250 return $prefix_length + 1;
185 }
186  
187 0 ▶sub max_mask_length { $_[0]->max_prefix_length() }
Subroutine max_mask_length: not called CC=1 SCAR=6.9
Pod undocumented
188  
189 5 ▶sub iterator {
Subroutine iterator: called CC=1 SCAR=0.0
Pod documented
190 5 my $self = shift;
191  
192 5 my $version = $self->version();
193 5 my $current_ip = $self->first()->as_integer();
194 5 my $last_ip = $self->last()->as_integer();
195  
196 284 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
197 284 ▶ return if $current_ip > $last_ip;
Branch: 1 branch
BranchTrueFalseTotal
if $current_ip > $last_ip 5 279 284
198  
199 279 Net::Works::Address->new_from_integer(
200 integer => $current_ip++,
201 version => $version,
202 );
203 5 };
204 }
205  
206 779 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
207 779 my $self = shift;
208  
209 779 return join '/', lc $self->_address_string(), $self->prefix_length();
210 }
211  
212 1026 ▶sub _build_first {
Subroutine _build_first: called CC=1 SCAR=0.0
213 1026 my $self = shift;
214  
215 1026 my $int = $self->first_as_integer;
216  
217 1026 return Net::Works::Address->new_from_integer(
218 integer => $int,
219 version => $self->version(),
220 );
221 }
222  
223 1853 ▶sub first_as_integer { $_[0]->_integer() & $_[0]->_subnet_integer() }
Subroutine first_as_integer: called CC=1 SCAR=0.0
Pod documented
224  
225 769 ▶sub _build_last {
Subroutine _build_last: called CC=1 SCAR=0.0
226 769 my $self = shift;
227  
228 769 my $int = $self->last_as_integer;
229  
230 769 return Net::Works::Address->new_from_integer(
231 integer => $int,
232 version => $self->version(),
233 );
234 }
235  
236 1184 ▶sub last_as_integer {
Subroutine last_as_integer: called CC=1 SCAR=0.0
Pod documented
237 1184 my $self = shift;
238  
239 1184 return $self->_integer() | ( $self->_max() & ~$self->_subnet_integer() );
240 }
241  
242 46 ▶sub contains {
Subroutine contains: called CC=4 SCAR=13.9
Pod documented
243 46 my $self = shift;
244 46 my $thing = shift;
245  
246 46 my $first_integer;
247 my $last_integer;
248 46 ▶ if ( $thing->isa('Net::Works::Address') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($thing->isa('Net::Works::Address')) { } 25 21 46
elsif ($thing->isa('Net::Works::Network')) { } 21 0 21
249 25 $first_integer = $last_integer = $thing->as_integer();
250 }
251 elsif ( $thing->isa('Net::Works::Network') ) {
252 21 $first_integer = $thing->first_as_integer();
253 21 $last_integer = $thing->last_as_integer();
254 }
255 else {
256 0 confess
257 "$thing is not a Net::Works::Address or Net::Works::Network object";
258 }
259  
260 46 ▶ return $first_integer >= $self->first_as_integer()
Condition100%3/3
$first_integer >= $self->first_as_integer && $last_integer <= $self->last_as_integer
!ll&&!rl&&r
101026
MC/DC100%2/2
$first_integer >= $self->first_as_integer && $last_integer <= $self->last_as_integer
$first_integer >= $self->first_as_integer $last_integer <= $self->last_as_integer
Truth table100%3/3
A && B
A= $first_integer >= $self->first_as_integerB= $last_integer <= $self->last_as_integer
ABresult
0X0
100
111
261 && $last_integer <= $self->last_as_integer();
262 }
263  
264 ## no critic (Subroutines::ProhibitBuiltinHomonyms)
265 34 ▶sub split {
Subroutine split: called CC=2 SCAR=6.9
Pod documented
266 34 my $self = shift;
267  
268 34 ▶ return () if $self->prefix_length() == $self->bits();
Branch: 1 branch
BranchTrueFalseTotal
if $self->prefix_length == $self->bits 2 32 34
269  
270 32 my $first_int = $self->first_as_integer();
271 32 my $last_int = $self->last_as_integer();
272  
273 return (
274 32 Net::Works::Network->new_from_integer(
275 integer => $first_int,
276 prefix_length => $self->prefix_length() + 1,
277 ),
278 Net::Works::Network->new_from_integer(
279 integer => ( $first_int + ( ( $last_int - $first_int ) / 2 ) )
280 + 1,
281 prefix_length => $self->prefix_length() + 1,
282 )
283 );
284 }
285 ## use critic
286  
287 12 ▶sub is_single_address {
Subroutine is_single_address: called CC=4 SCAR=13.9
Pod documented
288 12 my $self = shift;
289  
290 12 ▶ return ( $self->version == 4 && $self->prefix_length == 32 )
Condition100%9/9
$self->version == 4 && $self->prefix_length == 32 || $self->version == 6 && $self->prefix_length == 128
l!l&&r!l&&!r
336
$self->version == 4 and $self->prefix_length == 32
!ll&&!rl&&r
633
$self->version == 6 and $self->prefix_length == 128
!ll&&!rl&&r
333
MC/DC75%3/4
$self->version == 4 && $self->prefix_length == 32 || $self->version == 6 && $self->prefix_length == 128
$self->version == 4 $self->prefix_length == 32 $self->version == 6 $self->prefix_length == 128
Truth table57%4/7
A and B || C and D
A= $self->version == 4B= $self->prefix_length == 32C= $self->version == 6D= $self->prefix_length == 128
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
291 || ( $self->version == 6 && $self->prefix_length == 128 );
292 }
293  
294 5 ▶sub range_as_subnets {
Subroutine range_as_subnets: called CC=6 SCAR=18.0
Pod documented
295 5 my $class = shift;
296 5 my $first_ip = shift;
297 5 my $last_ip = shift;
298 5 ▶ my $version = shift || ( any { /:/ } $first_ip, $last_ip ) ? 6 : 4;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
shift() || &any(sub { /:/; } , $first_ip, $last_ip) ? : 2 3 5
Condition100%3/3
shift() or &any(sub { /:/; } , $first_ip, $last_ip)
l!l&&r!l&&!r
113
MC/DC100%2/2
shift() or &any(sub { /:/; } , $first_ip, $last_ip)
shift() &any(sub { /:/; } , $first_ip, $last_ip)
Truth table100%3/3
A or B
A= shift()B= &any(sub { /:/; } , $first_ip, $last_ip)
ABresult
1X1
011
000
299  
300 5 ▶ $first_ip = Net::Works::Address->new_from_string(
Branch: 1 branch
BranchTrueFalseTotal
unless ref $first_ip 5 0 5
301 string => $first_ip,
302 version => $version,
303 ) unless ref $first_ip;
304  
305 5 ▶ $last_ip = Net::Works::Address->new_from_string(
Branch: 1 branch
BranchTrueFalseTotal
unless ref $last_ip 5 0 5
306 string => $last_ip,
307 version => $version,
308 ) unless ref $last_ip;
309  
310 5 my @ranges = $class->_remove_reserved_subnets_from_range(
311 $first_ip->as_integer(),
312 $last_ip->as_integer(),
313 $version
314 );
315  
316 5 my @subnets;
317 5 for my $range (@ranges) {
318 24 push @subnets, $class->_split_one_range( @{$range}, $version );
319 }
320  
321 5 return @subnets;
322 }
323  
324 {
325 3 my @reserved_4 = qw(
326 0.0.0.0/8
327 10.0.0.0/8
328 100.64.0.0/10
329 127.0.0.0/8
330 169.254.0.0/16
331 172.16.0.0/12
332 192.0.0.0/29
333 192.0.2.0/24
334 192.88.99.0/24
335 192.168.0.0/16
336 198.18.0.0/15
337 198.51.100.0/24
338 203.0.113.0/24
339 224.0.0.0/4
340 240.0.0.0/4
341 );
342  
343 # ::/128 and ::1/128 are reserved under IPv6 but these are already covered
344 # under 0.0.0.0/8
345 3 my @reserved_6 = (
346 @reserved_4, qw(
347 100::/64
348 2001::/23
349 2001:db8::/32
350 fc00::/7
351 fe80::/10
352 ff00::/8
353 )
354 );
355  
356 my %reserved_networks = (
357 4 => [
358 45 map { [ $_->first()->as_integer(), $_->last()->as_integer() ] }
359 93 sort { $a->first <=> $b->first }
360 map {
361 45 Net::Works::Network->new_from_string(
362 string => $_,
363 version => 4
364 )
365 } @reserved_4,
366 ],
367 6 => [
368 63 map { [ $_->first()->as_integer(), $_->last()->as_integer() ] }
369 60 sort { $a->first <=> $b->first }
370 map {
371 3 Net::Works::Network->new_from_string(
372 string => $_,
373 version => 6
374 )
375 } @reserved_6,
376 ],
377 );
378  
379 13 ▶ sub _remove_reserved_subnets_from_range {
Subroutine _remove_reserved_subnets_from_range: called CC=7 SCAR=19.5
380 13 my $class = shift;
381 13 my $first_ip = shift;
382 13 my $last_ip = shift;
383 13 my $version = shift;
384  
385 13 my @ranges;
386 13 my $add_remaining = 1;
387  
388 13 for my $pn ( @{ $reserved_networks{$version} } ) {
389 82 my $reserved_first = $pn->[0];
390 82 my $reserved_last = $pn->[1];
391  
392 82 ▶ next if ( $reserved_last <= $first_ip );
Branch: 1 branch
BranchTrueFalseTotal
if $reserved_last <= $first_ip 8 74 82
393 74 ▶ last if ( $last_ip < $reserved_first );
Branch: 1 branch
BranchTrueFalseTotal
if $last_ip < $reserved_first 8 66 74
394  
395 66 ▶ push @ranges, [ $first_ip, $reserved_first - 1 ]
Branch: 1 branch
BranchTrueFalseTotal
if $first_ip < $reserved_first 54 12 66
396 if $first_ip < $reserved_first;
397  
398 66 ▶ if ( $last_ip <= $reserved_last ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_ip <= $reserved_last) 5 61 66
399 5 $add_remaining = 0;
400 5 last;
401 }
402  
403 61 $first_ip = $reserved_last + 1;
404 }
405  
406 13 ▶ push @ranges, [ $first_ip, $last_ip ] if $add_remaining;
Branch: 1 branch
BranchTrueFalseTotal
if $add_remaining 8 5 13
407  
408 13 return @ranges;
409 }
410 }
411  
412 3 ▶sub _split_one_range {
Subroutine _split_one_range: called CC=2 SCAR=6.9
413 24 my $class = shift;
414 24 my $first_ip = shift;
415 24 my $last_ip = shift;
416 24 my $version = shift;
417  
418 24 my @subnets;
419 24 ▶ while ( $first_ip <= $last_ip ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_ip <= $last_ip) 326 24 350
420 326 my $max_network = _max_subnet( $first_ip, $last_ip, $version );
421  
422 326 push @subnets, $max_network;
423  
424 326 $first_ip = $max_network->last_as_integer + 1;
425 }
426  
427 24 return @subnets;
428 }
429  
430 326 ▶sub _max_subnet {
Subroutine _max_subnet: called CC=6 SCAR=17.9
431 326 my $ip = shift;
432 326 my $maxip = shift;
433 326 my $version = shift;
434  
435 326 ▶ my $prefix_length = $version == 6 ? 128 : 32;
Branch: 1 branch
BranchTrueFalseTotal
$version == 6 ? : 309 17 326
436  
437 326 my $v = $ip;
438 326 ▶ my $reverse_mask = $version == 6 ? uint128(1) : 1;
Branch: 1 branch
BranchTrueFalseTotal
$version == 6 ? : 309 17 326
439  
440 326 ▶ while (( $v & 1 ) == 0
Branch: 1 branch
BranchTrueFalseTotal
if (($v & 1) == 0 and $prefix_length > 0 and ($ip | $reverse_mask) <= $maxip) 19009 326 19335
Condition83%5/6
($v & 1) == 0 and $prefix_length > 0 and ($ip | $reverse_mask) <= $maxip
!ll&&!rl&&r
2675919009
($v & 1) == 0 and $prefix_length > 0
!ll&&!rl&&r
267019068
MC/DC66%2/3
($v & 1) == 0 and $prefix_length > 0 and ($ip | $reverse_mask) <= $maxip
($v & 1) == 0 $prefix_length > 0 ($ip | $reverse_mask) <= $maxip
Truth table75%3/4
A and B and C
A= ($v & 1) == 0B= $prefix_length > 0C= ($ip | $reverse_mask) <= $maxip
ABCresult
0XX0
10X0
1100
1111
441 && $prefix_length > 0
442 && ( $ip | $reverse_mask ) <= $maxip ) {
443  
444 19009 $prefix_length--;
445 19009 $v = $v >> 1;
446  
447 19009 $reverse_mask = ( $reverse_mask << 1 ) | 1;
448 }
449  
450 326 return Net::Works::Network->new_from_integer(
451 integer => $ip,
452 prefix_length => $prefix_length,
453 version => $version,
454 );
455 }
456  
457 30 ▶sub _compare_overload {
Subroutine _compare_overload: called CC=7 SCAR=22.4
458 30 my $self = shift;
459 30 my $other = shift;
460  
461 confess 'Cannot compare unless both objects are '
462 . __PACKAGE__
463 . ' objects'
464 unless blessed $self
465 && blessed $other
466 30 ▶ && eval { $self->isa(__PACKAGE__) && $other->isa(__PACKAGE__) };
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self) and builtin::blessed($other) and eval { do { $self->isa(__PACKAGE__) and $other->isa(__PACKAGE__) } } 0 30 30
Condition33%3/9
builtin::blessed($self) and builtin::blessed($other) and eval { do { $self->isa(__PACKAGE__) and $other->isa(__PACKAGE__) } }
!ll&&!rl&&r
0030
builtin::blessed($self) and builtin::blessed($other)
!ll&&!rl&&r
0030
$self->isa(__PACKAGE__) && $other->isa(__PACKAGE__)
!ll&&!rl&&r
0030
MC/DC0%0/3
builtin::blessed($self) and builtin::blessed($other) and eval { do { $self->isa(__PACKAGE__) and $other->isa(__PACKAGE__) } }
builtin::blessed($self) builtin::blessed($other) eval { do { $self->isa(__PACKAGE__) and $other->isa(__PACKAGE__) } }
MC/DC0%0/2
$self->isa(__PACKAGE__) && $other->isa(__PACKAGE__)
$self->isa(__PACKAGE__) $other->isa(__PACKAGE__)
Truth table25%1/4
A and B and C
A= builtin::blessed($self)B= builtin::blessed($other)C= eval { do { $self->isa(__PACKAGE__) and $other->isa(__PACKAGE__) } }
ABCresult
0XX0
10X0
1100
1111
Truth table33%1/3
A && B
A= $self->isa(__PACKAGE__)B= $other->isa(__PACKAGE__)
ABresult
0X0
100
111
467  
468 30 ▶ my $cmp = (
Condition100%3/3
$self->first <=> $other->first || $self->prefix_length <=> $other->prefix_length
l!l&&r!l&&!r
2442
MC/DC100%2/2
$self->first <=> $other->first || $self->prefix_length <=> $other->prefix_length
$self->first <=> $other->first $self->prefix_length <=> $other->prefix_length
Truth table100%3/3
A || B
A= $self->first <=> $other->firstB= $self->prefix_length <=> $other->prefix_length
ABresult
1X1
011
000
469 $self->first() <=> $other->first()
470 or $self->prefix_length() <=> $other->prefix_length()
471 );
472  
473 30 ▶ return shift() ? $cmp * -1 : $cmp;
Branch: 1 branch
BranchTrueFalseTotal
shift() ? : 0 30 30
474 }
475  
476 3 __PACKAGE__->meta()->make_immutable();
477  
478 3 1;
479  
480 # ABSTRACT: An object representing a single IP address (4 or 6) subnet
481  
482 __END__
↑ Summary Works/Util.pm »