lib/Net/DHCPv6/Option/AftrName.pm

filter: Statementstmt 89.7% 61 / 68 Branchbran 54.5% 12 / 22 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 13 / 13 Podpod 100% 3 / 3 totaltotal 81.0% 90 / 111 CC 13 SCAR 17.9
CC
13
Cov
80%
_read_labels_at
13.6
_encode_domain
3.2
_decode_domain
2.0
CRAP 6.0
« blib/lib/Net/DHCPv6/Option/VendorClass.pm ↑ Summary blib/lib/Net/DHCPv6/Option/PdExclude.pm »
1 #!/usr/bin/false
2 # ABSTRACT: AFTR Name option (code 88) — RFC 6334 domain name
3 # PODNAME: Net::DHCPv6::Option::AftrName
4 package Net::DHCPv6::Option::AftrName;
5 15 $Net::DHCPv6::Option::AftrName::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 namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub _encode_domain {
15 6 ▶ my ( $domain ) = @_;
Subroutine _encode_domain: called CC=3 SCAR=11.8
16 6 ▶ return "\x00" 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
17 6 my @labels = split m/\./, $domain;
18 6 join( '', map { pack( 'C', CORE::length ) . $_ } @labels ) . "\x00";
19 }
20  
21 sub _read_labels_at {
22 6 ▶ my ( $data, $offset_ref, $len ) = @_;
Subroutine _read_labels_at: called CC=9 SCAR=26.1
23 6 my @labels;
24 6 ▶ while ( $$offset_ref < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$offset_ref < $len) 22 0 22
25 22 my $llen = unpack( 'C', substr( $data, $$offset_ref, 1 ) );
26 22 ▶ if ( $llen == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($llen == 0) 5 17 22
27 5 ++$$offset_ref;
28 5 last;
29 }
30 17 ▶ if ( ( $llen & 0xC0 ) == 0xC0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($llen & 192) == 192) 1 16 17
31 1 ▶ if ( $Net::DHCPv6::Option::FOLLOW_COMPRESSION ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::DHCPv6::Option::FOLLOW_COMPRESSION) 0 1 1
32 0 ▶ Net::DHCPv6::X::Truncated->throw( message => 'Truncated compression pointer' )
Branch: 1 branch
BranchTrueFalseTotal
if $$offset_ref + 2 > $len 0 0 0
33 if $$offset_ref + 2 > $len;
34 0 my $ptr = ( ( $llen & 0x3F ) << 8 ) | unpack( 'C', substr( $data, $$offset_ref + 1, 1 ) );
35 0 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer out of range' )
Branch: 1 branch
BranchTrueFalseTotal
if $ptr >= $len 0 0 0
36 if $ptr >= $len;
37 0 $$offset_ref += 2;
38 0 my $ptr_ref = \$ptr;
39 0 push @labels, _read_labels_at( $data, $ptr_ref, $len );
40 0 last;
41 }
42 1 Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer in domain name' );
43 }
44 16 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Invalid domain label length' ) if $llen > 63;
Branch: 1 branch
BranchTrueFalseTotal
if $llen > 63 0 16 16
45 16 ++$$offset_ref;
46 16 ▶ Net::DHCPv6::X::Truncated->throw( message => 'Truncated domain label' )
Branch: 1 branch
BranchTrueFalseTotal
if $$offset_ref + $llen > $len 0 16 16
47 if $$offset_ref + $llen > $len;
48 16 push @labels, substr( $data, $$offset_ref, $llen );
49 16 $$offset_ref += $llen;
50 }
51 5 return @labels;
52 }
53  
54 sub _decode_domain {
55 6 ▶ my ( $data ) = @_;
Subroutine _decode_domain: called CC=2 SCAR=7.0
56 6 ▶ return '' unless CORE::length( $data );
Branch: 1 branch
BranchTrueFalseTotal
unless length $data 0 6 6
57 6 my $offset = 0;
58 6 my @labels = _read_labels_at( $data, \$offset, CORE::length( $data ) );
59 5 return join( '.', @labels );
60 }
61  
62 sub new {
63 7 ▶ my ( $class, %args ) = @_;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
64 7 ▶ croak 'AftrName requires domain_name' unless defined $args{domain_name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"domain_name"} 1 6 7
65 6 $args{code} = $OPTION_AFTR_NAME;
66 6 $args{data} = _encode_domain( $args{domain_name} );
67 6 my $self = $class->SUPER::new( %args );
68 6 $self->{domain_name} = $args{domain_name};
69 6 bless $self, $class;
70 }
71  
72 2 ▶sub domain_name { shift->{domain_name} }
Subroutine domain_name: called CC=1 SCAR=0.0
Pod documented
73  
74 sub from_bytes_inner {
75 6 ▶ my ( $class, $code, $data ) = @_;
Subroutine from_bytes_inner: called CC=1 SCAR=0.0
Pod documented
76 6 my $name = _decode_domain( $data );
77 5 return $class->new( domain_name => $name );
78 }
79  
80 15 $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_AFTR_NAME} = __PACKAGE__;
81 15 1;
82  
83 __END__
« blib/lib/Net/DHCPv6/Option/VendorClass.pm ↑ Summary blib/lib/Net/DHCPv6/Option/PdExclude.pm »