line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
43552
|
use 5.010; |
|
1
|
|
|
|
|
2
|
|
2
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Geo::Openstreetmap::Parser; |
6
|
|
|
|
|
|
|
$Geo::Openstreetmap::Parser::VERSION = '0.03'; |
7
|
|
|
|
|
|
|
# ABSTRACT: Openstreetmap XML dump parser |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
3
|
use autodie; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
3234
|
use XML::Parser; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new |
16
|
|
|
|
|
|
|
{ |
17
|
|
|
|
|
|
|
my ($class, %callback) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $self = bless { callback => \%callback }, $class; |
20
|
|
|
|
|
|
|
$self->_init_parser(); |
21
|
|
|
|
|
|
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub parse |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
my ($self, $fh) = @_; |
29
|
|
|
|
|
|
|
$self->{parser}->parse($fh); |
30
|
|
|
|
|
|
|
return; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _init_parser |
37
|
|
|
|
|
|
|
{ |
38
|
|
|
|
|
|
|
my ($self) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my @path; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$self->{parser} = XML::Parser->new( Handlers => { |
43
|
|
|
|
|
|
|
Start => sub { |
44
|
|
|
|
|
|
|
my ($expat, $el, %attr) = @_; |
45
|
|
|
|
|
|
|
push @path, { attr => \%attr }; |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
End => sub { |
48
|
|
|
|
|
|
|
my ($expat, $el) = @_; |
49
|
|
|
|
|
|
|
my $obj = pop @path; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
if ($el eq 'tag') { $path[-1]->{$el}->{$obj->{attr}->{k}} = $obj->{attr}->{v} } |
52
|
|
|
|
|
|
|
if ($el eq 'nd') { push @{$path[-1]->{$el}}, $obj->{attr}->{ref} } |
53
|
|
|
|
|
|
|
if ($el eq 'member') { push @{$path[-1]->{$el}}, $obj->{attr} } |
54
|
|
|
|
|
|
|
if (my $cb = $self->{callback}->{$el}) { $cb->($obj) } |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
}); |
57
|
|
|
|
|
|
|
return; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |