lib/Net/DHCPv6/Packet.pm

filter: Statementstmt 100% 63 / 63 Branchbran 64.2% 9 / 14 Conditioncond 53.3% 8 / 15 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 100% 17 / 17 Podpod 90.0% 9 / 10 totaltotal 83.7% 108 / 129 CC 13 SCAR 14.9
CC
13
Cov
87%
new
9.7
from_bytes
6.2
BEGIN
1.0
CRAP 4.5
« lib/Net/DHCPv6/Option/SipServerD.pm ↑ Summary lib/Net/DHCPv6/Helpers.pm »
1 #!/bin/false
2 # ABSTRACT: DHCPv6 packet base class
3 # PODNAME: Net::DHCPv6::Packet
4 29 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Net::DHCPv6::Packet;
7 29 $Net::DHCPv6::Packet::VERSION = '0.003';
8 29 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 29 ▶use Net::DHCPv6::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
10 $RELAY_FORW $RELAY_REPLY
11 29 );
12 29 ▶use Net::DHCPv6::OptionList ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 29 ▶use Net::DHCPv6::Packet::Relay ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 29 ▶use Net::DHCPv6::X::BadMessage ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 29 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 29 my $TX_ID_MAX = 0xFFFFFF; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
18 29 my $TX_ID_BYTES = 3; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
19 29 my $HDR_SIZE = 4; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
20  
21 12 ▶sub new {
Subroutine new: called CC=8 SCAR=22.7
Pod undocumented
22 12 my ( $class, @argv ) = @_;
23 12 ▶ if ( @argv == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@argv == 1) 1 11 12
24 1 return $class->from_bytes( $argv[0] );
25 }
26 11 ▶ croak 'Packet->new: no arguments' unless @argv;
Branch: 1 branch
BranchTrueFalseTotal
unless @argv 0 11 11
27 11 my %args = @argv;
28 11 ▶ croak 'Packet->new: msg_type is required' unless defined $args{msg_type};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"msg_type"} 0 11 11
29 11 ▶ croak 'Packet->new: transaction_id is required' unless defined $args{transaction_id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"transaction_id"} 0 11 11
30 croak 'transaction_id must fit in 24 bits'
31 11 ▶ if $args{transaction_id} < 0 || $args{transaction_id} > $TX_ID_MAX;
Branch: 1 branch
BranchTrueFalseTotal
if $args{"transaction_id"} < 0 or $args{"transaction_id"} > $TX_ID_MAX 0 11 11
Condition33%1/3
$args{"transaction_id"} < 0 or $args{"transaction_id"} > $TX_ID_MAX
l!l&&r!l&&!r
0011
MC/DC0%0/2
$args{"transaction_id"} < 0 or $args{"transaction_id"} > $TX_ID_MAX
$args{"transaction_id"} < 0 $args{"transaction_id"} > $TX_ID_MAX
Truth table33%1/3
A or B
A= $args{"transaction_id"} < 0B= $args{"transaction_id"} > $TX_ID_MAX
ABresult
1X1
011
000
32 11 ▶ $args{options} = $args{options} // Net::DHCPv6::OptionList->new;
Condition33%1/3
$args{"options"} // "Net::DHCPv6::OptionList"->new
l!l&&r!l&&!r
0110
MC/DC0%0/2
$args{"options"} // "Net::DHCPv6::OptionList"->new
$args{"options"} "Net::DHCPv6::OptionList"->new
Truth table33%1/3
A // B
A= $args{"options"}B= "Net::DHCPv6::OptionList"->new
ABresult
1X1
011
000
33 my $self = {
34 msg_type => $args{msg_type},
35 transaction_id => $args{transaction_id},
36 options => $args{options},
37 11 };
38 11 return bless $self, $class;
39 }
40  
41 40 ▶sub msg_type { return shift->{msg_type} }
Subroutine msg_type: called CC=1 SCAR=0.0
Pod documented
42 34 ▶sub transaction_id { return shift->{transaction_id} }
Subroutine transaction_id: called CC=1 SCAR=0.0
Pod documented
43 44 ▶sub options { return shift->{options} }
Subroutine options: called CC=1 SCAR=0.0
Pod documented
44  
45 8 ▶sub add_option {
Subroutine add_option: called CC=1 SCAR=0.0
Pod documented
46 8 my ( $self, $option ) = @_;
47 8 return $self->{options}->add_option( $option );
48 }
49  
50 11 ▶sub get_option {
Subroutine get_option: called CC=1 SCAR=0.0
Pod documented
51 11 my ( $self, $code ) = @_;
52 11 return $self->{options}->get_option( $code );
53 }
54  
55 9 ▶sub as_bytes {
Subroutine as_bytes: called CC=1 SCAR=0.0
Pod documented
56 9 my $self = shift;
57 9 my $tid = substr( pack( 'N', $self->{transaction_id} ), 1, $TX_ID_BYTES );
58 9 my $opts = $self->{options}->as_bytes;
59 9 return pack( 'C', $self->{msg_type} ) . $tid . $opts;
60 }
61  
62 69 ▶sub from_bytes {
Subroutine from_bytes: called CC=6 SCAR=18.2
Pod documented
63 69 my ( $class, $bytes ) = @_;
64 69 ▶ Net::DHCPv6::X::BadMessage->throw( message => 'Empty packet data' )
Branch: 1 branch
BranchTrueFalseTotal
if not defined $bytes or length $bytes < $HDR_SIZE 0 69 69
Condition33%1/3
not defined $bytes or length $bytes < $HDR_SIZE
l!l&&r!l&&!r
0069
MC/DC0%0/2
not defined $bytes or length $bytes < $HDR_SIZE
not defined $bytes length $bytes < $HDR_SIZE
Truth table33%1/3
not(A) or B
A= not defined $bytesB= length $bytes < $HDR_SIZE
ABresult
1X1
011
000
65 if !defined $bytes || CORE::length( $bytes ) < $HDR_SIZE;
66 69 my $msg_type = unpack( 'C', substr( $bytes, 0, 1 ) );
67  
68 69 ▶ if ( $msg_type == $RELAY_FORW || $msg_type == $RELAY_REPLY ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg_type == $Net::DHCPv6::Packet::RELAY_FORW or $msg_type == $Net::DHCPv6::Packet::RELAY_REPLY) 5 64 69
Condition100%3/3
$msg_type == $Net::DHCPv6::Packet::RELAY_FORW or $msg_type == $Net::DHCPv6::Packet::RELAY_REPLY
l!l&&r!l&&!r
3264
MC/DC100%2/2
$msg_type == $Net::DHCPv6::Packet::RELAY_FORW or $msg_type == $Net::DHCPv6::Packet::RELAY_REPLY
$msg_type == $Net::DHCPv6::Packet::RELAY_FORW $msg_type == $Net::DHCPv6::Packet::RELAY_REPLY
Truth table100%3/3
A or B
A= $msg_type == $Net::DHCPv6::Packet::RELAY_FORWB= $msg_type == $Net::DHCPv6::Packet::RELAY_REPLY
ABresult
1X1
011
000
69 5 return Net::DHCPv6::Packet::Relay->from_bytes( $bytes );
70 }
71  
72 64 my $tid = unpack( 'N', chr( 0 ) . substr( $bytes, 1, $TX_ID_BYTES ) );
73 64 my $opts_bytes = substr( $bytes, $HDR_SIZE );
74  
75 64 ▶ my $subclass = $Net::DHCPv6::Packet::MESSAGE_CLASS{$msg_type} || $class;
Condition66%2/3
$Net::DHCPv6::Packet::MESSAGE_CLASS{$msg_type} || $class
l!l&&r!l&&!r
6310
MC/DC0%0/2
$Net::DHCPv6::Packet::MESSAGE_CLASS{$msg_type} || $class
$Net::DHCPv6::Packet::MESSAGE_CLASS{$msg_type} $class
Truth table66%2/3
A || B
A= $Net::DHCPv6::Packet::MESSAGE_CLASS{$msg_type}B= $class
ABresult
1X1
011
000
76 64 my $opts = Net::DHCPv6::OptionList->from_bytes( $opts_bytes );
77 64 my $packet = bless {
78 msg_type => $msg_type,
79 transaction_id => $tid,
80 options => $opts,
81 }, $subclass;
82 64 return $packet;
83 }
84  
85 10 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod documented
86 10 my $self = shift;
87 10 return $Net::DHCPv6::Constants::REV_MESSAGE_TYPE{ $self->{msg_type} };
88 }
89  
90 2 ▶sub msg_type_name { return shift->type }
Subroutine msg_type_name: called CC=1 SCAR=0.0
Pod documented
91  
92 29 our %MESSAGE_CLASS;
93  
94 29 1;
95  
96 __END__
« lib/Net/DHCPv6/Option/SipServerD.pm ↑ Summary lib/Net/DHCPv6/Helpers.pm »