| 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.002'; | |||||||||||
| 8 | 15 | ▶ | use Net::DHCPv6::OptionList; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 15 | ▶ | use Carp qw( croak ); | ||||||||||
|
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 parent 'Net::DHCPv6::Option'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 15 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 15 | my $EMPTY = q(); | |||||||||||
| 15 | |||||||||||||
| 16 | my %SUBOPT_DECODE = ( | ||||||||||||
| 17 | 1 | ▶ | 1 => sub { my ( $v ) = @_; return { subopt => 1, type => 'address', value => $v } }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 1 | ▶ | 2 => sub { my ( $v ) = @_; return { subopt => 2, type => 'fqdn', value => $v } }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 1 | ▶ | 3 => sub { my ( $v ) = @_; return { subopt => 3, type => 'domain', value => $v } }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 15 | ); | |||||||||||
| 21 | |||||||||||||
| 22 | sub new { | ||||||||||||
| 23 | 1 | ▶ | my ( $class, %args ) = @_; | ||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 24 | 1 | $args{code} = $OPTION_NTP_SERVER; | |||||||||||
| 25 | 1 | ▶ | my $entries = $args{entries} // []; | ||||||||||
|
Condition50%1/2
$args{"entries"} // []
MC/DC0%0/1
$args{"entries"} // []
$args{"entries"}
Truth table50%1/2
A
A= $args{"entries"}
| |||||||||||||
| 26 | $args{data} = | ||||||||||||
| 27 | 1 | join( $EMPTY, map { pack( 'n n', $_->{subopt}, CORE::length( $_->{value} ) ) . $_->{value} } @{$entries} ); | |||||||||||
| 28 | 1 | my $self = $class->SUPER::new( %args ); | |||||||||||
| 29 | 1 | $self->{entries} = $entries; | |||||||||||
| 30 | 1 | return bless $self, $class; | |||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | 5 | ▶ | sub entries { return shift->{entries} } | ||||||||||
|
Subroutine
entries: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 34 | |||||||||||||
| 35 | sub from_bytes_inner { | ||||||||||||
| 36 | 1 | ▶ | my ( $class, $code, $payload ) = @_; | ||||||||||
|
Subroutine
from_bytes_inner: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||
| 37 | 1 | my @entries; | |||||||||||
| 38 | 1 | my $len = CORE::length( $payload ); | |||||||||||
| 39 | 1 | my $off = 0; | |||||||||||
| 40 | 1 | ▶ | while ( $off + 4 <= $len ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | 3 | my $sc = unpack( 'n', substr( $payload, $off, 2 ) ); | |||||||||||
| 42 | 3 | my $slen = unpack( 'n', substr( $payload, $off + 2, 2 ) ); | |||||||||||
| 43 | 3 | $off += 4; | |||||||||||
| 44 | 3 | ▶ | Net::DHCPv6::X::Truncated->throw( message => 'Truncated NtpServer sub-option' ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | if $off + $slen > $len; | ||||||||||||
| 46 | 3 | my $sv = substr( $payload, $off, $slen ); | |||||||||||
| 47 | 3 | $off += $slen; | |||||||||||
| 48 | 3 | my $decoder = $SUBOPT_DECODE{$sc}; | |||||||||||
| 49 | 3 | ▶ | if ( $decoder ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 50 | 3 | push @entries, $decoder->( $sv ); | |||||||||||
| 51 | } | ||||||||||||
| 52 | else { | ||||||||||||
| 53 | 0 | push @entries, { subopt => $sc, value => $sv }; | |||||||||||
| 54 | } | ||||||||||||
| 55 | } | ||||||||||||
| 56 | 1 | ▶ | Net::DHCPv6::X::Truncated->throw( message => 'Truncated NtpServer sub-option header' ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | if $off != $len; | ||||||||||||
| 58 | 1 | return $class->new( entries => \@entries ); | |||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | 15 | $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_NTP_SERVER} = __PACKAGE__; | |||||||||||
| 62 | 15 | 1; | |||||||||||
| 63 | |||||||||||||
| 64 | __END__ | ||||||||||||