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 blib/lib/Net/DHCPv6/Option/IATA.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.002';
8 15 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use Net::DHCPv6::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use Net::DHCPv6::OptionList;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use Net::DHCPv6::X::Truncated;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use parent 'Net::DHCPv6::Option';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 15 my $IA_PREFIX_HDR = 25; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
16 15 my $LIFETIME_WIRE_LEN = 8; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
17 15 my $PLEN_OFFSET = 9; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
18  
19 sub new {
20 22 ▶ my ( $class, %args ) = @_;
Subroutine new: called CC=7 SCAR=20.2
Pod documented
21 22 my $addr = $class->_pick_addr( \%args, 'address' );
22 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
23 22 $args{code} = $OPTION_IAPREFIX;
24 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
25 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
26 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
27 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
28 my $payload =
29 pack( 'N N', $args{preferred_lifetime}, $args{valid_lifetime} )
30 . pack( 'C', $args{prefix_length} )
31 . $addr
32 22 . $args{options}->as_bytes;
33 22 $args{data} = $payload;
34 22 my $self = $class->SUPER::new( %args );
35 22 $self->{address} = $addr;
36 22 $self->{preferred_lifetime} = $args{preferred_lifetime};
37 22 $self->{valid_lifetime} = $args{valid_lifetime};
38 22 $self->{prefix_length} = $args{prefix_length};
39 22 $self->{options} = $args{options};
40 22 return bless $self, $class;
41 }
42  
43 5 ▶sub address_raw { return shift->{address} }
Subroutine address_raw: called CC=1 SCAR=0.0
Pod documented
44  
45 sub address {
46 4 ▶ my $self = shift;
Subroutine address: called CC=1 SCAR=0.0
Pod documented
47 4 return $self->_format_ipv6( $self->{address} );
48 }
49 12 ▶sub preferred_lifetime { return shift->{preferred_lifetime} }
Subroutine preferred_lifetime: called CC=1 SCAR=0.0
Pod documented
50 12 ▶sub valid_lifetime { return shift->{valid_lifetime} }
Subroutine valid_lifetime: called CC=1 SCAR=0.0
Pod documented
51 9 ▶sub prefix_length { return shift->{prefix_length} }
Subroutine prefix_length: called CC=1 SCAR=0.0
Pod documented
52 0 ▶sub options { return shift->{options} }
Subroutine options: not called CC=1 SCAR=6.9
Pod documented
53  
54 sub add_option {
55 0 ▶ my ( $self, $option ) = @_;
Subroutine add_option: not called CC=1 SCAR=6.9
Pod documented
56 0 return $self->{options}->add_option( $option );
57 }
58  
59 sub get_option {
60 0 ▶ my ( $self, $code ) = @_;
Subroutine get_option: not called CC=1 SCAR=6.9
Pod documented
61 0 return $self->{options}->get_option( $code );
62 }
63  
64 sub from_bytes_inner {
65 21 ▶ my ( $class, $code, $payload ) = @_;
Subroutine from_bytes_inner: called CC=2 SCAR=7.0
Pod documented
66 21 ▶ Net::DHCPv6::X::Truncated->throw( message => 'Truncated IAPrefix option' )
Branch: 1 branch
BranchTrueFalseTotal
if length $payload < $IA_PREFIX_HDR 0 21 21
67 if CORE::length( $payload ) < $IA_PREFIX_HDR;
68 21 my ( $pl, $vl ) = unpack( 'N N', substr( $payload, 0, $LIFETIME_WIRE_LEN ) );
69 21 my $plen = unpack( 'C', substr( $payload, $LIFETIME_WIRE_LEN, 1 ) );
70 21 my $addr = substr( $payload, $PLEN_OFFSET, $IPV6_ADDR_LEN );
71 21 my $opt_data = substr( $payload, $IA_PREFIX_HDR );
72 21 my $opts = Net::DHCPv6::OptionList->from_bytes( $opt_data );
73 21 return $class->new(
74 address_raw => $addr,
75 preferred_lifetime => $pl,
76 valid_lifetime => $vl,
77 prefix_length => $plen,
78 options => $opts,
79 );
80 }
81  
82 sub as_bytes {
83 22 ▶ my $self = shift;
Subroutine as_bytes: called CC=1 SCAR=0.0
Pod documented
84 my $payload =
85 pack( 'N N', $self->{preferred_lifetime}, $self->{valid_lifetime} )
86 . pack( 'C', $self->{prefix_length} )
87 . $self->{address}
88 22 . $self->{options}->as_bytes;
89 22 return pack( 'nn', $self->{code}, CORE::length( $payload ) ) . $payload;
90 }
91  
92 15 $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_IAPREFIX} = __PACKAGE__;
93  
94 15 1;
95  
96 __END__
« lib/Net/DHCPv6/Option/SntpServers.pm ↑ Summary blib/lib/Net/DHCPv6/Option/IATA.pm »