blib/lib/Net/DHCPv6.pm untested

filter: Statementstmt 0.0% 0 / 239 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 12 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 76 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 346 CC 6 SCAR 9.1
CC
6
Cov
0%
decode_or_croak
6.0
decode_or_null
6.0
decode_with_error
6.0
CRAP 2.5
1 #!/usr/bin/false
2 # ABSTRACT: DHCPv6 packet decoder/encoder
3 # PODNAME: Net::DHCPv6
4 package Net::DHCPv6;
5 $Net::DHCPv6::VERSION = '0.001';
6 use strictures 2;
7 use Carp qw(croak);
8 use Net::DHCPv6::DUID;
9  
10 # Option classes — loaded so they register in the dispatch tables
11 use Net::DHCPv6::Option::AftrName;
12 use Net::DHCPv6::Option::Auth;
13 use Net::DHCPv6::Option::BootfileParam;
14 use Net::DHCPv6::Option::BootfileUrl;
15 use Net::DHCPv6::Option::CaptivePortal;
16 use Net::DHCPv6::Option::ClientArchType;
17 use Net::DHCPv6::Option::ClientFqdn;
18 use Net::DHCPv6::Option::ClientId;
19 use Net::DHCPv6::Option::ClientLinkLayerAddr;
20 use Net::DHCPv6::Option::DnsServers;
21 use Net::DHCPv6::Option::DomainList;
22 use Net::DHCPv6::Option::ElapsedTime;
23 use Net::DHCPv6::Option::Generic;
24 use Net::DHCPv6::Option::IAAddr;
25 use Net::DHCPv6::Option::IANA;
26 use Net::DHCPv6::Option::IAPD;
27 use Net::DHCPv6::Option::IAPrefix;
28 use Net::DHCPv6::Option::IATA;
29 use Net::DHCPv6::Option::InfMaxRt;
30 use Net::DHCPv6::Option::InfoRefreshTime;
31 use Net::DHCPv6::Option::InterfaceId;
32 use Net::DHCPv6::Option::NewPosixTimezone;
33 use Net::DHCPv6::Option::NewTzdbTimezone;
34 use Net::DHCPv6::Option::NisDomainName;
35 use Net::DHCPv6::Option::NisServers;
36 use Net::DHCPv6::Option::NispDomainName;
37 use Net::DHCPv6::Option::NispServers;
38 use Net::DHCPv6::Option::NtpServer;
39 use Net::DHCPv6::Option::ORO;
40 use Net::DHCPv6::Option::PdExclude;
41 use Net::DHCPv6::Option::Preference;
42 use Net::DHCPv6::Option::RapidCommit;
43 use Net::DHCPv6::Option::ReconfAccept;
44 use Net::DHCPv6::Option::ReconfMsg;
45 use Net::DHCPv6::Option::RelayMsg;
46 use Net::DHCPv6::Option::RemoteId;
47 use Net::DHCPv6::Option::RSOO;
48 use Net::DHCPv6::Option::ServerId;
49 use Net::DHCPv6::Option::SipServerA;
50 use Net::DHCPv6::Option::SipServerD;
51 use Net::DHCPv6::Option::MudUrl;
52 use Net::DHCPv6::Option::SolMaxRt;
53 use Net::DHCPv6::Option::StatusCode;
54 use Net::DHCPv6::Option::SubscriberId;
55 use Net::DHCPv6::Option::Unicast;
56 use Net::DHCPv6::Option::UserClass;
57 use Net::DHCPv6::Option::VendorClass;
58 use Net::DHCPv6::Option::VendorOpts;
59  
60 # Message classes
61 use Net::DHCPv6::Message::Solicit;
62 use Net::DHCPv6::Message::Advertise;
63 use Net::DHCPv6::Message::Request;
64 use Net::DHCPv6::Message::Confirm;
65 use Net::DHCPv6::Message::Renew;
66 use Net::DHCPv6::Message::Rebind;
67 use Net::DHCPv6::Message::Reply;
68 use Net::DHCPv6::Message::Release;
69 use Net::DHCPv6::Message::Decline;
70 use Net::DHCPv6::Message::Reconfigure;
71 use Net::DHCPv6::Message::InformationRequest;
72 use Net::DHCPv6::Message::RelayForw;
73 use Net::DHCPv6::Message::RelayReply;
74  
75 use Net::DHCPv6::OptionList;
76 use Net::DHCPv6::Packet;
77 use namespace::clean;
78  
79 # Packet-level decoders
80 sub decode_or_croak {
81 my ( $class, $bytes ) = @_;
82 croak 'No data provided' unless defined $bytes && CORE::length( $bytes ) >= 4;
83 return Net::DHCPv6::Packet->from_bytes( $bytes );
84 }
85  
86 sub decode_or_null {
87 my ( $class, $bytes ) = @_;
88 return unless defined $bytes && CORE::length( $bytes ) >= 4;
89 my $packet;
90 eval { $packet = Net::DHCPv6::Packet->from_bytes( $bytes ); };
91 return $packet;
92 }
93  
94 sub decode_with_error {
95 my ( $class, $bytes ) = @_;
96 my $packet;
97 my $error;
98 if ( !defined $bytes || CORE::length( $bytes ) < 4 ) {
99 $error = 'No data provided';
100 }
101 else {
102 eval { $packet = Net::DHCPv6::Packet->from_bytes( $bytes ); 1 }
103 or do { $error = $@; };
104 }
105 return ( $packet, $error );
106 }
107  
108 # DUID streaming helpers
109 sub decode_duid_with_error {
110 my ( $class, $bytes ) = @_;
111 return Net::DHCPv6::DUID->try_from_bytes( $bytes );
112 }
113  
114 sub decode_duid_or_null {
115 my ( $class, $bytes ) = @_;
116 my ( $duid ) = Net::DHCPv6::DUID->try_from_bytes( $bytes );
117 return $duid;
118 }
119  
120 sub decode_duid_or_croak {
121 my ( $class, $bytes ) = @_;
122 my ( $duid, $error ) = Net::DHCPv6::DUID->try_from_bytes( $bytes );
123 croak $error if $error;
124 return $duid;
125 }
126  
127 # Option-list streaming helpers
128 sub decode_options_with_error {
129 my ( $class, $bytes ) = @_;
130 return Net::DHCPv6::OptionList->try_from_bytes( $bytes );
131 }
132  
133 sub decode_options_or_null {
134 my ( $class, $bytes ) = @_;
135 my ( $ol ) = Net::DHCPv6::OptionList->try_from_bytes( $bytes );
136 return $ol;
137 }
138  
139 sub decode_options_or_croak {
140 my ( $class, $bytes ) = @_;
141 my ( $ol, $error ) = Net::DHCPv6::OptionList->try_from_bytes( $bytes );
142 croak $error if $error;
143 return $ol;
144 }
145  
146 1;
147  
148 __END__