line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1351
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
726
|
|
4
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
109
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Gwybodaeth::Parsers::GeoNamesXML; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Parsers::GeoNamesXML - Parses XML from GeoNames.org into a data structure. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use GeoNamesXML; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $g = GeoNamesXML->new(); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$g->parse(@data); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This module parses XML data from GeoNames.org into an XMLTwig data structure. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=over |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
2
|
|
11
|
use Carp qw{croak}; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
132
|
|
29
|
2
|
|
|
2
|
|
3825
|
use XML::Twig; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Inherit from Gwybodaeth::Parsers::XML class |
32
|
|
|
|
|
|
|
use base 'Gwybodaeth::Parsers::XML'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=item parse(@data) |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Parses an array of lines from @data returning a XMLTwig instance. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub parse { |
41
|
|
|
|
|
|
|
my($self, @data) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
ref($self) or croak "instance variable expected"; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $xml = XML::Twig->new(); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $string; |
48
|
|
|
|
|
|
|
for my $line (@data) { |
49
|
|
|
|
|
|
|
$string .= $line; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
if($xml->safe_parse($string)) { |
53
|
|
|
|
|
|
|
return $xml; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# if we've reached here something has gone wrong, return a fail |
57
|
|
|
|
|
|
|
return 0; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |