blib/lib/Net/DHCP/Packet/Attributes.pm

filter: Statementstmt 90.7% 118 / 130 Branchbran 80.7% 42 / 52 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 30 / 30 Podpod 100% 22 / 22 totaltotal 90.6% 212 / 234 CC 27 SCAR 7.9
CC
27
Cov
88%
hlen
4.8
sname
3.0
file
3.0
CRAP 2.2
« Build ↑ Summary blib/lib/Net/DHCP.pm »
1 #!/bin/false
2 # PODNAME: Net::DHCP::Packet::Attributes
3 # Author : D. Hamstead
4 # Original Author: F. van Dun, S. Hadinger
5 # ABSTRACT: Attribute methods for Net::DHCP::Packet
6 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use 5.8.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 package Net::DHCP::Packet::Attributes;
11 12 $Net::DHCP::Packet::Attributes::VERSION = '0.7';
12 # standard module declaration
13 12 our ( @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS );
14 12 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 12 @ISA = qw(Exporter);
16 12 @EXPORT = qw( );
17 12 @EXPORT_OK = qw(
18 comment op htype hlen hops xid secs flags ciaddr
19 ciaddrRaw yiaddr yiaddrRaw siaddr siaddrRaw giaddr giaddrRaw
20 chaddr chaddrRaw sname file isDhcp padding
21 );
22 12 %EXPORT_TAGS = ( all => \@EXPORT_OK );
23  
24 12 ▶use Carp qw/ carp /;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 12 ▶use Net::DHCP::Packet::IPv4Utils qw( packinet unpackinet );
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 #=======================================================================
28 # comment attribute : enables transaction number identification
29 sub comment {
30 2 ▶ my $self = shift;
Subroutine comment: called CC=2 SCAR=7.6
Pod documented
31 2 ▶ if (@_) { $self->{comment} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
32 2 return $self->{comment};
33 }
34  
35 # op attribute
36 sub op {
37 3 ▶ my $self = shift;
Subroutine op: called CC=2 SCAR=6.9
Pod documented
38 3 ▶ if (@_) { $self->{op} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
39 3 return $self->{op};
40 }
41  
42 # htype attribute
43 sub htype {
44 3 ▶ my $self = shift;
Subroutine htype: called CC=2 SCAR=6.9
Pod documented
45 3 ▶ if (@_) { $self->{htype} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
46 3 return $self->{htype};
47 }
48  
49 # hlen attribute
50 sub hlen {
51 3 ▶ my $self = shift;
Subroutine hlen: called CC=4 SCAR=15.8
Pod documented
52 3 ▶ if (@_) { $self->{hlen} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
53 3 ▶ if ( $self->{hlen} < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"hlen"} < 0) 0 3 3
54 0 carp( 'hlen must not be < 0 (currently ' . $self->{hlen} . ')' );
55 0 $self->{hlen} = 0;
56 }
57 3 ▶ if ( $self->{hlen} > 16 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"hlen"} > 16) 0 3 3
58 0 carp( 'hlen must not be > 16 (currently ' . $self->{hlen} . ')' );
59 0 $self->{hlen} = 16;
60 }
61 3 return $self->{hlen};
62 }
63  
64 # hops attribute
65 sub hops {
66 3 ▶ my $self = shift;
Subroutine hops: called CC=2 SCAR=6.9
Pod documented
67 3 ▶ if (@_) { $self->{hops} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
68 3 return $self->{hops};
69 }
70  
71 # xid attribute
72 sub xid {
73 3 ▶ my $self = shift;
Subroutine xid: called CC=2 SCAR=6.9
Pod documented
74 3 ▶ if (@_) { $self->{xid} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
75 3 return $self->{xid};
76 }
77  
78 # secs attribute
79 sub secs {
80 1 ▶ my $self = shift;
Subroutine secs: called CC=2 SCAR=7.6
Pod documented
81 1 ▶ if (@_) { $self->{secs} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
82 1 return $self->{secs};
83 }
84  
85 # flags attribute
86 sub flags {
87 2 ▶ my $self = shift;
Subroutine flags: called CC=2 SCAR=6.9
Pod documented
88 2 ▶ if (@_) { $self->{flags} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
89 2 return $self->{flags};
90 }
91  
92 # ciaddr attribute
93 sub ciaddr {
94 3 ▶ my $self = shift;
Subroutine ciaddr: called CC=2 SCAR=6.9
Pod documented
95 3 ▶ if (@_) { $self->{ciaddr} = packinet(shift) }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
96 3 return unpackinet( $self->{ciaddr} );
97 }
98  
99 # ciaddr attribute, Raw version
100 sub ciaddrRaw {
101 2 ▶ my $self = shift;
Subroutine ciaddrRaw: called CC=2 SCAR=7.6
Pod documented
102 2 ▶ if (@_) { $self->{ciaddr} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
103 2 return $self->{ciaddr};
104 }
105  
106 # yiaddr attribute
107 sub yiaddr {
108 3 ▶ my $self = shift;
Subroutine yiaddr: called CC=2 SCAR=6.9
Pod documented
109 3 ▶ if (@_) { $self->{yiaddr} = packinet(shift) }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
110 3 return unpackinet( $self->{yiaddr} );
111 }
112  
113 # yiaddr attribute, Raw version
114 sub yiaddrRaw {
115 2 ▶ my $self = shift;
Subroutine yiaddrRaw: called CC=2 SCAR=7.6
Pod documented
116 2 ▶ if (@_) { $self->{yiaddr} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
117 2 return $self->{yiaddr};
118 }
119  
120 # siaddr attribute
121 sub siaddr {
122 3 ▶ my $self = shift;
Subroutine siaddr: called CC=2 SCAR=6.9
Pod documented
123 3 ▶ if (@_) { $self->{siaddr} = packinet(shift) }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
124 3 return unpackinet( $self->{siaddr} );
125 }
126  
127 # siaddr attribute, Raw version
128 sub siaddrRaw {
129 2 ▶ my $self = shift;
Subroutine siaddrRaw: called CC=2 SCAR=7.6
Pod documented
130 2 ▶ if (@_) { $self->{siaddr} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
131 2 return $self->{siaddr};
132 }
133  
134 # giaddr attribute
135 sub giaddr {
136 3 ▶ my $self = shift;
Subroutine giaddr: called CC=2 SCAR=6.9
Pod documented
137 3 ▶ if (@_) { $self->{giaddr} = packinet(shift) }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
138 3 return unpackinet( $self->{giaddr} );
139 }
140  
141 # giaddr attribute, Raw version
142 sub giaddrRaw {
143 2 ▶ my $self = shift;
Subroutine giaddrRaw: called CC=2 SCAR=7.6
Pod documented
144 2 ▶ if (@_) { $self->{giaddr} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
145 2 return $self->{giaddr};
146 }
147  
148 # chaddr attribute
149 sub chaddr {
150 3 ▶ my $self = shift;
Subroutine chaddr: called CC=2 SCAR=6.9
Pod documented
151 3 ▶ if (@_) { $self->{chaddr} = pack( 'H*', shift ) }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
152 3 return unpack( 'H*', $self->{chaddr} );
153 }
154  
155 # chaddr attribute, Raw version
156 sub chaddrRaw {
157 1 ▶ my $self = shift;
Subroutine chaddrRaw: called CC=2 SCAR=7.6
Pod documented
158 1 ▶ if (@_) { $self->{chaddr} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
159 1 return $self->{chaddr};
160 }
161  
162 # sname attribute
163 sub sname {
164 12 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
165 3 ▶ my $self = shift;
Subroutine sname: called CC=3 SCAR=11.0
Pod documented
166 3 ▶ if (@_) { $self->{sname} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
167 3 ▶ if ( length( $self->{sname} ) > 63 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"sname"} > 63) 1 2 3
168 carp( sprintf q|'sname' must not be > 63 bytes, (currently %d)|,
169 1 length( $self->{sname} ));
170 1 $self->{sname} = substr( $self->{sname}, 0, 63 );
171 }
172 3 return $self->{sname};
173 }
174  
175 # file attribute
176 sub file {
177 12 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
178 3 ▶ my $self = shift;
Subroutine file: called CC=3 SCAR=11.0
Pod documented
179 3 ▶ if (@_) { $self->{file} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
180 3 ▶ if ( length( $self->{file} ) > 127 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"file"} > 127) 1 2 3
181 carp( sprintf q|'file' must not be > 127 bytes, (currently %d)|,
182 1 length( $self->{file} ));
183 1 $self->{file} = substr( $self->{file}, 0, 127 );
184 }
185 3 return $self->{file};
186 }
187  
188 # is it DHCP or BOOTP
189 # -> DHCP needs magic cookie and options
190 sub isDhcp {
191 2 ▶ my $self = shift;
Subroutine isDhcp: called CC=2 SCAR=7.6
Pod documented
192 2 ▶ if (@_) { $self->{isDhcp} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
193 2 return $self->{isDhcp};
194 }
195  
196 # padding attribute
197 sub padding {
198 4 ▶ my $self = shift;
Subroutine padding: called CC=2 SCAR=6.9
Pod documented
199 4 ▶ if (@_) { $self->{padding} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 2 4
200 4 return $self->{padding};
201 }
202  
203 #=======================================================================
204  
205 12 1;
206  
207 __END__
« Build ↑ Summary blib/lib/Net/DHCP.pm »