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