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

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 77 CC 3 SCAR 11.0
CC
3
Cov
0%
new
6.0
from_bytes_inner
6.0
iaid
2.0
CRAP 3.0
1 #!/usr/bin/false
2 # ABSTRACT: Identity Association for Temporary Addresses option (code 4)
3 # PODNAME: Net::DHCPv6::Option::IATA
4 package Net::DHCPv6::Option::IATA;
5 $Net::DHCPv6::Option::IATA::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 'IATA requires iaid' unless defined $args{iaid};
17 $args{code} = $OPTION_IA_TA;
18 $args{options} = $args{options} // Net::DHCPv6::OptionList->new;
19 my $data = pack( 'N', $args{iaid} ) . $args{options}->as_bytes;
20 $args{data} = $data;
21 my $self = $class->SUPER::new( %args );
22 $self->{iaid} = $args{iaid};
23 $self->{options} = $args{options};
24 bless $self, $class;
25 }
26  
27 sub iaid { shift->{iaid} }
28 sub options { shift->{options} }
29  
30 sub add_option {
31 my ( $self, $option ) = @_;
32 $self->{options}->add_option( $option );
33 }
34  
35 sub get_option {
36 my ( $self, $code ) = @_;
37 return $self->{options}->get_option( $code );
38 }
39  
40 sub from_bytes_inner {
41 my ( $class, $code, $data ) = @_;
42 Net::DHCPv6::X::Truncated->throw( message => 'Truncated IATA option' )
43 if CORE::length( $data ) < 4;
44 my $iaid = unpack( 'N', substr( $data, 0, 4 ) );
45 my $opt_data = substr( $data, 4 );
46 my $opts = Net::DHCPv6::OptionList->from_bytes( $opt_data );
47 return $class->new( iaid => $iaid, options => $opts );
48 }
49  
50 sub as_bytes {
51 my $self = shift;
52 my $data = pack( 'N', $self->{iaid} ) . $self->{options}->as_bytes;
53 return pack( 'nn', $self->{code}, CORE::length( $data ) ) . $data;
54 }
55  
56 $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_IA_TA} = __PACKAGE__;
57  
58 1;
59  
60 __END__