blib/lib/Net/DHCPv6/Option/IAPD.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 7 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 91 CC 3 SCAR 10.6
CC
3
Cov
0%
new
6.0
from_bytes_inner
6.0
iaid
2.0
CRAP 2.9
1 #!/usr/bin/false
2 # ABSTRACT: Identity Association for Prefix Delegation option (code 25)
3 # PODNAME: Net::DHCPv6::Option::IAPD
4 package Net::DHCPv6::Option::IAPD;
5 $Net::DHCPv6::Option::IAPD::VERSION = '0.001';
6 use strictures 2;
7 use Carp qw(croak);
8 use Net::DHCPv6::Constants;
9 use Net::DHCPv6::OptionList;
10 use Net::DHCPv6::X::Truncated;
11 use parent 'Net::DHCPv6::Option';
12 use namespace::clean;
13  
14 sub new {
15 my ( $class, %args ) = @_;
16 croak 'IAPD requires iaid' unless defined $args{iaid};
17 $args{code} = $OPTION_IA_PD;
18 $args{t1} = $args{t1} // 0;
19 $args{t2} = $args{t2} // 0;
20 $args{options} = $args{options} // Net::DHCPv6::OptionList->new;
21 my $data = pack( 'N N N', $args{iaid}, $args{t1}, $args{t2} ) . $args{options}->as_bytes;
22 $args{data} = $data;
23 my $self = $class->SUPER::new( %args );
24 $self->{iaid} = $args{iaid};
25 $self->{t1} = $args{t1};
26 $self->{t2} = $args{t2};
27 $self->{options} = $args{options};
28 bless $self, $class;
29 }
30  
31 sub iaid { shift->{iaid} }
32 sub t1 { shift->{t1} }
33 sub t2 { shift->{t2} }
34 sub options { shift->{options} }
35  
36 sub add_option {
37 my ( $self, $option ) = @_;
38 $self->{options}->add_option( $option );
39 }
40  
41 sub get_option {
42 my ( $self, $code ) = @_;
43 return $self->{options}->get_option( $code );
44 }
45  
46 sub from_bytes_inner {
47 my ( $class, $code, $data ) = @_;
48 Net::DHCPv6::X::Truncated->throw( message => 'Truncated IAPD option' )
49 if CORE::length( $data ) < 12;
50 my ( $iaid, $t1, $t2 ) = unpack( 'N N N', substr( $data, 0, 12 ) );
51 my $opt_data = substr( $data, 12 );
52 my $opts = Net::DHCPv6::OptionList->from_bytes( $opt_data );
53 return $class->new( iaid => $iaid, t1 => $t1, t2 => $t2, options => $opts );
54 }
55  
56 sub as_bytes {
57 my $self = shift;
58 my $data = pack( 'N N N', $self->{iaid}, $self->{t1}, $self->{t2} ) . $self->{options}->as_bytes;
59 return pack( 'nn', $self->{code}, CORE::length( $data ) ) . $data;
60 }
61  
62 $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_IA_PD} = __PACKAGE__;
63  
64 1;
65  
66 __END__