Works/Role/IP.pm

filter: Statementstmt 97.9% 47 / 48 Branchbran 83.3% 10 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 1 totaltotal 88.7% 71 / 80 CC 8 SCAR 9.7
CC
8
Cov
92%
__ANON__
6.0
_validate_ip_integer
5.0
_max
2.1
CRAP 2.6
« Works/Address.pm ↑ Summary Works.pm »
1 package Net::Works::Role::IP;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use namespace::autoclean 0.16;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 our $VERSION = '0.22';
8  
9 4 ▶use Carp qw( confess );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Math::Int128 qw( string_to_uint128 uint128 uint128_to_number );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Net::Works::Types qw( Int IPInt IPVersion );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Socket qw( AF_INET AF_INET6 );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 has version => (
19 is => 'ro',
20 isa => IPVersion,
21 required => 1,
22 );
23  
24 4 has _integer => (
25 is => 'rw',
26 writer => '_set_integer',
27 isa => IPInt,
28 required => 1,
29 );
30  
31 has address_family => (
32 is => 'ro',
33 isa => Int,
34 lazy => 1,
35 0 ▶ default => sub { $_[0]->version() == 6 ? AF_INET6 : AF_INET },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->version == 6 ? : 0 0 0
36 4 );
37  
38 {
39 4 my %max = (
40 4 => 0xFFFFFFFF,
41 6 => string_to_uint128( '0x' . ( 'F' x 32 ) ),
42 );
43  
44 28301 ▶ sub _max {
Subroutine _max: called CC=2 SCAR=7.6
45 28301 my $self = shift;
46 28301 ▶ my $version = shift // $self->version();
Condition33%1/3
shift() // $self->version
l!l&&r!l&&!r
0283010
MC/DC0%0/2
shift() // $self->version
shift() $self->version
Truth table33%1/3
A // B
A= shift()B= $self->version
ABresult
1X1
011
000
47  
48 28301 return $max{$version};
49 }
50 }
51  
52 14999 ▶sub bits { $_[0]->version() == 6 ? 128 : 32 }
Subroutine bits: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->version == 6 ? : 14382 617 14999
53  
54 3685 ▶sub _validate_ip_integer {
Subroutine _validate_ip_integer: called CC=5 SCAR=16.1
55 3685 my $self = shift;
56  
57 3685 my $int = $self->_integer();
58  
59 # We don't need to check if it's too big with v6 because uint128 does not
60 # allow a number larger than 2**128-1.
61 3685 ▶ if ( $self->version() == 6 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->version == 6) { } 2935 750 3685
62 2935 ▶ $self->_set_integer( uint128($int) )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $int 3 2932 2935
63 unless ref $int;
64 }
65 else {
66 750 ▶ confess("$int is not a valid integer for an IP address")
Branch: 1 branch
BranchTrueFalseTotal
if $int >= 4294967296 3 747 750
67 if $int >= 2**32;
68 747 ▶ if ( ref $int ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $int) 254 493 747
69 254 $self->_set_integer( uint128_to_number($int) );
70 }
71 }
72  
73 3682 return;
74 }
75  
76 # overload passes extra arguments to this sub for some reason
77 1013 ▶sub _overloaded_as_string {
Subroutine _overloaded_as_string: called CC=1 SCAR=0.0
78 1013 return $_[0]->as_string();
79 }
80  
81 4 1;
« Works/Address.pm ↑ Summary Works.pm »