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