blib/lib/Net/Geohash.pm

filter: Statementstmt 80.6% 25 / 31 Branchbran 50.0% 5 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 76.0% 35 / 46 CC 6 SCAR 17.1
CC
6
Cov
73%
get
7.8
BEGIN
1.0
BEGIN
1.0
CRAP 5.5
↑ Summary
1 package Net::Geohash;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '1.1';
9  
10 8 ▶sub get {
Subroutine get: called CC=6 SCAR=20.5
Pod documented
11 8 my ($coords) = shift @_;
12 8 ▶ if (! $coords) { warn 'Missing lattitude/longitude param'; return ''; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($coords) 2 6 8
13 6 ▶ if (@_) { warn 'Extra parameters found.'; return; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 5 6
14 5 my $ua = LWP::UserAgent->new();
15 5 $ua->agent('perl-Net-Geohash/' . $VERSION );
16 5 $ua->max_redirect(0);
17 5 my $resp = $ua->get('http://geohash.org/?q=' . $coords);
18 5 ▶ if ($resp->code() eq '303') {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->code eq 303) 0 5 5
19 0 ▶ if (my $loc = $resp->header('location')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $loc = $resp->header('location')) { } 0 0 0
20 0 ▶ if ($loc eq 'http://geohash.org/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($loc eq "http://geohash.org/") 0 0 0
21 0 warn 'geohash.org response indicates that the geocode was invalid.';
22 0 return '';
23 }
24 0 return $loc;
25 } else {
26 0 return '';
27 }
28 }
29 5 warn 'geohash.org response was not a redirect, possibly invalid geocoords.';
30 5 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<< <nick at gerakines.net> >>
68  
69 =head1 BUGS
70  
71 Please report any bugs or feature requests to
72 C<bug-net-geohash at rt.cpan.org>, or through the web interface at
73 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Geohash>.
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<http://geohash.org/>
90  
91 =item * del.icio.us/tag/geohash
92  
93 L<http://del.icio.us/tag/geohash>
94  
95 =over 4
96  
97 =item * AnnoCPAN: Annotated CPAN documentation
98  
99 L<http://annocpan.org/dist/Net-Geohash>
100  
101 =item * CPAN Ratings
102  
103 L<http://cpanratings.perl.org/d/Net-Geohash>
104  
105 =item * RT: CPAN's request tracker
106  
107 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Geohash>
108  
109 =item * Search CPAN
110  
111 L<http://search.cpan.org/dist/Net-Geohash>
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 2 1; # End of Net::Geohash
125  
↑ Summary