lib/Net/DHCPv6/Option/IAPrefix.pm

filter: Statementstmt 92.4% 61 / 66 Branchbran 50.0% 2 / 4 Conditioncond 50.0% 6 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 83.3% 15 / 18 Podpod 100% 11 / 11 totaltotal 80.5% 95 / 118 CC 8 SCAR 11.1
CC
8
Cov
84%
new
7.6
from_bytes_inner
2.0
options
2.0
CRAP 3.0
« lib/Net/DHCPv6/Option/SntpServers.pm ↑ Summary lib/Net/DHCPv6/Option/Auth.pm »
1 #!/bin/false
2 # ABSTRACT: IA Prefix option (code 26) -- prefix delegation sub-option
3 # PODNAME: Net::DHCPv6::Option::IAPrefix
4 15 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Net::DHCPv6::Option::IAPrefix;
7 15 $Net::DHCPv6::Option::IAPrefix::VERSION = '0.003';
8 15 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use Net::DHCPv6::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
10 $IPV6_ADDR_LEN $OPTION_IAPREFIX
11 15 );
12 15 ▶use Net::DHCPv6::OptionList ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use Net::DHCPv6::X::Truncated ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 15 ▶use parent 'Net::DHCPv6::Option';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 15 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 15 my $IA_PREFIX_HDR = 25; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
18 15 my $LIFETIME_WIRE_LEN = 8; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
19 15 my $PLEN_OFFSET = 9; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
20  
21 22 ▶sub new {
Subroutine new: called CC=7 SCAR=20.2
Pod documented
22 22 my ( $class, %args ) = @_;
23 22 my $addr = $class->_pick_addr( \%args, 'address' );
24 22 ▶ croak 'IAPrefix requires address' unless $addr && CORE::length( $addr ) == $IPV6_ADDR_LEN;
Branch: 1 branch
BranchTrueFalseTotal
unless $addr and length $addr == $Net::DHCPv6::Option::IAPrefix::IPV6_ADDR_LEN 0 22 22
Condition33%1/3
$addr and length $addr == $Net::DHCPv6::Option::IAPrefix::IPV6_ADDR_LEN
!ll&&!rl&&r
0022
MC/DC0%0/2
$addr and length $addr == $Net::DHCPv6::Option::IAPrefix::IPV6_ADDR_LEN
$addr length $addr == $Net::DHCPv6::Option::IAPrefix::IPV6_ADDR_LEN
Truth table33%1/3
A and B
A= $addrB= length $addr == $Net::DHCPv6::Option::IAPrefix::IPV6_ADDR_LEN
ABresult
0X0
100
111
25 22 $args{code} = $OPTION_IAPREFIX;
26 22 ▶ $args{preferred_lifetime} = $args{preferred_lifetime} // 0;
Condition50%1/2
$args{"preferred_lifetime"} // 0
l!l
220
MC/DC0%0/1
$args{"preferred_lifetime"} // 0
$args{"preferred_lifetime"}
Truth table50%1/2
A
A= $args{"preferred_lifetime"}
Aresult
11
00
27 22 ▶ $args{valid_lifetime} = $args{valid_lifetime} // 0;
Condition50%1/2
$args{"valid_lifetime"} // 0
l!l
220
MC/DC0%0/1
$args{"valid_lifetime"} // 0
$args{"valid_lifetime"}
Truth table50%1/2
A
A= $args{"valid_lifetime"}
Aresult
11
00
28 22 ▶ $args{prefix_length} = $args{prefix_length} // 0;
Condition50%1/2
$args{"prefix_length"} // 0
l!l
220
MC/DC0%0/1
$args{"prefix_length"} // 0
$args{"prefix_length"}
Truth table50%1/2
A
A= $args{"prefix_length"}
Aresult
11
00
29 22 ▶ $args{options} = $args{options} // Net::DHCPv6::OptionList->new;
Condition66%2/3
$args{"options"} // "Net::DHCPv6::OptionList"->new
l!l&&r!l&&!r
2110
MC/DC0%0/2
$args{"options"} // "Net::DHCPv6::OptionList"->new
$args{"options"} "Net::DHCPv6::OptionList"->new
Truth table66%2/3
A // B
A= $args{"options"}B= "Net::DHCPv6::OptionList"->new
ABresult
1X1
011
000
30 my $payload =
31 pack( 'N N', $args{preferred_lifetime}, $args{valid_lifetime} )
32 . pack( 'C', $args{prefix_length} )
33 . $addr
34 22 . $args{options}->as_bytes;
35 22 $args{data} = $payload;
36 22 my $self = $class->SUPER::new( %args );
37 22 $self->{address} = $addr;
38 22 $self->{preferred_lifetime} = $args{preferred_lifetime};
39 22 $self->{valid_lifetime} = $args{valid_lifetime};
40 22 $self->{prefix_length} = $args{prefix_length};
41 22 $self->{options} = $args{options};
42 22 return bless $self, $class;
43 }
44  
45 5 ▶sub address_raw { return shift->{address} }
Subroutine address_raw: called CC=1 SCAR=0.0
Pod documented
46  
47 4 ▶sub address {
Subroutine address: called CC=1 SCAR=0.0
Pod documented
48 4 my $self = shift;
49 4 return $self->_format_ipv6( $self->{address} );
50 }
51 12 ▶sub preferred_lifetime { return shift->{preferred_lifetime} }
Subroutine preferred_lifetime: called CC=1 SCAR=0.0
Pod documented
52 12 ▶sub valid_lifetime { return shift->{valid_lifetime} }
Subroutine valid_lifetime: called CC=1 SCAR=0.0
Pod documented
53 9 ▶sub prefix_length { return shift->{prefix_length} }
Subroutine prefix_length: called CC=1 SCAR=0.0
Pod documented
54 0 ▶sub options { return shift->{options} }
Subroutine options: not called CC=1 SCAR=6.9
Pod documented
55  
56 0 ▶sub add_option {
Subroutine add_option: not called CC=1 SCAR=6.9
Pod documented
57 0 my ( $self, $option ) = @_;
58 0 return $self->{options}->add_option( $option );
59 }
60  
61 0 ▶sub get_option {
Subroutine get_option: not called CC=1 SCAR=6.9
Pod documented
62 0 my ( $self, $code ) = @_;
63 0 return $self->{options}->get_option( $code );
64 }
65  
66 21 ▶sub from_bytes_inner {
Subroutine from_bytes_inner: called CC=2 SCAR=7.0
Pod documented
67 21 my ( $class, $code, $payload ) = @_;
68 21 ▶ Net::DHCPv6::X::Truncated->throw( message => 'Truncated IAPrefix option' )
Branch: 1 branch
BranchTrueFalseTotal
if length $payload < $IA_PREFIX_HDR 0 21 21
69 if CORE::length( $payload ) < $IA_PREFIX_HDR;
70 21 my ( $pl, $vl ) = unpack( 'N N', substr( $payload, 0, $LIFETIME_WIRE_LEN ) );
71 21 my $plen = unpack( 'C', substr( $payload, $LIFETIME_WIRE_LEN, 1 ) );
72 21 my $addr = substr( $payload, $PLEN_OFFSET, $IPV6_ADDR_LEN );
73 21 my $opt_data = substr( $payload, $IA_PREFIX_HDR );
74 21 my $opts = Net::DHCPv6::OptionList->from_bytes( $opt_data );
75 21 return $class->new(
76 address_raw => $addr,
77 preferred_lifetime => $pl,
78 valid_lifetime => $vl,
79 prefix_length => $plen,
80 options => $opts,
81 );
82 }
83  
84 22 ▶sub as_bytes {
Subroutine as_bytes: called CC=1 SCAR=0.0
Pod documented
85 22 my $self = shift;
86 my $payload =
87 pack( 'N N', $self->{preferred_lifetime}, $self->{valid_lifetime} )
88 . pack( 'C', $self->{prefix_length} )
89 . $self->{address}
90 22 . $self->{options}->as_bytes;
91 22 return pack( 'nn', $self->{code}, CORE::length( $payload ) ) . $payload;
92 }
93  
94 15 $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_IAPREFIX} = __PACKAGE__;
95  
96 15 1;
97  
98 __END__
« lib/Net/DHCPv6/Option/SntpServers.pm ↑ Summary lib/Net/DHCPv6/Option/Auth.pm »