| 1 | #!/usr/bin/false | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: DHCPv6 option base class | ||||||||||||||||||||||||||||
| 3 | # PODNAME: Net::DHCPv6::Option | ||||||||||||||||||||||||||||
| 4 | package Net::DHCPv6::Option; | ||||||||||||||||||||||||||||
| 5 | 65 | $Net::DHCPv6::Option::VERSION = '0.001'; | |||||||||||||||||||||||||||
| 6 | 65 | ▶ | use strictures 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 65 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 65 | ▶ | use Net::DHCPv6::Constants; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 65 | ▶ | use Net::DHCPv6::OptionList; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 65 | ▶ | use Net::DHCPv6::X::Truncated; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 65 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 65 | our $FOLLOW_COMPRESSION = 0; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | sub new { | ||||||||||||||||||||||||||||
| 16 | 396 | ▶ | my ( $class, %args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 396 | ▶ | croak 'Option->new: code is required' unless defined $args{code}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 396 | ▶ | my $self = { code => $args{code}, data => $args{data} // '' }; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args{"data"} // ""
MC/DC100%1/1
$args{"data"} // ""
$args{"data"}
Truth table100%2/2
A
A= $args{"data"}
| |||||||||||||||||||||||||||||
| 19 | 396 | bless $self, $class; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 364 | ▶ | sub code { shift->{code} } | ||||||||||||||||||||||||||
|
Subroutine
code: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 11 | ▶ | sub data { shift->{data} } | ||||||||||||||||||||||||||
|
Subroutine
data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | sub type { | ||||||||||||||||||||||||||||
| 26 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 4 | return $Net::DHCPv6::Constants::REV_OPTION_CODE{ $self->{code} }; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub as_bytes { | ||||||||||||||||||||||||||||
| 31 | 35 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
as_bytes: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 35 | ▶ | my $data = $self->{data} // ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"data"} // ""
MC/DC0%0/1
$self->{"data"} // ""
$self->{"data"}
Truth table50%1/2
A
A= $self->{"data"}
| |||||||||||||||||||||||||||||
| 33 | 35 | return pack( 'nn', $self->{code}, CORE::length( $data ) ) . $data; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | sub from_bytes { | ||||||||||||||||||||||||||||
| 37 | 45 | ▶ | my ( $class, $bytes ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
from_bytes: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 45 | ▶ | Net::DHCPv6::X::Truncated->throw( message => 'Option->from_bytes: need at least 4 bytes for TLV header' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $bytes and length $bytes >= 4
MC/DC0%0/2
defined $bytes and length $bytes >= 4
defined $bytes
length $bytes >= 4
Truth table33%1/3
A and B
A= defined $bytesB= length $bytes >= 4
| |||||||||||||||||||||||||||||
| 39 | unless defined $bytes && CORE::length( $bytes ) >= 4; | ||||||||||||||||||||||||||||
| 40 | 45 | my $code = unpack( 'n', substr( $bytes, 0, 2 ) ); | |||||||||||||||||||||||||||
| 41 | 45 | my $optlen = unpack( 'n', substr( $bytes, 2, 2 ) ); | |||||||||||||||||||||||||||
| 42 | 45 | ▶ | Net::DHCPv6::X::Truncated->throw( message => 'Truncated option TLV payload' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | if 4 + $optlen > CORE::length( $bytes ); | ||||||||||||||||||||||||||||
| 44 | 45 | my $data = substr( $bytes, 4, $optlen ); | |||||||||||||||||||||||||||
| 45 | 45 | my $remain = substr( $bytes, 4 + $optlen ); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 45 | ▶ | my $class_name = $Net::DHCPv6::OptionList::OPTION_CLASS{$code} | ||||||||||||||||||||||||||
|
Condition100%2/2
$Net::DHCPv6::OptionList::OPTION_CLASS{$code} || 'Net::DHCPv6::Option::Generic'
MC/DC100%1/1
$Net::DHCPv6::OptionList::OPTION_CLASS{$code} || 'Net::DHCPv6::Option::Generic'
$Net::DHCPv6::OptionList::OPTION_CLASS{$code}
Truth table100%2/2
A
A= $Net::DHCPv6::OptionList::OPTION_CLASS{$code}
| |||||||||||||||||||||||||||||
| 48 | || 'Net::DHCPv6::Option::Generic'; | ||||||||||||||||||||||||||||
| 49 | 45 | my $option = $class_name->from_bytes_inner( $code, $data ); | |||||||||||||||||||||||||||
| 50 | 45 | return ( $option, $remain ); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 65 | 1; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | __END__ | ||||||||||||||||||||||||||||