Zonemaster/Engine/Packet.pm

filter: Statementstmt 16.2% 20 / 123 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 15.7% 6 / 38 Podpod 100% 32 / 32 totaltotal 23.2% 58 / 249 CC 18 SCAR 19.2
CC
18
Cov
12%
get_records
30.0
new
12.0
answerfrom
12.0
CRAP 6.8
« Zonemaster/Engine/Normalization/Error.pm ↑ Summary Zonemaster/Engine/Constants.pm »
1 package Zonemaster::Engine::Packet;
2  
3 1 ▶use v5.16.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use version; our $VERSION = version->declare("v1.0.5");
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Class::Accessor 'antlers';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp qw( confess );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Zonemaster::Engine::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 has 'packet' => (
13 is => 'ro',
14 isa => 'Zonemaster::LDNS::Packet',
15 );
16  
17 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
18 0 my $proto = shift;
19 0 ▶ my $class = ref $proto || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
20 0 my $attrs = shift;
21  
22 0 my $packet = delete $attrs->{packet};
23 0 ▶ if ( %$attrs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$attrs) 0 0 0
24 0 confess "unexpected arguments: " . join ', ', sort keys %$attrs;
25 }
26  
27 0 return Class::Accessor::new( $class, { packet => $packet } );
28 }
29  
30 0 ▶sub timestamp { my ( $self, $time ) = @_; return $self->packet->timestamp( $time // () ); }
Subroutine timestamp: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
$time // ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$time // ()
$time ()
Truth table0%0/3
A // B
A= $timeB= ()
ABresult
1X1
011
000
31 0 ▶sub querytime { my ( $self, $value ) = @_; return $self->packet->querytime( $value // () ); }
Subroutine querytime: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
$value // ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$value // ()
$value ()
Truth table0%0/3
A // B
A= $valueB= ()
ABresult
1X1
011
000
32 0 ▶sub id { my ( $self, $id ) = @_; return $self->packet->id( $id // () ); }
Subroutine id: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
$id // ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$id // ()
$id ()
Truth table0%0/3
A // B
A= $idB= ()
ABresult
1X1
011
000
33 0 ▶sub opcode { my ( $self, $string ) = @_; return $self->packet->opcode( $string // () ); }
Subroutine opcode: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
$string // ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$string // ()
$string ()
Truth table0%0/3
A // B
A= $stringB= ()
ABresult
1X1
011
000
34 0 ▶sub rcode { my ( $self, $string ) = @_; return $self->packet->rcode( $string // () ); }
Subroutine rcode: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
$string // ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$string // ()
$string ()
Truth table0%0/3
A // B
A= $stringB= ()
ABresult
1X1
011
000
35 0 ▶sub edns_version { my ( $self, $version ) = @_; return $self->packet->edns_version( $version // () ); }
Subroutine edns_version: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
$version // ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$version // ()
$version ()
Truth table0%0/3
A // B
A= $versionB= ()
ABresult
1X1
011
000
36  
37 0 ▶sub type { my ( $self ) = @_; return $self->packet->type; }
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
38 0 ▶sub string { my ( $self ) = @_; return $self->packet->string; }
Subroutine string: not called CC=1 SCAR=6.9
Pod documented
39 0 ▶sub data { my ( $self ) = @_; return $self->packet->data; }
Subroutine data: not called CC=1 SCAR=6.9
Pod documented
40 0 ▶sub aa { my ( $self ) = @_; return $self->packet->aa; }
Subroutine aa: not called CC=1 SCAR=6.9
Pod documented
41 0 ▶sub do { my ( $self ) = @_; return $self->packet->do; }
Subroutine do: not called CC=1 SCAR=6.9
Pod documented
42 0 ▶sub ra { my ( $self ) = @_; return $self->packet->ra; }
Subroutine ra: not called CC=1 SCAR=6.9
Pod documented
43 0 ▶sub tc { my ( $self ) = @_; return $self->packet->tc; }
Subroutine tc: not called CC=1 SCAR=6.9
Pod documented
44 0 ▶sub question { my ( $self ) = @_; return $self->packet->question; }
Subroutine question: not called CC=1 SCAR=6.9
Pod documented
45 0 ▶sub authority { my ( $self ) = @_; return $self->packet->authority; }
Subroutine authority: not called CC=1 SCAR=6.9
Pod documented
46 0 ▶sub answer { my ( $self ) = @_; return $self->packet->answer; }
Subroutine answer: not called CC=1 SCAR=6.9
Pod documented
47 0 ▶sub additional { my ( $self ) = @_; return $self->packet->additional; }
Subroutine additional: not called CC=1 SCAR=6.9
Pod documented
48 0 ▶sub edns_size { my ( $self ) = @_; return $self->packet->edns_size; }
Subroutine edns_size: not called CC=1 SCAR=6.9
Pod documented
49 0 ▶sub edns_rcode { my ( $self ) = @_; return $self->packet->edns_rcode; }
Subroutine edns_rcode: not called CC=1 SCAR=6.9
Pod documented
50 0 ▶sub edns_data { my ( $self ) = @_; return $self->packet->edns_data; }
Subroutine edns_data: not called CC=1 SCAR=6.9
Pod documented
51 0 ▶sub edns_z { my ( $self ) = @_; return $self->packet->edns_z; }
Subroutine edns_z: not called CC=1 SCAR=6.9
Pod documented
52 0 ▶sub has_edns { my ( $self ) = @_; return $self->packet->has_edns; }
Subroutine has_edns: not called CC=1 SCAR=6.9
Pod documented
53  
54 0 ▶sub unique_push {
Subroutine unique_push: not called CC=1 SCAR=6.9
Pod documented
55 0 my ( $self, $section, $rr ) = @_;
56 0 return $self->packet->unique_push( $section, $rr );
57 }
58  
59 0 ▶sub no_such_record {
Subroutine no_such_record: not called CC=2 SCAR=17.9
Pod documented
60 0 my ( $self ) = @_;
61  
62 0 ▶ if ( $self->type eq 'nodata' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type eq 'nodata') { } 0 0 0
63 0 my ( $q ) = $self->question;
64 0 Zonemaster::Engine::Util::info( NO_SUCH_RECORD => { name => Zonemaster::Engine::Util::name( $q->name ), type => $q->type } );
65  
66 0 return 1;
67 }
68 else {
69 0 return;
70 }
71 }
72  
73 0 ▶sub no_such_name {
Subroutine no_such_name: not called CC=2 SCAR=17.9
Pod documented
74 0 my ( $self ) = @_;
75  
76 0 ▶ if ( $self->type eq 'nxdomain' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type eq 'nxdomain') { } 0 0 0
77 0 my ( $q ) = $self->question;
78 0 info( NO_SUCH_NAME => { name => name( $q->name ), type => $q->type } );
79  
80 0 return 1;
81 }
82 else {
83 0 return;
84 }
85 }
86  
87 0 ▶sub is_redirect {
Subroutine is_redirect: not called CC=2 SCAR=17.9
Pod documented
88 0 my ( $self ) = @_;
89  
90 0 ▶ if ( $self->type eq 'referral' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type eq 'referral') { } 0 0 0
91 0 my ( $q ) = $self->question;
92 0 my ( $a ) = $self->authority;
93 0 Zonemaster::Engine::Util::info(
94 IS_REDIRECT => {
95 name => Zonemaster::Engine::DNSName->from_string( $q->name ),
96 type => $q->type,
97 to => Zonemaster::Engine::DNSName->from_string( $a->name )
98 }
99 );
100  
101 0 return 1;
102 }
103 else {
104 0 return;
105 }
106 } ## end sub is_redirect
107  
108 0 ▶sub get_records {
Subroutine get_records: not called CC=5 SCAR=34.0
Pod documented
109 0 my ( $self, $type, @section ) = @_;
110 0 ▶ @section = qw(answer authority additional) if !@section;
Branch: 1 branch
BranchTrueFalseTotal
unless @section 0 0 0
111 0 my %sec = map { lc( $_ ) => 1 } @section;
112 0 my @raw;
113 0 $type = uc( $type );
114  
115 0 ▶ if ( $sec{'answer'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sec{"answer"}) 0 0 0
116 0 push @raw, grep { $_->type eq $type } $self->packet->answer;
117 }
118  
119 0 ▶ if ( $sec{'authority'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sec{"authority"}) 0 0 0
120 0 push @raw, grep { $_->type eq $type } $self->packet->authority;
121 }
122  
123 0 ▶ if ( $sec{'additional'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sec{"additional"}) 0 0 0
124 0 push @raw, grep { $_->type eq $type } $self->packet->additional;
125 }
126  
127 0 return @raw;
128 } ## end sub get_records
129  
130 0 ▶sub get_records_for_name {
Subroutine get_records_for_name: not called CC=1 SCAR=6.9
Pod documented
131 0 my ( $self, $type, $name, @section ) = @_;
132  
133 # Make sure $name is a Zonemaster::Engine::DNSName
134 0 $name = name( $name );
135  
136 0 return grep { name( $_->name ) eq $name } $self->get_records( $type, @section );
137 }
138  
139 0 ▶sub has_rrs_of_type_for_name {
Subroutine has_rrs_of_type_for_name: not called CC=1 SCAR=6.9
Pod documented
140 0 my ( $self, $type, $name, @section ) = @_;
141  
142 # Make sure $name is a Zonemaster::Engine::DNSName
143 0 $name = name( $name );
144  
145 0 return ( grep { name( $_->name ) eq $name } $self->get_records( $type, @section ) ) > 0;
146 }
147  
148 0 ▶sub answerfrom {
Subroutine answerfrom: not called CC=3 SCAR=24.8
Pod documented
149 0 my ( $self, @args ) = @_;
150  
151 0 ▶ if ( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 0 0
152 0 $self->packet->answerfrom( @args );
153 }
154  
155 0 ▶ my $from = $self->packet->answerfrom // '<unknown>';
Condition0%0/2
$self->packet->answerfrom // "<unknown>"
l!l
00
MC/DC0%0/1
$self->packet->answerfrom // "<unknown>"
$self->packet->answerfrom
Truth table0%0/2
A
A= $self->packet->answerfrom
Aresult
11
00
156  
157 0 return $from;
158 }
159  
160 0 ▶sub TO_JSON {
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod documented
161 0 my ( $self ) = @_;
162  
163 0 return { 'Zonemaster::Engine::Packet' => $self->packet };
164 }
165  
166 1 1;
167  
168 =head1 NAME
169  
170 Zonemaster::Engine::Packet - wrapping object for L<Zonemaster::LDNS::Packet> objects
171  
172 =head1 SYNOPSIS
173  
174 my $packet = $ns->query('iis.se', 'NS');
175 my @rrs = $packet->get_records('ns');
176  
177 =head1 ATTRIBUTES
178  
179 =over
180  
181 =item packet
182  
183 Holds the L<Zonemaster::LDNS::Packet> the object is wrapping.
184  
185 =back
186  
187 =head1 CONSTRUCTORS
188  
189 =over
190  
191 =item new
192  
193 Construct a new instance.
194  
195 =back
196  
197 =head1 METHODS
198  
199 =over
200  
201 =item no_such_record
202  
203 Returns true if the packet represents an existing DNS node lacking any records of the requested type.
204  
205 =item no_such_name
206  
207 Returns true if the packet represents a nonexistent DNS node.
208  
209 =item is_redirect
210  
211 Returns true if the packet is a redirect to another set of nameservers.
212  
213 =item get_records($type[, @section])
214  
215 Returns the L<Zonemaster::LDNS::RR> objects of the requested type in the packet.
216 If the optional C<@section> argument is given, and is a list of C<answer>,
217 C<authority> and C<additional>, only RRs from those sections are returned.
218  
219 =item get_records_for_name($type, $name[, @section])
220  
221 Returns all L<Zonemaster::LDNS::RR> objects for the given name in the packet.
222 If the optional C<@section> argument is given, and is a list of C<answer>,
223 C<authority> and C<additional>, only RRs from those sections are returned.
224  
225 =item has_rrs_of_type_for_name($type, $name[, @section])
226  
227 Returns true if the packet holds any RRs of the specified type for the given name.
228 If the optional C<@section> argument is given, and is a list of C<answer>,
229 C<authority> and C<additional>, only RRs from those sections are returned.
230  
231 =item answerfrom
232  
233 Wrapper for the underlying packet method, that replaces undefined values with the string C<E<lt>unknownE<gt>>.
234  
235 =item TO_JSON
236  
237 Support method for L<JSON> to be able to serialize these objects.
238  
239 =back
240  
241 =head1 METHODS PASSED THROUGH
242  
243 These methods are passed through transparently to the underlying L<Zonemaster::LDNS::Packet> object.
244  
245 =over
246  
247 =item data
248  
249 =item rcode
250  
251 =item aa
252  
253 =item ra
254  
255 =item tc
256  
257 =item question
258  
259 =item answer
260  
261 =item authority
262  
263 =item additional
264  
265 =item string
266  
267 =item unique_push
268  
269 =item timestamp
270  
271 =item type
272  
273 =item edns_size
274  
275 =item edns_rcode
276  
277 =item edns_version
278  
279 =item edns_z
280  
281 =item edns_data
282  
283 =item has_edns
284  
285 =item id
286  
287 =item querytime
288  
289 =item do
290  
291 =item opcode
292  
293 =back
« Zonemaster/Engine/Normalization/Error.pm ↑ Summary Zonemaster/Engine/Constants.pm »