lib/Net/DHCPv6/Option/SipServerD.pm

filter: Statementstmt 100% 94 / 94 Branchbran 65.3% 17 / 26 Conditioncond 70.0% 7 / 10 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 15 / 15 Podpod 100% 3 / 3 totaltotal 90.2% 138 / 153 CC 18 SCAR 16.6
CC
18
Cov
91%
_read_labels_at
11.2
new
4.0
_encode_domain
3.2
CRAP 5.3
« lib/Net/DHCPv6/Option/DomainList.pm ↑ Summary blib/lib/Net/DHCPv6/Option/ClientLinkLayerAddr.pm »
1 #!/bin/false
2 # ABSTRACT: SIP Server Domain Name option (code 21) -- list of domain names
3 # PODNAME: Net::DHCPv6::Option::SipServerD
4 15 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Net::DHCPv6::Option::SipServerD;
7 15 $Net::DHCPv6::Option::SipServerD::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 9 ▶ my ( $domain ) = @_;
Subroutine _encode_domain: called CC=3 SCAR=11.8
21 9 ▶ return chr( 0 ) unless defined $domain && CORE::length( $domain );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $domain and length $domain 0 9 9
Condition33%1/3
defined $domain and length $domain
!ll&&!rl&&r
009
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 9 my @labels = split m/[.]/, $domain;
23 9 return join( $EMPTY, map { pack( 'C', CORE::length ) . $_ } @labels ) . chr( 0 );
24 }
25  
26 sub _read_labels_at {
27 10 ▶ my ( $payload, $offset_ref, $len, $depth ) = @_;
Subroutine _read_labels_at: called CC=11 SCAR=24.1
28 10 ▶ $depth //= 0;
Condition100%2/2
$depth //= 0
l!l
19
MC/DC100%1/1
$depth //= 0
$depth
Truth table100%2/2
A
A= $depth
Aresult
11
00
29 10 my @labels;
30 10 ▶ 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) 8 28 36
33 8 ++${$offset_ref};
34 8 last;
35 }
36 28 ▶ if ( ( $llen & $DN_COMPRESS_MASK ) == $DN_COMPRESS_MASK ) { ## no critic (Bangs::ProhibitBitwiseOperators ValuesAndExpressions::ProhibitMagicNumbers)
Branch: 1 branch
BranchTrueFalseTotal
if (($llen & $Net::DHCPv6::Option::SipServerD::DN_COMPRESS_MASK) == $Net::DHCPv6::Option::SipServerD::DN_COMPRESS_MASK) 2 26 28
37 2 ▶ if ( $Net::DHCPv6::Option::FOLLOW_COMPRESSION ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::DHCPv6::Option::FOLLOW_COMPRESSION) 1 1 2
38 Net::DHCPv6::X::Truncated->throw( message => 'Truncated compression pointer' )
39 1 ▶ if ${$offset_ref} + 2 > $len;
Branch: 1 branch
BranchTrueFalseTotal
if ${$offset_ref;} + 2 > $len 0 1 1
40 my $ptr =
41 1 ( ( $llen & $DN_LABEL_MASK ) << 8 ) | unpack( 'C', substr( $payload, ${$offset_ref} + 1, 1 ) ); ## no critic (Bangs::ProhibitBitwiseOperators ValuesAndExpressions::ProhibitMagicNumbers)
42 1 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer out of range' )
Branch: 1 branch
BranchTrueFalseTotal
if $ptr >= $len 0 1 1
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 26 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Invalid domain label length' ) if $llen > $DN_LABEL_MASK;
Branch: 1 branch
BranchTrueFalseTotal
if $llen > $Net::DHCPv6::Option::SipServerD::DN_LABEL_MASK 0 26 26
54 26 ++${$offset_ref};
55 Net::DHCPv6::X::Truncated->throw( message => 'Truncated domain label' )
56 26 ▶ if ${$offset_ref} + $llen > $len;
Branch: 1 branch
BranchTrueFalseTotal
if ${$offset_ref;} + $llen > $len 0 26 26
57 26 push @labels, substr( $payload, ${$offset_ref}, $llen );
58 26 ${$offset_ref} += $llen;
59 }
60 9 return @labels;
61 }
62  
63 sub _decode_domains {
64 4 ▶ my ( $payload ) = @_;
Subroutine _decode_domains: called CC=3 SCAR=11.0
65 4 my @domain_list;
66 4 my $offset = 0;
67 4 my $len = CORE::length( $payload );
68 4 ▶ while ( $offset < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < $len) 9 3 12
69 9 my @labels = _read_labels_at( $payload, \$offset, $len );
70 8 ▶ push @domain_list, @labels ? join( '.', @labels ) : $EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
@labels ? : 8 0 8
71 }
72 3 return \@domain_list;
73 }
74  
75 sub new {
76 6 ▶ my ( $class, %args ) = @_;
Subroutine new: called CC=4 SCAR=13.9
Pod documented
77 6 ▶ my $domains = $args{domains} // $args{data} // [];
Condition80%4/5
($args{"domains"} // $args{"data"}) // []
l!l
42
$args{"domains"} // $args{"data"}
l!l&&r!l&&!r
402
MC/DC50%1/2
($args{"domains"} // $args{"data"}) // []
$args{"domains"} $args{"data"}
Truth table66%2/3
A // B
A= $args{"domains"}B= $args{"data"}
ABresult
1X1
011
000
78 6 ▶ $domains = [$domains] unless is_plain_arrayref( $domains );
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_plain_arrayref($domains) 0 6 6
79 6 $args{code} = $OPTION_SIP_SERVER_D;
80 6 $args{data} = join( $EMPTY, map { _encode_domain( $_ ) } @{$domains} );
81 6 my $self = $class->SUPER::new( %args );
82 6 $self->{domains} = $domains;
83 6 return bless $self, $class;
84 }
85  
86 6 ▶sub domains { return shift->{domains} }
Subroutine domains: called CC=1 SCAR=0.0
Pod documented
87  
88 sub from_bytes_inner {
89 4 ▶ my ( $class, $code, $payload ) = @_;
Subroutine from_bytes_inner: called CC=1 SCAR=0.0
Pod documented
90 4 my $domains = _decode_domains( $payload );
91 3 return $class->new( domains => $domains );
92 }
93  
94 15 $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_SIP_SERVER_D} = __PACKAGE__;
95 15 1;
96  
97 __END__
« lib/Net/DHCPv6/Option/DomainList.pm ↑ Summary blib/lib/Net/DHCPv6/Option/ClientLinkLayerAddr.pm »