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

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