lib/Net/DHCPv6/Option/DomainList.pm

filter: Statementstmt 100% 76 / 76 Branchbran 79.1% 19 / 24 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 14 / 14 Podpod 100% 3 / 3 totaltotal 89.1% 115 / 129 CC 16 SCAR 14.8
CC
16
Cov
91%
_read_labels_at
9.0
new
4.2
_encode_domain
3.2
CRAP 4.4
« blib/lib/Net/DHCPv6/Option/Auth.pm ↑ Summary lib/Net/DHCPv6/Option/SipServerD.pm »
1 #!/usr/bin/false
2 # ABSTRACT: Domain Search List option (code 24) — RFC 1035 domain names
3 # PODNAME: Net::DHCPv6::Option::DomainList
4 package Net::DHCPv6::Option::DomainList;
5 15 $Net::DHCPv6::Option::DomainList::VERSION = '0.001';
6 15 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use Net::DHCPv6::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use Net::DHCPv6::X::Truncated;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use Net::DHCPv6::X::BadOption;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use parent 'Net::DHCPv6::Option';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use Ref::Util qw(is_plain_arrayref);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub _encode_domain {
16 10 ▶ my ( $domain ) = @_;
Subroutine _encode_domain: called CC=3 SCAR=11.8
17 10 ▶ return "\x00" unless defined $domain && CORE::length( $domain );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $domain and length $domain 0 10 10
Condition33%1/3
defined $domain and length $domain
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $domain and length $domain
defined $domain length $domain
Truth table33%1/3
A and B
A= defined $domainB= length $domain
ABresult
0X0
100
111
18 10 my @labels = split m/\./, $domain;
19 10 join( '', map { pack( 'C', CORE::length ) . $_ } @labels ) . "\x00";
20 }
21  
22 sub _read_labels_at {
23 15 ▶ my ( $data, $offset_ref, $len ) = @_;
Subroutine _read_labels_at: called CC=9 SCAR=22.0
24 15 my @labels;
25 15 ▶ while ( $$offset_ref < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$offset_ref < $len) 36 0 36
26 36 my $llen = unpack( 'C', substr( $data, $$offset_ref, 1 ) );
27 36 ▶ if ( $llen == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($llen == 0) 9 27 36
28 9 ++$$offset_ref;
29 9 last;
30 }
31 27 ▶ if ( ( $llen & 0xC0 ) == 0xC0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($llen & 192) == 192) 3 24 27
32 3 ▶ if ( $Net::DHCPv6::Option::FOLLOW_COMPRESSION ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::DHCPv6::Option::FOLLOW_COMPRESSION) 2 1 3
33 2 ▶ Net::DHCPv6::X::Truncated->throw( message => 'Truncated compression pointer' )
Branch: 1 branch
BranchTrueFalseTotal
if $$offset_ref + 2 > $len 0 2 2
34 if $$offset_ref + 2 > $len;
35 2 my $ptr = ( ( $llen & 0x3F ) << 8 ) | unpack( 'C', substr( $data, $$offset_ref + 1, 1 ) );
36 2 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer out of range' )
Branch: 1 branch
BranchTrueFalseTotal
if $ptr >= $len 1 1 2
37 if $ptr >= $len;
38 1 $$offset_ref += 2;
39 1 my $ptr_ref = \$ptr;
40 1 push @labels, _read_labels_at( $data, $ptr_ref, $len );
41 1 last;
42 }
43 1 Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer in domain name' );
44 }
45 24 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Invalid domain label length' ) if $llen > 63;
Branch: 1 branch
BranchTrueFalseTotal
if $llen > 63 1 23 24
46 23 ++$$offset_ref;
47 23 ▶ Net::DHCPv6::X::Truncated->throw( message => 'Truncated domain label' )
Branch: 1 branch
BranchTrueFalseTotal
if $$offset_ref + $llen > $len 2 21 23
48 if $$offset_ref + $llen > $len;
49 21 push @labels, substr( $data, $$offset_ref, $llen );
50 21 $$offset_ref += $llen;
51 }
52 10 return @labels;
53 }
54  
55 sub _decode_domains {
56 11 ▶ my ( $data ) = @_;
Subroutine _decode_domains: called CC=3 SCAR=11.0
57 11 my @domains;
58 11 my $offset = 0;
59 11 my $len = CORE::length( $data );
60 11 ▶ while ( $offset < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < $len) 14 6 20
61 14 my @labels = _read_labels_at( $data, \$offset, $len );
62 9 ▶ push @domains, @labels ? join( '.', @labels ) : '';
Branch: 1 branch
BranchTrueFalseTotal
@labels ? : 9 0 9
63 }
64 6 return \@domains;
65 }
66  
67 sub new {
68 7 ▶ my ( $class, %args ) = @_;
Subroutine new: called CC=4 SCAR=14.5
Pod documented
69 7 ▶ my $domains = $args{domains} // $args{data} // [];
Condition40%2/5
($args{"domains"} // $args{"data"}) // []
l!l
70
$args{"domains"} // $args{"data"}
l!l&&r!l&&!r
700
MC/DC0%0/2
($args{"domains"} // $args{"data"}) // []
$args{"domains"} $args{"data"}
Truth table33%1/3
A // B
A= $args{"domains"}B= $args{"data"}
ABresult
1X1
011
000
70 7 ▶ $domains = [$domains] unless is_plain_arrayref( $domains );
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_plain_arrayref($domains) 0 7 7
71 7 $args{code} = $OPTION_DOMAIN_LIST;
72 7 $args{data} = join( '', map { _encode_domain( $_ ) } @$domains );
73 7 my $self = $class->SUPER::new( %args );
74 7 $self->{domains} = $domains;
75 7 bless $self, $class;
76 }
77  
78 4 ▶sub domains { shift->{domains} }
Subroutine domains: called CC=1 SCAR=0.0
Pod documented
79  
80 sub from_bytes_inner {
81 11 ▶ my ( $class, $code, $data ) = @_;
Subroutine from_bytes_inner: called CC=1 SCAR=0.0
Pod documented
82 11 my $domains = _decode_domains( $data );
83 6 return $class->new( domains => $domains );
84 }
85  
86 15 $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_DOMAIN_LIST} = __PACKAGE__;
87 15 1;
88  
89 __END__
« blib/lib/Net/DHCPv6/Option/Auth.pm ↑ Summary lib/Net/DHCPv6/Option/SipServerD.pm »