blib/lib/Lemonldap/NG/Common/IPv6.pm

filter: Statementstmt 22.5% 9 / 40 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 2 / 6 Podpod 0.0% 0 / 4 totaltotal 17.7% 11 / 62 CC 7 SCAR 26.3
CC
7
Cov
17%
expand6
20.0
compact6
20.0
isIPv6
2.0
CRAP 13.8
« blib/lib/Lemonldap/NG/Common/Conf/SAML/Metadata.pm ↑ Summary blib/lib/Lemonldap/NG/Common/CliSessions.pm »
1 package Lemonldap::NG::Common::IPv6;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = '2.0.10';
7 3 our @EXPORT = qw(&isIPv6 &net6 &expand6);
8  
9 0 ▶sub isIPv6 {
Subroutine isIPv6: not called CC=1 SCAR=6.9
Pod undocumented
10 0 my ($ip) = @_;
11 0 return $ip =~ /^[a-z0-9:]+$/i;
12 }
13  
14 0 ▶sub net6 {
Subroutine net6: not called CC=1 SCAR=6.9
Pod undocumented
15 0 my ( $ip, $bits ) = @_;
16  
17 # Convert to binary
18 my $b = join '',
19 0 map { unpack( 'B*', pack( 'H*', $_ ) ) } split( ':', expand6($ip) );
20 0 my $net = substr $b, 0, $bits;
21 0 $net .= '0' x ( 128 - length($net) );
22 0 $net = unpack( 'H*', pack( 'B*', $net ) );
23 0 $net = join( ':', ( unpack "a4" x 8, $net ) );
24 0 $net = compact6($net);
25 0 return $net;
26 }
27  
28 0 ▶sub expand6 {
Subroutine expand6: not called CC=4 SCAR=30.0
Pod undocumented
29 0 my @arr;
30 0 my @_parts = ( $_[0] =~ /([0-9A-Fa-f]+)/g );
31 0 my $nparts = scalar @_parts;
32 0 ▶ if ( $nparts != 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nparts != 8) 0 0 0
33 0 ▶ for ( my $i = 1 ; $i <= ( 8 - $nparts ) ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= 8 - $nparts) 0 0 0
34 0 push @arr, hex "0000";
35 }
36 }
37  
38 0 ▶ my @parts = map { ( $_ eq '::' ) ? @arr : hex $_ }
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '::' ? : 0 0 0
39 ( $_[0] =~ /((?:[0-9A-Fa-f]+)|(?:::))/g );
40  
41 0 return join( ":", map { sprintf "%04x", $_ } @parts );
42  
43 }
44  
45 0 ▶sub compact6 {
Subroutine compact6: not called CC=4 SCAR=30.0
Pod undocumented
46 0 $_[0] =~ s/(^|:)0+([\w])/$1$2/g;
47 0 ▶ if ( $_[0] =~ ':0:' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /:0:/) 0 0 0
48 0 my @t = ( $_[0] =~ /\:(?:0\:)+/g );
49 0 my $ind = -1;
50 0 my $len = 0;
51 0 ▶ for ( my $i = 0 ; $i < @t ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @t) 0 0 0
52 0 ▶ $ind = $i if ( length( $t[$i] ) > $len );
Branch: 1 branch
BranchTrueFalseTotal
if length $t[$i] > $len 0 0 0
53 }
54 0 $_[0] =~ s/$t[$ind]/::/;
55 0 $_[0] =~ s/^0//;
56 }
57 0 return $_[0];
58 }
59  
60 3 1;
« blib/lib/Lemonldap/NG/Common/Conf/SAML/Metadata.pm ↑ Summary blib/lib/Lemonldap/NG/Common/CliSessions.pm »