blib/lib/DNS/Record/Check.pm

filter: Statementstmt 8.6% 8 / 93 Branchbran 0.0% 0 / 62 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 16.6% 2 / 12 Podpod 100% 10 / 10 totaltotal 11.3% 20 / 177 CC 32 SCAR 39.7
CC
32
Cov
5%
A
132.0
MX
42.0
RP
42.0
CRAP 53.2
↑ Summary
1 package DNS::Record::Check;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 DNS::Record::Check - Provides checks for some common DNS records.
9  
10 =head1 VERSION
11  
12 Version 0.0.0
13  
14 =cut
15  
16 2 our $VERSION = '0.0.0';
17  
18  
19 =head1 SYNOPSIS
20  
21 use DNS::Record::Check;
22
23 my $dnsrc=DNS::Record::Check->new;
24
25 if($dnsrc->A($recordValue)){
26 warn($recordValue.' is not a valid a record');
27 }
28  
29 =head1 SUBROUTINES/METHODS
30  
31 =head2 new
32  
33 This initiates the object.
34  
35 $dnsrc=DNS::Record::Check->new;
36  
37 =cut
38  
39 0 ▶sub new{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
40 0 my $self={};
41 0 bless $self;
42  
43 0 return $self;
44 }
45  
46 =head2 A
47  
48 Checks if a A record value is valid.
49  
50 my $return=$dnsrc->A($value);
51  
52 =head3 Return Values
53  
54 =head4 0
55  
56 Valid.
57  
58 =head4 1
59  
60 Not defined.
61  
62 =head4 2
63  
64 Contains non-numeric or period characters.
65  
66 =head4 3
67  
68 It has less than four numbers.
69  
70 =head4 4
71  
72 It has more than four numbers.
73  
74 =head4 5
75  
76 The number is 0.
77  
78 =head4 6
79  
80 One of the numbers is greater than 255.
81  
82 =head4 7
83  
84 The fourth number is zero.
85  
86 =cut
87  
88 0 ▶sub A{
Subroutine A: not called CC=11 SCAR=48.8
Pod documented
89 0 my $record=$_[1];
90  
91 #makes sure the record is defined
92 0 ▶ if (!defined($record)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $record) 0 0 0
93 0 return 1;
94 }
95  
96 #make sure it does no
97 0 ▶ if (!($record =~ /^[0123456789\.]*$/)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($record =~ /^[0123456789\.]*$/) 0 0 0
98 0 return 2;
99 }
100
101 #checks each byte
102 0 my @recordSplit=split(/\./, $record);
103 0 my $int=0;
104 0 ▶ while (defined($recordSplit[$int])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $recordSplit[$int]) 0 0 0
105  
106 #if we are at 4, it means there are 5 bytes
107 0 ▶ if ($recordSplit[$int] == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recordSplit[$int] == 4) 0 0 0
108 0 return 4;
109 }
110  
111 #check if the first byte is equal to zero
112 0 ▶ if ($int == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($int == 0) 0 0 0
113 0 ▶ if ($recordSplit[$int] == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recordSplit[$int] == 0) 0 0 0
114 0 return 5;
115 }
116 }
117  
118 #makes sure the byde is not larger than 255
119 0 ▶ if ($recordSplit[$int] > 255) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recordSplit[$int] > 255) 0 0 0
120 0 return 6;
121 }
122  
123 #check if the last number is zero
124 0 ▶ if ($int == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($int == 3) 0 0 0
125 0 ▶ if ($recordSplit[$int] == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recordSplit[$int] == 0) 0 0 0
126 0 return 7;
127 }
128 }
129  
130 0 $int++;
131 }
132  
133 0 ▶ if ($int < 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($int < 4) 0 0 0
134 0 return 3;
135 }
136  
137 0 return 0;
138 }
139  
140 =head2 AAAA
141  
142 Checks if a AAAA record value is valid.
143  
144 my $return=$dnsrc->AAAA($value);
145  
146 =head3 Return Values
147  
148 =head4 0
149  
150 Valid.
151  
152 =head4 1
153  
154 Not defined.
155  
156 =head4 2
157  
158 Found characters that do not match a AAAA record.
159  
160 =head4 3
161  
162 Matched more than two semi-colons in a row.
163  
164 =cut
165  
166 0 ▶sub AAAA{
Subroutine AAAA: not called CC=4 SCAR=30.0
Pod documented
167 0 my $record=$_[1];
168  
169 #makes sure the record is defined
170 0 ▶ if (!defined($record)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $record) 0 0 0
171 0 return 1;
172 }
173  
174 #make sure it does no
175 0 ▶ if (!($record =~ /^[0123456789AaBbCcDdEeFf\:]*$/)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($record =~ /^[0123456789AaBbCcDdEeFf\:]*$/) 0 0 0
176 0 return 2;
177 }
178  
179 #make sure it does not have more than two : in a row
180 0 ▶ if ($record =~ /\:\:\:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record =~ /\:\:\:/) 0 0 0
181 0 return 3;
182 }
183  
184 0 return 0;
185 }
186  
187 =head2 CNAME
188  
189 Checks if a CNAME record value is valid.
190  
191 my $return=$dnsrc->CNAME($value);
192  
193 =head3 Return Values
194  
195 =head4 0
196  
197 Valid.
198  
199 =head4 1
200  
201 Not defined.
202  
203 =head4 2
204  
205 Non-alphanumeric/period characters found.
206  
207 =head4 3
208  
209 The host name begins with a period.
210  
211 =cut
212  
213 0 ▶sub CNAME{
Subroutine CNAME: not called CC=4 SCAR=30.0
Pod documented
214 0 my $record=$_[1];
215  
216 #makes sure the record is defined
217 0 ▶ if (!defined($record)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $record) 0 0 0
218 0 return 1;
219 }
220  
221 #makes sure no Non-alphanumeric/period characters found.
222 0 ▶ if (!($record=~/^[[:alnum:]\.]*$/)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($record =~ /^[[:alnum:]\.]*$/) 0 0 0
223 0 return 2;
224 }
225  
226 #makes sure it does not begin with a period
227 0 ▶ if ($record =~ /^\./) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record =~ /^\./) 0 0 0
228 0 return 3;
229 }
230  
231 0 return 0;
232 }
233  
234 =head2 HINFO
235  
236 Check a HINFO record value.
237  
238 my $return=$dnsrc->HINFO($value);
239  
240 =head3 Return Values
241  
242 =head4 0
243  
244 Valid.
245  
246 =head4 1
247  
248 Undefined.
249  
250 =head4 2
251  
252 Does not start with a leter.
253  
254 =head4 3
255  
256 Contains values outside of capital letters, numbers, forwdward
257 slash, or a hyphen.
258  
259 =head4 4
260  
261 Does not end in either a capital letter or number.
262  
263 =cut
264  
265 0 ▶sub HINFO{
Subroutine HINFO: not called CC=5 SCAR=34.0
Pod documented
266 0 my $record=$_[1];
267  
268 #makes sure the record is defined
269 0 ▶ if (!defined($record)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $record) 0 0 0
270 0 return 1;
271 }
272  
273 #make sure it starts with a capital letter
274 0 ▶ if (!($record =~ /^[A-Z]/)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($record =~ /^[A-Z]/) 0 0 0
275 0 return 2;
276 }
277  
278 #makes sure it only contains the required characters
279 0 ▶ if (!($record =~ /^[A-Z0-1\-\/]$/)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($record =~ m[^[A-Z0-1\-/]$]) 0 0 0
280 0 return 3;
281 }
282  
283 #makes sure it ends in either a number or letter
284 0 ▶ if (!($record =~ /[A-Z0-1]$/)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($record =~ /[A-Z0-1]$/) 0 0 0
285 0 return 4;
286 }
287  
288 0 return 0;
289 }
290  
291 =head2 MX
292  
293 The MX value is not valid.
294  
295 my $return=$dnsrc->MX($value);
296  
297 =head3 Return Values
298  
299 =head4 0
300  
301 Valid.
302  
303 =head4 1
304  
305 Undefined.
306  
307 =head4 2
308  
309 Non-numeric priority.
310  
311 =head4 3
312  
313 No hostname.
314  
315 =head4 4
316  
317 The hostname is not a valid domain name.
318  
319 =head4 5
320  
321 Additional information was found after a third space.
322  
323 =cut
324  
325 0 ▶sub MX{
Subroutine MX: not called CC=6 SCAR=37.4
Pod documented
326 0 my $record=$_[1];
327  
328 #makes sure the record is defined
329 0 ▶ if (!defined($record)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $record) 0 0 0
330 0 return 1;
331 }
332  
333 #splits the record
334 0 my @recordSplit=split(/\ /, $record);
335  
336 #the priority is not numeric
337 0 ▶ if (!($recordSplit[0] =~ /^[[:digit:]]$/)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($recordSplit[0] =~ /^[[:digit:]]$/) 0 0 0
338 0 return 2;
339 }
340  
341 #no host name
342 0 ▶ if (!defined($recordSplit[1])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $recordSplit[1]) 0 0 0
343 0 return 3;
344 }
345  
346 #the CNAME check just checks if it is a valid host name or not
347 0 ▶ if ($_[0]->CNAME($recordSplit[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]->CNAME($recordSplit[1])) 0 0 0
348 0 return 4;
349 }
350  
351 #has extra info
352 0 ▶ if (defined($recordSplit[2])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $recordSplit[2]) 0 0 0
353 0 return 5;
354 }
355  
356 0 return 0;
357 }
358  
359 =head2 NS
360  
361 Checks if a NS record value is valid.
362  
363 my $return=$dnsrc->NS($value);
364  
365 =head3 Return Values
366  
367 See the return value listing for CNAME.
368  
369 =cut
370  
371 0 ▶sub NS{
Subroutine NS: not called CC=1 SCAR=6.9
Pod documented
372 0 my $record=$_[1];
373  
374 0 return $_[0]->CNAME($record);
375 }
376  
377 =head2 PTR
378  
379 Checks if a PTR record value is valid.
380  
381 my $return=$dnsrc->PTR($value);
382  
383 =head3 Return Values
384  
385 See the return value listing for CNAME.
386  
387 =cut
388  
389 0 ▶sub PTR{
Subroutine PTR: not called CC=1 SCAR=6.9
Pod documented
390 0 my $record=$_[1];
391  
392 0 return $_[0]->CNAME($record);
393 }
394  
395 =head2 RP
396  
397 Checks if a RP record value is valid.
398  
399 my $return=$dnsrc->RP($value);
400  
401 =head3 Return Values
402  
403 =head4 0
404  
405 Valid.
406  
407 =head4 1
408  
409 Undefined.
410  
411 =head4 2
412  
413 Invalid email address.
414  
415 =head4 3
416  
417 Invalid hostname in email address.
418  
419 =cut
420  
421 0 ▶sub RP{
Subroutine RP: not called CC=6 SCAR=37.4
Pod documented
422 0 my $record=$_[1];
423  
424 0 ▶ if (!defined($record)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $record) 0 0 0
425 0 return 1;
426 }
427  
428 0 my @recordSplit=split(/\@/, $record);
429  
430 0 ▶ if (defined($recordSplit[2])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $recordSplit[2]) 0 0 0
431 0 return 2;
432 }
433  
434 0 ▶ if (!defined($recordSplit[1])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $recordSplit[1]) 0 0 0
435 0 return 2;
436 }
437  
438 0 ▶ if ($recordSplit[0] =~ /[\!\#\$\%\^\&\*\(\)\;\:\<\>\[\]]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recordSplit[0] =~ /[\!\#\$\%\^\&\*\(\)\;\:\<\>\[\]]/) 0 0 0
439 0 return 2;
440 }
441  
442 0 ▶ if (!$_[0]->CNAME($recordSplit[1])) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[0]->CNAME($recordSplit[1])) 0 0 0
443 0 return 3;
444 }
445  
446 0 return 0;
447 }
448  
449  
450 =head2 TXT
451  
452 Checks if a TXT record value is valid.
453  
454 my $return=$dnsrc->TXT($value);
455  
456 =head3 Return Values
457  
458 =head4 0
459  
460 Valid.
461  
462 =head4 1
463  
464 Undefined.
465  
466 =cut
467  
468 0 ▶sub TXT{
Subroutine TXT: not called CC=2 SCAR=17.9
Pod documented
469 0 my $record=$_[1];
470  
471 0 ▶ if (!defined($record)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $record) 0 0 0
472 0 return 1;
473 }
474  
475 0 return 0;
476 }
477  
478 =head1 AUTHOR
479  
480 Zane C. Bowers, C<< <vvelox at vvelox.net> >>
481  
482 =head1 BUGS
483  
484 Please report any bugs or feature requests to C<bug-dns-record-check at rt.cpan.org>, or through
485 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DNS-Record-Check>. I will be notified, and then you'll
486 automatically be notified of progress on your bug as I make changes.
487  
488  
489  
490  
491 =head1 SUPPORT
492  
493 You can find documentation for this module with the perldoc command.
494  
495 perldoc DNS::Record::Check
496  
497  
498 You can also look for information at:
499  
500 =over 4
501  
502 =item * RT: CPAN's request tracker
503  
504 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=DNS-Record-Check>
505  
506 =item * AnnoCPAN: Annotated CPAN documentation
507  
508 L<http://annocpan.org/dist/DNS-Record-Check>
509  
510 =item * CPAN Ratings
511  
512 L<http://cpanratings.perl.org/d/DNS-Record-Check>
513  
514 =item * Search CPAN
515  
516 L<http://search.cpan.org/dist/DNS-Record-Check/>
517  
518 =item * SVN Repo
519  
520 L<http://eesdp.org/svnweb/index.cgi/pubsvn/browse/Perl/DNS%3A%3ARecord%3A%3ACheck>
521  
522 =back
523  
524  
525 =head1 ACKNOWLEDGEMENTS
526  
527  
528 =head1 LICENSE AND COPYRIGHT
529  
530 Copyright 2010 Zane C. Bowers.
531  
532 This program is free software; you can redistribute it and/or modify it
533 under the terms of either: the GNU General Public License as published
534 by the Free Software Foundation; or the Artistic License.
535  
536 See http://dev.perl.org/licenses/ for more information.
537  
538  
539 =cut
540  
541 2 1; # End of DNS::Record::Check
↑ Summary