lib/Net/DHCPv6/Option/NtpServer.pm

filter: Statementstmt 98.3% 59 / 60 Branchbran 62.5% 5 / 8 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 12 / 12 Podpod 100% 3 / 3 totaltotal 93.0% 80 / 86 CC 6 SCAR 8.4
CC
6
Cov
93%
from_bytes_inner
5.1
new
2.0
BEGIN
1.0
CRAP 2.3
« lib/Net/DHCPv6/Option.pm ↑ Summary lib/Net/DHCPv6/Option/IANA.pm »
1 #!/bin/false
2 # ABSTRACT: NTP Server option (code 56) -- sub-options for NTP configuration per RFC 5908
3 # PODNAME: Net::DHCPv6::Option::NtpServer
4 15 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Net::DHCPv6::Option::NtpServer;
7 15 $Net::DHCPv6::Option::NtpServer::VERSION = '0.003';
8 15 ▶use Net::DHCPv6::OptionList ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use Net::DHCPv6::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
10 $OPTION_NTP_SERVER
11 15 );
12 15 ▶use Net::DHCPv6::X::Truncated ();
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 namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 15 my $EMPTY = q();
16 15 my $NTP_SUBOPT_ADDR = 1;
17 15 my $NTP_SUBOPT_DOMAIN = 3; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
18 15 my $NTP_SUBOPT_FQDN = 2;
19 15 my $NTP_SUBOPT_HDR_LEN = 4; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
20  
21 my %SUBOPT_DECODE = (
22 1 ▶ $NTP_SUBOPT_ADDR => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
23 1 my ( $v ) = @_;
24 1 return { subopt => $NTP_SUBOPT_ADDR, type => 'address', value => $v };
25 },
26 1 ▶ $NTP_SUBOPT_FQDN => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
27 1 my ( $v ) = @_;
28 1 return { subopt => $NTP_SUBOPT_FQDN, type => 'fqdn', value => $v };
29 },
30 1 ▶ $NTP_SUBOPT_DOMAIN => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
31 1 my ( $v ) = @_;
32 1 return { subopt => $NTP_SUBOPT_DOMAIN, type => 'domain', value => $v };
33 },
34 15 );
35  
36 1 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
37 1 my ( $class, %args ) = @_;
38 1 $args{code} = $OPTION_NTP_SERVER;
39 1 ▶ my $entries = $args{entries} // [];
Condition50%1/2
$args{"entries"} // []
l!l
10
MC/DC0%0/1
$args{"entries"} // []
$args{"entries"}
Truth table50%1/2
A
A= $args{"entries"}
Aresult
11
00
40 $args{data} =
41 1 join( $EMPTY, map { pack( 'n n', $_->{subopt}, CORE::length( $_->{value} ) ) . $_->{value} } @{$entries} );
42 1 my $self = $class->SUPER::new( %args );
43 1 $self->{entries} = $entries;
44 1 return bless $self, $class;
45 }
46  
47 5 ▶sub entries { return shift->{entries} }
Subroutine entries: called CC=1 SCAR=0.0
Pod documented
48  
49 1 ▶sub from_bytes_inner {
Subroutine from_bytes_inner: called CC=5 SCAR=16.3
Pod documented
50 1 my ( $class, $code, $payload ) = @_;
51 1 my @decoded;
52 1 my $len = CORE::length( $payload );
53 1 my $off = 0;
54 1 ▶ while ( $off + $NTP_SUBOPT_HDR_LEN <= $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($off + $NTP_SUBOPT_HDR_LEN <= $len) 3 1 4
55 3 my $sc = unpack( 'n', substr( $payload, $off, 2 ) );
56 3 my $slen = unpack( 'n', substr( $payload, $off + 2, 2 ) );
57 3 $off += $NTP_SUBOPT_HDR_LEN;
58 3 ▶ Net::DHCPv6::X::Truncated->throw( message => 'Truncated NtpServer sub-option' )
Branch: 1 branch
BranchTrueFalseTotal
if $off + $slen > $len 0 3 3
59 if $off + $slen > $len;
60 3 my $sv = substr( $payload, $off, $slen );
61 3 $off += $slen;
62 3 my $decoder = $SUBOPT_DECODE{$sc};
63 3 ▶ if ( $decoder ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decoder) { } 3 0 3
64 3 push @decoded, $decoder->( $sv );
65 }
66 else {
67 0 push @decoded, { subopt => $sc, value => $sv };
68 }
69 }
70 1 ▶ Net::DHCPv6::X::Truncated->throw( message => 'Truncated NtpServer sub-option header' )
Branch: 1 branch
BranchTrueFalseTotal
if $off != $len 0 1 1
71 if $off != $len;
72 1 return $class->new( entries => \@decoded );
73 }
74  
75 15 $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_NTP_SERVER} = __PACKAGE__;
76 15 1;
77  
78 __END__
« lib/Net/DHCPv6/Option.pm ↑ Summary lib/Net/DHCPv6/Option/IANA.pm »