| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
################################################### |
|
2
|
|
|
|
|
|
|
## YahooRESTGeocode.pm |
|
3
|
|
|
|
|
|
|
## Andrew N. Hicox |
|
4
|
|
|
|
|
|
|
## Hicox Information Systems Development |
|
5
|
|
|
|
|
|
|
## |
|
6
|
|
|
|
|
|
|
## a built in XML::Parser style for parsing |
|
7
|
|
|
|
|
|
|
## the xml returned from Yahoo REST webservices |
|
8
|
|
|
|
|
|
|
################################################### |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
## Global Stuff ################################### |
|
12
|
|
|
|
|
|
|
package XML::Parser::YahooRESTGeocode; |
|
13
|
1
|
|
|
1
|
|
6838
|
use 5.6.0; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
45
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
812
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$VERSION = 0.2; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#register with XML::Parser as built in style |
|
19
|
|
|
|
|
|
|
$XML::Parser::Built_In_Styles{YahooRESTGeocode} = 1; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#host data fields |
|
22
|
|
|
|
|
|
|
my %node_tree = ( |
|
23
|
|
|
|
|
|
|
'Result' => ['Latitude','Longitude','Address','City','State','Zip','Country'] |
|
24
|
|
|
|
|
|
|
); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
## Init ########################################### |
|
30
|
|
|
|
|
|
|
sub Init { |
|
31
|
0
|
|
|
0
|
0
|
|
my $expat = shift; |
|
32
|
0
|
|
|
|
|
|
$expat->{'Lists'} = {}; |
|
33
|
0
|
|
|
|
|
|
$expat->{'Curlist'} = []; #everything @OPEN used to be |
|
34
|
0
|
|
|
|
|
|
$expat->{'errstr'} = (); #clear out the error string |
|
35
|
0
|
|
|
|
|
|
$expat->{'errmsg'} = (); #clear out the advisory errorrs |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#if there's any arguments corresponding to nodes in 'node_tree', |
|
38
|
|
|
|
|
|
|
#evacuate them to '_CDB2IMP_callbacks', they must be code refs |
|
39
|
|
|
|
|
|
|
#we'll execute 'em when one of those nodes ends |
|
40
|
0
|
|
|
|
|
|
foreach (keys %node_tree){ |
|
41
|
0
|
0
|
0
|
|
|
|
if ((exists($expat->{$_})) && (ref ($expat->{$_}) eq "CODE")){ |
|
42
|
0
|
|
|
|
|
|
$expat->{'_YahooREST_callbacks'}->{$_} = $expat->{$_}; |
|
43
|
0
|
|
|
|
|
|
delete($expat->{$_}); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
## Start ########################################## |
|
53
|
|
|
|
|
|
|
sub Start { |
|
54
|
0
|
|
|
0
|
0
|
|
my ($expat, $element, %p) = @_; |
|
55
|
0
|
|
|
|
|
|
push (@{$expat->{'Curlist'}}, { |
|
|
0
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
'_name' => $element, |
|
57
|
|
|
|
|
|
|
'_attributes' => \%p |
|
58
|
|
|
|
|
|
|
}); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
## Char ########################################### |
|
65
|
|
|
|
|
|
|
sub Char { |
|
66
|
0
|
|
|
0
|
0
|
|
my ($expat, $data) = @_; |
|
67
|
0
|
0
|
|
|
|
|
unless ($data =~/^\s+$/){ |
|
68
|
0
|
|
|
|
|
|
$expat->{'Curlist'}->[$#{$expat->{'Curlist'}}]->{'_data'} .= $data; |
|
|
0
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
## Final ########################################## |
|
76
|
|
|
|
|
|
|
sub Final { |
|
77
|
0
|
|
|
0
|
0
|
|
my $expat = shift; |
|
78
|
|
|
|
|
|
|
#handle error |
|
79
|
0
|
0
|
|
|
|
|
if ($expat->{'errstr'}){ $XML::Parser::errstr = $expat->{'errstr'}; return (undef); } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
#handle advisory messages |
|
81
|
0
|
0
|
|
|
|
|
if ($expat->{'errmsg'}){ $XML::Parser::errmsg = $expat->{'errmsg'}; } |
|
|
0
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#clean up |
|
83
|
0
|
|
|
|
|
|
delete $expat->{Curlist}; |
|
84
|
0
|
|
|
|
|
|
my $out = $expat->{Lists}->{'DATA'}; |
|
85
|
0
|
|
|
|
|
|
delete $expat->{Lists}; |
|
86
|
0
|
|
|
|
|
|
return ($out); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
## gather_data #################################### |
|
91
|
|
|
|
|
|
|
sub gather_data { |
|
92
|
0
|
|
|
0
|
0
|
|
my ($expat, $name) = @_; |
|
93
|
0
|
|
|
|
|
|
my (@data) = (); |
|
94
|
0
|
|
|
|
|
|
while ($expat->{'Curlist'}->[$#{$expat->{'Curlist'}}]->{'_name'} ne $name){ |
|
|
0
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
push (@data, pop(@{$expat->{'Curlist'}})); |
|
|
0
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
}; |
|
97
|
|
|
|
|
|
|
#one more to catch the start tag |
|
98
|
0
|
|
|
|
|
|
push (@data, pop(@{$expat->{'Curlist'}})); |
|
|
0
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
reverse (@data); |
|
100
|
0
|
|
|
|
|
|
return (\@data); |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
## extract_pcdata ################################# |
|
105
|
|
|
|
|
|
|
sub extract_pcdata { |
|
106
|
0
|
|
|
0
|
0
|
|
my $data = shift(); |
|
107
|
0
|
|
|
|
|
|
my %out = (); |
|
108
|
0
|
|
|
|
|
|
foreach (@{$data}){ |
|
|
0
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
foreach my $f (@_){ |
|
110
|
0
|
0
|
0
|
|
|
|
if (($_->{'_name'} eq $f) && ($_->{'_data'} !~/^$/)){ |
|
111
|
0
|
|
|
|
|
|
$out{$f} = $_->{'_data'}; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
} |
|
115
|
0
|
|
|
|
|
|
return (\%out); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
## End ############################################ |
|
120
|
|
|
|
|
|
|
sub End { |
|
121
|
0
|
|
|
0
|
0
|
|
my ($expat, $element) = @_; |
|
122
|
|
|
|
|
|
|
|
|
123
|
0
|
0
|
|
|
|
|
if (exists($node_tree{$element})){ |
|
124
|
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my $data = extract_pcdata(gather_data($expat, $element), @{$node_tree{$element}}); |
|
|
0
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
push (@{$expat->{'Lists'}->{'DATA'}->{$element}}, $data); |
|
|
0
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
#if the user defined some callback to execute, do that |
|
129
|
0
|
0
|
|
|
|
|
if (exists($expat->{'_YahooREST_callbacks'}->{$element})){ |
|
130
|
0
|
|
|
|
|
|
&{$expat->{'_YahooREST_callbacks'}->{$element}}($data); |
|
|
0
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
## True ########################################### |
|
137
|
|
|
|
|
|
|
1; |