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 lib/Net/DHCPv6/OptionList.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.003';
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 qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 $DN_COMPRESS_MASK $DN_LABEL_MASK $OPTION_AFTR_NAME
13 15 );
14 15 ▶use Net::DHCPv6::X::Truncated ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 15 ▶use Net::DHCPv6::X::BadOption ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 15 ▶use parent 'Net::DHCPv6::Option';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 15 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 15 my $EMPTY = q();
19 15 my $MAX_PTR_DEPTH = 255; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
20  
21 6 ▶sub _encode_domain {
Subroutine _encode_domain: called CC=3 SCAR=11.8
22 6 my ( $domain ) = @_;
23 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
24 6 my @labels = split m/[.]/, $domain;
25 6 return join( $EMPTY, map { pack( 'C', CORE::length ) . $_ } @labels ) . chr( 0 );
26 }
27  
28 6 ▶sub _read_labels_at {
Subroutine _read_labels_at: called CC=11 SCAR=29.3
29 6 my ( $payload, $offset_ref, $len, $depth ) = @_;
30 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
31 6 my @labels;
32 6 ▶ while ( ${$offset_ref} < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if (${$offset_ref;} < $len) 22 0 22
33 22 my $llen = unpack( 'C', substr( $payload, ${$offset_ref}, 1 ) );
34 22 ▶ if ( $llen == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($llen == 0) 5 17 22
35 5 ++${$offset_ref};
36 5 last;
37 }
38 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
39 1 ▶ if ( $Net::DHCPv6::Option::FOLLOW_COMPRESSION ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::DHCPv6::Option::FOLLOW_COMPRESSION) 0 1 1
40 Net::DHCPv6::X::Truncated->throw( message => 'Truncated compression pointer' )
41 0 ▶ if ${$offset_ref} + 2 > $len;
Branch: 1 branch
BranchTrueFalseTotal
if ${$offset_ref;} + 2 > $len 0 0 0
42 my $ptr =
43 0 ( ( $llen & $DN_LABEL_MASK ) << 8 ) | unpack( 'C', substr( $payload, ${$offset_ref} + 1, 1 ) ); ## no critic (Bangs::ProhibitBitwiseOperators ValuesAndExpressions::ProhibitMagicNumbers)
44 0 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer out of range' )
Branch: 1 branch
BranchTrueFalseTotal
if $ptr >= $len 0 0 0
45 if $ptr >= $len;
46 0 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer depth exceeded' )
Branch: 1 branch
BranchTrueFalseTotal
if $depth > $MAX_PTR_DEPTH 0 0 0
47 if $depth > $MAX_PTR_DEPTH;
48 0 ${$offset_ref} += 2;
49 0 my $ptr_ref = \$ptr;
50 0 push @labels, _read_labels_at( $payload, $ptr_ref, $len, $depth + 1 );
51 0 last;
52 }
53 1 Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer in domain name' );
54 }
55 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
56 16 ++${$offset_ref};
57 Net::DHCPv6::X::Truncated->throw( message => 'Truncated domain label' )
58 16 ▶ if ${$offset_ref} + $llen > $len;
Branch: 1 branch
BranchTrueFalseTotal
if ${$offset_ref;} + $llen > $len 0 16 16
59 16 push @labels, substr( $payload, ${$offset_ref}, $llen );
60 16 ${$offset_ref} += $llen;
61 }
62 5 return @labels;
63 }
64  
65 6 ▶sub _decode_domain {
Subroutine _decode_domain: called CC=2 SCAR=7.0
66 6 my ( $payload ) = @_;
67 6 ▶ return $EMPTY unless CORE::length( $payload );
Branch: 1 branch
BranchTrueFalseTotal
unless length $payload 0 6 6
68 6 my $offset = 0;
69 6 my @labels = _read_labels_at( $payload, \$offset, CORE::length( $payload ) );
70 5 return join( q{.}, @labels );
71 }
72  
73 7 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
74 7 my ( $class, %args ) = @_;
75 7 ▶ croak 'AftrName requires domain_name' unless defined $args{domain_name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"domain_name"} 1 6 7
76 6 $args{code} = $OPTION_AFTR_NAME;
77 6 $args{data} = _encode_domain( $args{domain_name} );
78 6 my $self = $class->SUPER::new( %args );
79 6 $self->{domain_name} = $args{domain_name};
80 6 return bless $self, $class;
81 }
82  
83 2 ▶sub domain_name { return shift->{domain_name} }
Subroutine domain_name: called CC=1 SCAR=0.0
Pod documented
84  
85 6 ▶sub from_bytes_inner {
Subroutine from_bytes_inner: called CC=1 SCAR=0.0
Pod documented
86 6 my ( $class, $code, $payload ) = @_;
87 6 my $name = _decode_domain( $payload );
88 5 return $class->new( domain_name => $name );
89 }
90  
91 15 $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_AFTR_NAME} = __PACKAGE__;
92 15 1;
93  
94 __END__
« lib/Net/DHCPv6/Option/ClientFqdn.pm ↑ Summary lib/Net/DHCPv6/OptionList.pm »