lib/Net/DHCPv6/Option/AftrName.pm

filter: Statementstmt 87.5% 77 / 88 Branchbran 50.0% 12 / 24 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 15 / 15 Podpod 100% 3 / 3 totaltotal 78.9% 109 / 138 CC 15 SCAR 20.9
CC
15
Cov
78%
_read_labels_at
18.7
_encode_domain
3.2
_decode_domain
2.0
CRAP 8.1
« lib/Net/DHCPv6/Option/ClientFqdn.pm ↑ Summary blib/lib/Net/DHCPv6/Option/NtpServer.pm »
1 #!/bin/false
2 # ABSTRACT: AFTR Name option (code 88) -- RFC 6334 domain name
3 # PODNAME: Net::DHCPv6::Option::AftrName
4 15 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Net::DHCPv6::Option::AftrName;
7 15 $Net::DHCPv6::Option::AftrName::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 Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use Net::DHCPv6::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use Net::DHCPv6::X::Truncated;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use Net::DHCPv6::X::BadOption;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 15 ▶use parent 'Net::DHCPv6::Option';
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 6 ▶ my ( $domain ) = @_;
Subroutine _encode_domain: called CC=3 SCAR=11.8
21 6 ▶ return chr( 0 ) unless defined $domain && CORE::length( $domain );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $domain and length $domain 0 6 6
Condition33%1/3
defined $domain and length $domain
!ll&&!rl&&r
006
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 6 my @labels = split m/[.]/, $domain;
23 6 return join( $EMPTY, map { pack( 'C', CORE::length ) . $_ } @labels ) . chr( 0 );
24 }
25  
26 sub _read_labels_at {
27 6 ▶ my ( $payload, $offset_ref, $len, $depth ) = @_;
Subroutine _read_labels_at: called CC=11 SCAR=29.3
28 6 ▶ $depth //= 0;
Condition50%1/2
$depth //= 0
l!l
06
MC/DC0%0/1
$depth //= 0
$depth
Truth table50%1/2
A
A= $depth
Aresult
11
00
29 6 my @labels;
30 6 ▶ while ( ${$offset_ref} < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if (${$offset_ref;} < $len) 22 0 22
31 22 my $llen = unpack( 'C', substr( $payload, ${$offset_ref}, 1 ) );
32 22 ▶ if ( $llen == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($llen == 0) 5 17 22
33 5 ++${$offset_ref};
34 5 last;
35 }
36 17 ▶ if ( ( $llen & $DN_COMPRESS_MASK ) == $DN_COMPRESS_MASK ) { ## no critic (Bangs::ProhibitBitwiseOperators ValuesAndExpressions::ProhibitMagicNumbers)
Branch: 1 branch
BranchTrueFalseTotal
if (($llen & $Net::DHCPv6::Option::AftrName::DN_COMPRESS_MASK) == $Net::DHCPv6::Option::AftrName::DN_COMPRESS_MASK) 1 16 17
37 1 ▶ if ( $Net::DHCPv6::Option::FOLLOW_COMPRESSION ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::DHCPv6::Option::FOLLOW_COMPRESSION) 0 1 1
38 Net::DHCPv6::X::Truncated->throw( message => 'Truncated compression pointer' )
39 0 ▶ if ${$offset_ref} + 2 > $len;
Branch: 1 branch
BranchTrueFalseTotal
if ${$offset_ref;} + 2 > $len 0 0 0
40 my $ptr =
41 0 ( ( $llen & $DN_LABEL_MASK ) << 8 ) | unpack( 'C', substr( $payload, ${$offset_ref} + 1, 1 ) ); ## no critic (Bangs::ProhibitBitwiseOperators ValuesAndExpressions::ProhibitMagicNumbers)
42 0 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer out of range' )
Branch: 1 branch
BranchTrueFalseTotal
if $ptr >= $len 0 0 0
43 if $ptr >= $len;
44 0 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer depth exceeded' )
Branch: 1 branch
BranchTrueFalseTotal
if $depth > $MAX_PTR_DEPTH 0 0 0
45 if $depth > $MAX_PTR_DEPTH;
46 0 ${$offset_ref} += 2;
47 0 my $ptr_ref = \$ptr;
48 0 push @labels, _read_labels_at( $payload, $ptr_ref, $len, $depth + 1 );
49 0 last;
50 }
51 1 Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer in domain name' );
52 }
53 16 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Invalid domain label length' ) if $llen > $DN_LABEL_MASK;
Branch: 1 branch
BranchTrueFalseTotal
if $llen > $Net::DHCPv6::Option::AftrName::DN_LABEL_MASK 0 16 16
54 16 ++${$offset_ref};
55 Net::DHCPv6::X::Truncated->throw( message => 'Truncated domain label' )
56 16 ▶ if ${$offset_ref} + $llen > $len;
Branch: 1 branch
BranchTrueFalseTotal
if ${$offset_ref;} + $llen > $len 0 16 16
57 16 push @labels, substr( $payload, ${$offset_ref}, $llen );
58 16 ${$offset_ref} += $llen;
59 }
60 5 return @labels;
61 }
62  
63 sub _decode_domain {
64 6 ▶ my ( $payload ) = @_;
Subroutine _decode_domain: called CC=2 SCAR=7.0
65 6 ▶ return $EMPTY unless CORE::length( $payload );
Branch: 1 branch
BranchTrueFalseTotal
unless length $payload 0 6 6
66 6 my $offset = 0;
67 6 my @labels = _read_labels_at( $payload, \$offset, CORE::length( $payload ) );
68 5 return join( '.', @labels );
69 }
70  
71 sub new {
72 7 ▶ my ( $class, %args ) = @_;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
73 7 ▶ croak 'AftrName requires domain_name' unless defined $args{domain_name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"domain_name"} 1 6 7
74 6 $args{code} = $OPTION_AFTR_NAME;
75 6 $args{data} = _encode_domain( $args{domain_name} );
76 6 my $self = $class->SUPER::new( %args );
77 6 $self->{domain_name} = $args{domain_name};
78 6 return bless $self, $class;
79 }
80  
81 2 ▶sub domain_name { return shift->{domain_name} }
Subroutine domain_name: called CC=1 SCAR=0.0
Pod documented
82  
83 sub from_bytes_inner {
84 6 ▶ my ( $class, $code, $payload ) = @_;
Subroutine from_bytes_inner: called CC=1 SCAR=0.0
Pod documented
85 6 my $name = _decode_domain( $payload );
86 5 return $class->new( domain_name => $name );
87 }
88  
89 15 $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_AFTR_NAME} = __PACKAGE__;
90 15 1;
91  
92 __END__
« lib/Net/DHCPv6/Option/ClientFqdn.pm ↑ Summary blib/lib/Net/DHCPv6/Option/NtpServer.pm »