lib/Net/DHCPv6/Option/NisDomainName.pm

filter: Statementstmt 85.2% 75 / 88 Branchbran 41.6% 10 / 24 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 15 / 15 Podpod 100% 3 / 3 totaltotal 76.0% 105 / 138 CC 15 SCAR 23.0
CC
15
Cov
74%
_read_labels_at
23.8
_encode_domain
3.2
_decode_domain
2.0
CRAP 10.0
« blib/lib/Net/DHCPv6/Packet.pm ↑ Summary lib/Net/DHCPv6/Option/ClientFqdn.pm »
1 #!/bin/false
2 # ABSTRACT: NIS Domain Name option (code 29) -- RFC 1035 domain name
3 # PODNAME: Net::DHCPv6::Option::NisDomainName
4 15 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Net::DHCPv6::Option::NisDomainName;
7 15 $Net::DHCPv6::Option::NisDomainName::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 2 ▶ my ( $domain ) = @_;
Subroutine _encode_domain: called CC=3 SCAR=11.8
21 2 ▶ return chr( 0 ) unless defined $domain && CORE::length( $domain );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $domain and length $domain 0 2 2
Condition33%1/3
defined $domain and length $domain
!ll&&!rl&&r
002
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 2 my @labels = split m/[.]/, $domain;
23 2 return join( $EMPTY, map { pack( 'C', CORE::length ) . $_ } @labels ) . chr( 0 );
24 }
25  
26 sub _read_labels_at {
27 1 ▶ my ( $payload, $offset_ref, $len, $depth ) = @_;
Subroutine _read_labels_at: called CC=11 SCAR=31.7
28 1 ▶ $depth //= 0;
Condition50%1/2
$depth //= 0
l!l
01
MC/DC0%0/1
$depth //= 0
$depth
Truth table50%1/2
A
A= $depth
Aresult
11
00
29 1 my @labels;
30 1 ▶ while ( ${$offset_ref} < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if (${$offset_ref;} < $len) 4 0 4
31 4 my $llen = unpack( 'C', substr( $payload, ${$offset_ref}, 1 ) );
32 4 ▶ if ( $llen == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($llen == 0) 1 3 4
33 1 ++${$offset_ref};
34 1 last;
35 }
36 3 ▶ if ( ( $llen & $DN_COMPRESS_MASK ) == $DN_COMPRESS_MASK ) { ## no critic (Bangs::ProhibitBitwiseOperators ValuesAndExpressions::ProhibitMagicNumbers)
Branch: 1 branch
BranchTrueFalseTotal
if (($llen & $Net::DHCPv6::Option::NisDomainName::DN_COMPRESS_MASK) == $Net::DHCPv6::Option::NisDomainName::DN_COMPRESS_MASK) 0 3 3
37 0 ▶ if ( $Net::DHCPv6::Option::FOLLOW_COMPRESSION ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::DHCPv6::Option::FOLLOW_COMPRESSION) 0 0 0
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 0 Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer in domain name' );
52 }
53 3 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Invalid domain label length' ) if $llen > $DN_LABEL_MASK;
Branch: 1 branch
BranchTrueFalseTotal
if $llen > $Net::DHCPv6::Option::NisDomainName::DN_LABEL_MASK 0 3 3
54 3 ++${$offset_ref};
55 Net::DHCPv6::X::Truncated->throw( message => 'Truncated domain label' )
56 3 ▶ if ${$offset_ref} + $llen > $len;
Branch: 1 branch
BranchTrueFalseTotal
if ${$offset_ref;} + $llen > $len 0 3 3
57 3 push @labels, substr( $payload, ${$offset_ref}, $llen );
58 3 ${$offset_ref} += $llen;
59 }
60 1 return @labels;
61 }
62  
63 sub _decode_domain {
64 1 ▶ my ( $payload ) = @_;
Subroutine _decode_domain: called CC=2 SCAR=7.0
65 1 ▶ return $EMPTY unless CORE::length( $payload );
Branch: 1 branch
BranchTrueFalseTotal
unless length $payload 0 1 1
66 1 my $offset = 0;
67 1 my @labels = _read_labels_at( $payload, \$offset, CORE::length( $payload ) );
68 1 return join( '.', @labels );
69 }
70  
71 sub new {
72 3 ▶ my ( $class, %args ) = @_;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
73 3 ▶ croak 'NisDomainName requires domain_name' unless defined $args{domain_name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"domain_name"} 1 2 3
74 2 $args{code} = $OPTION_NIS_DOMAIN_NAME;
75 2 $args{data} = _encode_domain( $args{domain_name} );
76 2 my $self = $class->SUPER::new( %args );
77 2 $self->{domain_name} = $args{domain_name};
78 2 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 1 ▶ my ( $class, $code, $payload ) = @_;
Subroutine from_bytes_inner: called CC=1 SCAR=0.0
Pod documented
85 1 my $name = _decode_domain( $payload );
86 1 return $class->new( domain_name => $name );
87 }
88  
89 15 $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_NIS_DOMAIN_NAME} = __PACKAGE__;
90 15 1;
91  
92 __END__
« blib/lib/Net/DHCPv6/Packet.pm ↑ Summary lib/Net/DHCPv6/Option/ClientFqdn.pm »