lib/Net/DHCPv6/Option/SipServerD.pm

filter: Statementstmt 100% 76 / 76 Branchbran 66.6% 16 / 24 Conditioncond 62.5% 5 / 8 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 14 / 14 Podpod 100% 3 / 3 totaltotal 89.1% 115 / 129 CC 16 SCAR 14.8
CC
16
Cov
90%
_read_labels_at
9.2
new
4.0
_encode_domain
3.2
CRAP 4.4
« lib/Net/DHCPv6/Option/DomainList.pm ↑ Summary Build »
1 #!/usr/bin/false
2 # ABSTRACT: SIP Server Domain Name option (code 21) — list of domain names
3 # PODNAME: Net::DHCPv6::Option::SipServerD
4 package Net::DHCPv6::Option::SipServerD;
5 15 $Net::DHCPv6::Option::SipServerD::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 Ref::Util qw(is_plain_arrayref);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub _encode_domain {
16 9 ▶ my ( $domain ) = @_;
Subroutine _encode_domain: called CC=3 SCAR=11.8
17 9 ▶ return "\x00" 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
18 9 my @labels = split m/\./, $domain;
19 9 join( '', map { pack( 'C', CORE::length ) . $_ } @labels ) . "\x00";
20 }
21  
22 sub _read_labels_at {
23 10 ▶ my ( $data, $offset_ref, $len ) = @_;
Subroutine _read_labels_at: called CC=9 SCAR=22.2
24 10 my @labels;
25 10 ▶ while ( $$offset_ref < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$offset_ref < $len) 36 0 36
26 36 my $llen = unpack( 'C', substr( $data, $$offset_ref, 1 ) );
27 36 ▶ if ( $llen == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($llen == 0) 8 28 36
28 8 ++$$offset_ref;
29 8 last;
30 }
31 28 ▶ if ( ( $llen & 0xC0 ) == 0xC0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($llen & 192) == 192) 2 26 28
32 2 ▶ if ( $Net::DHCPv6::Option::FOLLOW_COMPRESSION ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::DHCPv6::Option::FOLLOW_COMPRESSION) 1 1 2
33 1 ▶ Net::DHCPv6::X::Truncated->throw( message => 'Truncated compression pointer' )
Branch: 1 branch
BranchTrueFalseTotal
if $$offset_ref + 2 > $len 0 1 1
34 if $$offset_ref + 2 > $len;
35 1 my $ptr = ( ( $llen & 0x3F ) << 8 ) | unpack( 'C', substr( $data, $$offset_ref + 1, 1 ) );
36 1 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer out of range' )
Branch: 1 branch
BranchTrueFalseTotal
if $ptr >= $len 0 1 1
37 if $ptr >= $len;
38 1 $$offset_ref += 2;
39 1 my $ptr_ref = \$ptr;
40 1 push @labels, _read_labels_at( $data, $ptr_ref, $len );
41 1 last;
42 }
43 1 Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer in domain name' );
44 }
45 26 ▶ Net::DHCPv6::X::BadOption->throw( message => 'Invalid domain label length' ) if $llen > 63;
Branch: 1 branch
BranchTrueFalseTotal
if $llen > 63 0 26 26
46 26 ++$$offset_ref;
47 26 ▶ Net::DHCPv6::X::Truncated->throw( message => 'Truncated domain label' )
Branch: 1 branch
BranchTrueFalseTotal
if $$offset_ref + $llen > $len 0 26 26
48 if $$offset_ref + $llen > $len;
49 26 push @labels, substr( $data, $$offset_ref, $llen );
50 26 $$offset_ref += $llen;
51 }
52 9 return @labels;
53 }
54  
55 sub _decode_domains {
56 4 ▶ my ( $data ) = @_;
Subroutine _decode_domains: called CC=3 SCAR=11.0
57 4 my @domains;
58 4 my $offset = 0;
59 4 my $len = CORE::length( $data );
60 4 ▶ while ( $offset < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < $len) 9 3 12
61 9 my @labels = _read_labels_at( $data, \$offset, $len );
62 8 ▶ push @domains, @labels ? join( '.', @labels ) : '';
Branch: 1 branch
BranchTrueFalseTotal
@labels ? : 8 0 8
63 }
64 3 return \@domains;
65 }
66  
67 sub new {
68 6 ▶ my ( $class, %args ) = @_;
Subroutine new: called CC=4 SCAR=13.9
Pod documented
69 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
70 6 ▶ $domains = [$domains] unless is_plain_arrayref( $domains );
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_plain_arrayref($domains) 0 6 6
71 6 $args{code} = $OPTION_SIP_SERVER_D;
72 6 $args{data} = join( '', map { _encode_domain( $_ ) } @$domains );
73 6 my $self = $class->SUPER::new( %args );
74 6 $self->{domains} = $domains;
75 6 bless $self, $class;
76 }
77  
78 6 ▶sub domains { shift->{domains} }
Subroutine domains: called CC=1 SCAR=0.0
Pod documented
79  
80 sub from_bytes_inner {
81 4 ▶ my ( $class, $code, $data ) = @_;
Subroutine from_bytes_inner: called CC=1 SCAR=0.0
Pod documented
82 4 my $domains = _decode_domains( $data );
83 3 return $class->new( domains => $domains );
84 }
85  
86 15 $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_SIP_SERVER_D} = __PACKAGE__;
87 15 1;
88  
89 __END__
« lib/Net/DHCPv6/Option/DomainList.pm ↑ Summary Build »