| 1 | #!/bin/false | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: DHCPv6 option base class | ||||||||||||||||||||||||||||
| 3 | # PODNAME: Net::DHCPv6::Option | ||||||||||||||||||||||||||||
| 4 | 83 | ▶ | use strictures 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package Net::DHCPv6::Option; | ||||||||||||||||||||||||||||
| 7 | 83 | $Net::DHCPv6::Option::VERSION = '0.003'; | |||||||||||||||||||||||||||
| 8 | 83 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 83 | ▶ | use Net::DHCPv6::Constants (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 83 | ▶ | use Net::DHCPv6::X::Truncated (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 83 | ▶ | use parent 'Net::DHCPv6::Helpers'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 83 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 83 | my $EMPTY = q(); | |||||||||||||||||||||||||||
| 14 | 83 | my $OPT_HDR_SIZE = 4; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers) | |||||||||||||||||||||||||||
| 15 | 83 | our $FOLLOW_COMPRESSION = 0; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 419 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 419 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||
| 19 | 419 | ▶ | croak 'Option->new: code is required' unless defined $args{code}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 419 | ▶ | my $self = { code => $args{code}, data => $args{data} // $EMPTY }; | ||||||||||||||||||||||||||
|
Condition66%2/3
$args{"data"} // $EMPTY
MC/DC0%0/2
$args{"data"} // $EMPTY
$args{"data"}
$EMPTY
Truth table66%2/3
A // B
A= $args{"data"}B= $EMPTY
| |||||||||||||||||||||||||||||
| 21 | 419 | return bless $self, $class; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 388 | ▶ | sub code { return shift->{code} } | ||||||||||||||||||||||||||
|
Subroutine
code: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 12 | ▶ | sub data { return shift->{data} } ## no critic (Bangs::ProhibitVagueNames) | ||||||||||||||||||||||||||
|
Subroutine
data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 6 | ▶ | sub type { | ||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 29 | 6 | return $Net::DHCPv6::Constants::REV_OPTION_CODE{ $self->{code} }; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 70 | ▶ | sub as_bytes { | ||||||||||||||||||||||||||
|
Subroutine
as_bytes: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 70 | my $self = shift; | |||||||||||||||||||||||||||
| 34 | 70 | ▶ | my $payload = $self->{data} // $EMPTY; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"data"} // $EMPTY
MC/DC0%0/2
$self->{"data"} // $EMPTY
$self->{"data"}
$EMPTY
Truth table33%1/3
A // B
A= $self->{"data"}B= $EMPTY
| |||||||||||||||||||||||||||||
| 35 | 70 | return pack( 'nn', $self->{code}, CORE::length( $payload ) ) . $payload; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 53 | ▶ | sub from_bytes { | ||||||||||||||||||||||||||
|
Subroutine
from_bytes: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 53 | my ( $class, $bytes ) = @_; | |||||||||||||||||||||||||||
| 40 | 53 | ▶ | Net::DHCPv6::X::Truncated->throw( message => 'Option->from_bytes: need at least 4 bytes for TLV header' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $bytes or length $bytes < $OPT_HDR_SIZE
MC/DC100%2/2
not defined $bytes or length $bytes < $OPT_HDR_SIZE
not defined $bytes
length $bytes < $OPT_HDR_SIZE
Truth table100%3/3
not(A) or B
A= not defined $bytesB= length $bytes < $OPT_HDR_SIZE
| |||||||||||||||||||||||||||||
| 41 | if !defined $bytes || CORE::length( $bytes ) < $OPT_HDR_SIZE; | ||||||||||||||||||||||||||||
| 42 | 51 | my $code = unpack( 'n', substr( $bytes, 0, 2 ) ); | |||||||||||||||||||||||||||
| 43 | 51 | my $optlen = unpack( 'n', substr( $bytes, 2, 2 ) ); | |||||||||||||||||||||||||||
| 44 | 51 | ▶ | Net::DHCPv6::X::Truncated->throw( message => 'Truncated option TLV payload' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | if $OPT_HDR_SIZE + $optlen > CORE::length( $bytes ); | ||||||||||||||||||||||||||||
| 46 | 50 | my $payload = substr( $bytes, $OPT_HDR_SIZE, $optlen ); | |||||||||||||||||||||||||||
| 47 | 50 | my $remain = substr( $bytes, $OPT_HDR_SIZE + $optlen ); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 50 | require Net::DHCPv6::OptionList; | |||||||||||||||||||||||||||
| 50 | 50 | ▶ | 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}
| |||||||||||||||||||||||||||||
| 51 | || 'Net::DHCPv6::Option::Generic'; | ||||||||||||||||||||||||||||
| 52 | 50 | my $option = $class_name->from_bytes_inner( $code, $payload ); | |||||||||||||||||||||||||||
| 53 | 50 | return ( $option, $remain ); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 83 | 1; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | __END__ | ||||||||||||||||||||||||||||