line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
TinyDNS::Reader - Read TinyDNS files. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 DESCRIPTION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
This module allows the parsing of a TinyDNS data-file, or individual records |
9
|
|
|
|
|
|
|
taken from one. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 AUTHOR |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Steve Kemp <steve@steve.org.uk> |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Copyright (C) 2014 Steve Kemp <steve@steve.org.uk>. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This code was developed for an online Git-based DNS hosting solution, |
24
|
|
|
|
|
|
|
which can be found at: |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=over 8 |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=item * |
29
|
|
|
|
|
|
|
https://dns-api.com/ |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=back |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This library is free software. You can modify and or distribute it under |
34
|
|
|
|
|
|
|
the same terms as Perl itself. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
3
|
|
40279
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
117
|
|
40
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
109
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
package TinyDNS::Reader; |
43
|
|
|
|
|
|
|
|
44
|
3
|
|
|
3
|
|
1100
|
use TinyDNS::Record; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
1215
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
our $VERSION = '0.7'; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=begin doc |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Constructor. We should be given either a "file" or "text" parameter. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=end doc |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub new |
58
|
|
|
|
|
|
|
{ |
59
|
9
|
|
|
9
|
0
|
16957
|
my ( $proto, %supplied ) = (@_); |
60
|
9
|
|
33
|
|
|
53
|
my $class = ref($proto) || $proto; |
61
|
|
|
|
|
|
|
|
62
|
9
|
|
|
|
|
13
|
my $self = {}; |
63
|
9
|
|
|
|
|
27
|
bless( $self, $class ); |
64
|
|
|
|
|
|
|
|
65
|
9
|
50
|
|
|
|
40
|
if ( $supplied{ 'file' } ) |
|
|
50
|
|
|
|
|
|
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
|
|
0
|
$self->{ 'data' } = $self->_readFile( $supplied{ 'file' } ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
elsif ( $supplied{ 'text' } ) |
70
|
|
|
|
|
|
|
{ |
71
|
9
|
|
|
|
|
33
|
$self->{ 'data' } = $supplied{ 'text' }; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else |
74
|
|
|
|
|
|
|
{ |
75
|
0
|
|
|
|
|
0
|
die "Missing 'text' or 'file' argument."; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
9
|
|
|
|
|
32
|
return $self; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=begin doc |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Read the contents of the specified file. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Invoked by the constructor if it was passed a C<file> argument. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=end doc |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _readFile |
94
|
|
|
|
|
|
|
{ |
95
|
0
|
|
|
0
|
|
0
|
my ( $self, $file ) = (@_); |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
0
|
open( my $handle, "<", $file ) or |
98
|
|
|
|
|
|
|
die "Failed to read $file - $!"; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
0
|
my $text = ""; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
while ( my $line = <$handle> ) |
103
|
|
|
|
|
|
|
{ |
104
|
0
|
|
|
|
|
0
|
$text .= $line; |
105
|
|
|
|
|
|
|
} |
106
|
0
|
|
|
|
|
0
|
close($handle); |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
0
|
return ($text); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=begin doc |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Process and return an array of L<TinyDNS::Records> from the data. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=end doc |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub parse |
121
|
|
|
|
|
|
|
{ |
122
|
9
|
|
|
9
|
0
|
2355
|
my ($self) = (@_); |
123
|
|
|
|
|
|
|
|
124
|
9
|
|
|
|
|
14
|
my $records; |
125
|
|
|
|
|
|
|
|
126
|
9
|
|
|
|
|
41
|
foreach my $line ( split( /[\n\r]/, $self->{ 'data' } ) ) |
127
|
|
|
|
|
|
|
{ |
128
|
10
|
|
|
|
|
22
|
chomp($line); |
129
|
10
|
50
|
33
|
|
|
56
|
next if ( !$line || !length($line) ); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
10
|
50
|
|
|
|
35
|
next if ( $line =~ /^\s*#/ ); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
10
|
50
|
|
|
|
35
|
next if ( $line =~ /^\s*[:.]/ ); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
10
|
|
|
|
|
49
|
my $rec = TinyDNS::Record->new($line); |
145
|
10
|
50
|
|
|
|
42
|
push( @$records, $rec ) if ($rec); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
9
|
|
|
|
|
22
|
return ($records); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |
153
|
|
|
|
|
|
|
|