line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package xDT::Parser; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
15468
|
use v5.10; |
|
1
|
|
|
|
|
2
|
|
4
|
1
|
|
|
1
|
|
317
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use namespace::autoclean; |
6
|
|
|
|
|
|
|
use FileHandle; |
7
|
|
|
|
|
|
|
use Carp; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use xDT::Record; |
10
|
|
|
|
|
|
|
use xDT::Object; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
xDT::Parser - A Parser for xDT files. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 VERSION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Version 1.00 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Can be used to open xdt files and to iterate over contained objects. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use xDT::Parser; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $parser = xDT::Parser->new(); |
32
|
|
|
|
|
|
|
$parser->open($xdtFile); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $object = $parser->nextObject(); |
35
|
|
|
|
|
|
|
... |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$parser->close(); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 ATTRUBITES |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 fh |
42
|
|
|
|
|
|
|
FileHandle to the currently open file. |
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has 'fh' => ( |
46
|
|
|
|
|
|
|
is => 'rw', |
47
|
|
|
|
|
|
|
isa => 'FileHandle', |
48
|
|
|
|
|
|
|
documentation => q{The filehandle the parser will use to read xDT data.}, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 open($xdtFile) |
54
|
|
|
|
|
|
|
Sets the parsers filehandle on this file. |
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub open { |
58
|
|
|
|
|
|
|
my ($self, $file) = @_; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
croak("Error: provided file '$file' does not exist or is not readable.") |
61
|
|
|
|
|
|
|
unless (-f $file); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $fh = FileHandle->new($file, 'r') |
64
|
|
|
|
|
|
|
or croak("Error: could not open filehandle $file."); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$self->fh($fh); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 close |
70
|
|
|
|
|
|
|
Closes the parsers filehandle |
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub close { |
74
|
|
|
|
|
|
|
my $self = shift; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
close $self->fh; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 nextObject |
80
|
|
|
|
|
|
|
Returns the next object of the xDT file. |
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub nextObject { |
84
|
|
|
|
|
|
|
my $self = shift; |
85
|
|
|
|
|
|
|
my $object = xDT::Object->new(); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
while (my $record = $self->_next()) { |
88
|
|
|
|
|
|
|
last if ($record->isObjectEnd); |
89
|
|
|
|
|
|
|
$object->addRecord($record); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
return $object; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _next { |
96
|
|
|
|
|
|
|
my $self = shift; |
97
|
|
|
|
|
|
|
my $line; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
do { |
100
|
|
|
|
|
|
|
$line = $self->fh->getline() or return undef; |
101
|
|
|
|
|
|
|
} while ($line =~ /^\s*$/); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return xDT::Record->new($line); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 AUTHOR |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Christoph Beger, C<< >> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 BUGS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
113
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
114
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 SUPPORT |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
perldoc xDT::Parser |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
You can also look for information at: |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=over 4 |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
L |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * CPAN Ratings |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
L |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * Search CPAN |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
L |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=back |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Copyright 2017 Christoph Beger. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
This program is released under the following license: MIT |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
1; # End of xDT::Parser |