lib/Net/DHCPv6/Option/DomainList.pm

filter: Statementstmt 100% 94 / 94 Branchbran 76.9% 20 / 26 Conditioncond 50.0% 5 / 10 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 15 / 15 Podpod 100% 3 / 3 totaltotal 90.2% 138 / 153 CC 18 SCAR 16.6
CC
18
Cov
92%
_read_labels_at
11.0
new
4.2
_encode_domain
3.2
CRAP 5.2
« lib/Net/DHCPv6/OptionList.pm ↑ Summary lib/Net/DHCPv6/Option/SipServerD.pm »
1 #!/bin/false
2 # ABSTRACT: Domain Search List option (code 24) -- RFC 1035 domain names
3 # PODNAME: Net::DHCPv6::Option::DomainList
4 15 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Net::DHCPv6::Option::DomainList;
7 15 $Net::DHCPv6::Option::DomainList::VERSION = '0.002';
8 15 ▶use Net::DHCPv6::OptionList;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use Net::DHCPv6::Option;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use Net::DHCPv6::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use Net::DHCPv6::X::Truncated;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use Net::DHCPv6::X::BadOption;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use parent 'Net::DHCPv6::Option';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 15 ▶use Ref::Util qw( is_plain_arrayref );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 15 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 15 my $EMPTY = q();
17 15 my $MAX_PTR_DEPTH = 255; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
18  
19 sub _encode_domain {
20 10 ▶ my ( $domain ) = @_;
Subroutine _encode_domain: called CC=3 SCAR=11.8
21 10 ▶ return chr( 0 ) 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
22 10 my @labels = split m/[.]/, $domain;
23 10 return join( $EMPTY, map { pack( 'C', CORE::length ) . $_ } @labels ) . chr( 0 );
24 }
25  
26 sub _read_labels_at {
27 15 ▶ my ( $payload, $offset_ref, $len, $depth ) = @_;
Subroutine _read_labels_at: called CC=11 SCAR=24.0
28 15 ▶ $depth //= 0;
Condition100%2/2
$depth //= 0
l!l
114
MC/DC100%1/1
$depth //= 0
$depth
Truth table100%2/2
A
A= $depth
Aresult
11
00
29 15 my @labels;
30 15 ▶ while ( ${$offset_ref} < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if (${$offset_ref;} < $len) 36 0 36
31 36 my $llen = unpack( 'C', substr( $payload, ${$offset_ref}, 1 ) );
32 36 ▶ if ( $llen == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($llen == 0) 9 27 36
33 9 ++${$offset_ref};
34 9 last;
35 }
36 27 ▶ if ( ( $llen & $DN_COMPRESS_MASK ) == $DN_COMPRESS_MASK ) { ## no critic (Bangs::ProhibitBitwiseOperators ValuesAndExpressions::ProhibitMagicNumbers)
Branch: 1 branch
BranchTrueFalseTotal
if (($llen & $Net::DHCPv6::Option::DomainList::DN_COMPRESS_MASK) == $Net::DHCPv6::Option::DomainList::DN_COMPRESS_MASK) 3 24 27
37 3 ▶ if ( $Net::DHCPv6::Option::FOLLOW_COMPRESSION ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::DHCPv6::Option::FOLLOW_COMPRESSION) 2 1 3
38 Net::DHCPv6::X::Truncated->throw( message => 'Truncated compression pointer' )
39 2 ▶ if ${$offset_ref} + 2 > $len;
Branch: 1 branch
BranchTrueFalseTotal
if ${$offset_ref;} + 2 > $len 0 2 2
40 my $ptr =
41 2 ( ( $llen & $DN_LABEL_MASK ) << 8 ) | unpack( 'C', substr( $payload, ${$offset_ref} + 1, 1 ) ); ## no critic (Bangs::ProhibitBitwiseOperators ValuesAndExpressions::ProhibitMagicNumbers)
42 2 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer out of range' )
Branch: 1 branch
BranchTrueFalseTotal
if $ptr >= $len 1 1 2
43 if $ptr >= $len;
44 1 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer depth exceeded' )
Branch: 1 branch
BranchTrueFalseTotal
if $depth > $MAX_PTR_DEPTH 0 1 1
45 if $depth > $MAX_PTR_DEPTH;
46 1 ${$offset_ref} += 2;
47 1 my $ptr_ref = \$ptr;
48 1 push @labels, _read_labels_at( $payload, $ptr_ref, $len, $depth + 1 );
49 1 last;
50 }
51 1 Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer in domain name' );
52 }
53 24 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Invalid domain label length' ) if $llen > $DN_LABEL_MASK;
Branch: 1 branch
BranchTrueFalseTotal
if $llen > $Net::DHCPv6::Option::DomainList::DN_LABEL_MASK 1 23 24
54 23 ++${$offset_ref};
55 Net::DHCPv6::X::Truncated->throw( message => 'Truncated domain label' )
56 23 ▶ if ${$offset_ref} + $llen > $len;
Branch: 1 branch
BranchTrueFalseTotal
if ${$offset_ref;} + $llen > $len 2 21 23
57 21 push @labels, substr( $payload, ${$offset_ref}, $llen );
58 21 ${$offset_ref} += $llen;
59 }
60 10 return @labels;
61 }
62  
63 sub _decode_domains {
64 11 ▶ my ( $payload ) = @_;
Subroutine _decode_domains: called CC=3 SCAR=11.0
65 11 my @domain_list;
66 11 my $offset = 0;
67 11 my $len = CORE::length( $payload );
68 11 ▶ while ( $offset < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < $len) 14 6 20
69 14 my @labels = _read_labels_at( $payload, \$offset, $len );
70 9 ▶ push @domain_list, @labels ? join( '.', @labels ) : $EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
@labels ? : 9 0 9
71 }
72 6 return \@domain_list;
73 }
74  
75 sub new {
76 8 ▶ my ( $class, %args ) = @_;
Subroutine new: called CC=4 SCAR=14.4
Pod documented
77 8 ▶ my $domains = $args{domains} // $args{data} // [];
Condition40%2/5
($args{"domains"} // $args{"data"}) // []
l!l
80
$args{"domains"} // $args{"data"}
l!l&&r!l&&!r
800
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
78 8 ▶ $domains = [$domains] unless is_plain_arrayref( $domains );
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_plain_arrayref($domains) 0 8 8
79 8 $args{code} = $OPTION_DOMAIN_LIST;
80 8 $args{data} = join( $EMPTY, map { _encode_domain( $_ ) } @{$domains} );
81 8 my $self = $class->SUPER::new( %args );
82 8 $self->{domains} = $domains;
83 8 return bless $self, $class;
84 }
85  
86 4 ▶sub domains { return shift->{domains} }
Subroutine domains: called CC=1 SCAR=0.0
Pod documented
87  
88 sub from_bytes_inner {
89 11 ▶ my ( $class, $code, $payload ) = @_;
Subroutine from_bytes_inner: called CC=1 SCAR=0.0
Pod documented
90 11 my $domains = _decode_domains( $payload );
91 6 return $class->new( domains => $domains );
92 }
93  
94 15 $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_DOMAIN_LIST} = __PACKAGE__;
95 15 1;
96  
97 __END__
« lib/Net/DHCPv6/OptionList.pm ↑ Summary lib/Net/DHCPv6/Option/SipServerD.pm »