lib/Net/DHCPv6/Option.pm

filter: Statementstmt 100% 45 / 45 Branchbran 83.3% 5 / 6 Conditioncond 72.7% 8 / 11 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 100% 12 / 12 Podpod 100% 6 / 6 totaltotal 90.8% 79 / 87 CC 8 SCAR 9.2
CC
8
Cov
94%
from_bytes
5.0
new
3.1
as_bytes
2.1
CRAP 2.5
« lib/Net/DHCPv6/Option/IAAddr.pm ↑ Summary lib/Net/DHCPv6/Option/NtpServer.pm »
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
BranchTrueFalseTotal
unless defined $args{"code"} 0 419 419
20 419 ▶ my $self = { code => $args{code}, data => $args{data} // $EMPTY };
Condition66%2/3
$args{"data"} // $EMPTY
l!l&&r!l&&!r
41270
MC/DC0%0/2
$args{"data"} // $EMPTY
$args{"data"} $EMPTY
Truth table66%2/3
A // B
A= $args{"data"}B= $EMPTY
ABresult
1X1
011
000
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
l!l&&r!l&&!r
7000
MC/DC0%0/2
$self->{"data"} // $EMPTY
$self->{"data"} $EMPTY
Truth table33%1/3
A // B
A= $self->{"data"}B= $EMPTY
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if not defined $bytes or length $bytes < $OPT_HDR_SIZE 2 51 53
Condition100%3/3
not defined $bytes or length $bytes < $OPT_HDR_SIZE
l!l&&r!l&&!r
1151
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if $OPT_HDR_SIZE + $optlen > length $bytes 1 50 51
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'
l!l
473
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}
Aresult
11
00
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__
« lib/Net/DHCPv6/Option/IAAddr.pm ↑ Summary lib/Net/DHCPv6/Option/NtpServer.pm »