line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Geohash; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
62763
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
77
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
56
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
2565
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
115440
|
|
|
2
|
|
|
|
|
415
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.1'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub get { |
11
|
8
|
|
|
8
|
1
|
1987
|
my ($coords) = shift @_; |
12
|
8
|
100
|
|
|
|
30
|
if (! $coords) { warn 'Missing lattitude/longitude param'; return ''; } |
|
2
|
|
|
|
|
21
|
|
|
2
|
|
|
|
|
151
|
|
13
|
6
|
100
|
|
|
|
27
|
if (@_) { warn 'Extra parameters found.'; return; } |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
64
|
|
14
|
5
|
|
|
|
|
47
|
my $ua = LWP::UserAgent->new(); |
15
|
5
|
|
|
|
|
8197
|
$ua->agent('perl-Net-Geohash/' . $VERSION ); |
16
|
5
|
|
|
|
|
324
|
$ua->max_redirect(0); |
17
|
5
|
|
|
|
|
93
|
my $resp = $ua->get('http://geohash.org/?q=' . $coords); |
18
|
5
|
50
|
|
|
|
2969994
|
if ($resp->code() eq '303') { |
19
|
5
|
50
|
|
|
|
103
|
if (my $loc = $resp->header('location')) { |
20
|
5
|
100
|
|
|
|
239
|
if ($loc eq 'http://geohash.org/') { |
21
|
2
|
|
|
|
|
311
|
warn 'geohash.org response indicates that the geocode was invalid.'; |
22
|
2
|
|
|
|
|
66
|
return ''; |
23
|
|
|
|
|
|
|
} |
24
|
3
|
|
|
|
|
117
|
return $loc; |
25
|
|
|
|
|
|
|
} else { |
26
|
0
|
|
|
|
|
|
return ''; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
0
|
|
|
|
|
|
warn 'geohash.org response was not a redirect, possibly invalid geocoords.'; |
30
|
0
|
|
|
|
|
|
return ''; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 NAME |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Net::Geohash - The great new Net::Geohash! |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 VERSION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Version 1.1 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SYNOPSIS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Quick summary of what the module does. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Perhaps a little code snippet. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
use Net::Geohash; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $ghurl = Net::Geohash::get('37.391012 -122.071873'); |
50
|
|
|
|
|
|
|
... |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 EXPORT |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 FUNCTIONS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 get |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
The get function accepts a string containing the lat/lon to send to |
59
|
|
|
|
|
|
|
geohash.org for hashing. It returns the fully qualified geohash.org url |
60
|
|
|
|
|
|
|
on success. If an error occurs it will give a warning message and return |
61
|
|
|
|
|
|
|
an empty string. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Location names such as 'Paris, France' can also be given. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 AUTHOR |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Nick Gerakines, C<< >> |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 BUGS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
72
|
|
|
|
|
|
|
C, or through the web interface at |
73
|
|
|
|
|
|
|
L. |
74
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
75
|
|
|
|
|
|
|
your bug as I make changes. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SUPPORT |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
perldoc Net::Geohash |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
You can also look for information at: |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=over 4 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item * geohash.org |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
L |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item * del.icio.us/tag/geohash |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
L |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over 4 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
L |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item * CPAN Ratings |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
L |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
L |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item * Search CPAN |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
L |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=back |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Copyright 2008 Nick Gerakines, all rights reserved. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
120
|
|
|
|
|
|
|
under the same terms as Perl itself. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; # End of Net::Geohash |
125
|
|
|
|
|
|
|
|