| 1 | package Geo::Coordinates::Converter::Format::Geohash; | ||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use parent 'Geo::Coordinates::Converter::Format'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | our $VERSION = '0.05'; | |||||||||
| 6 | |||||||||||
| 7 | 3 | ▶ | use Geo::Coordinates::Converter::Point::Geohash; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use Geohash; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 6 | ▶ | sub name { 'geohash' } | ||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 11 | |||||||||||
| 12 | 4 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 13 | 4 | my($class, %args) = @_; | |||||||||
| 14 | 4 | my $self = $class->SUPER::new(%args); | |||||||||
| 15 | 4 | $self->{geohash} = Geohash->new; | |||||||||
| 16 | 4 | $self; | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 3 | ▶ | sub detect { | ||||||||
|
Subroutine
detect: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 20 | 3 | my($self, $point) = @_; | |||||||||
| 21 | 3 | ▶ | return unless $point->isa('Geo::Coordinates::Converter::Point::Geohash'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 2 | ▶ | return unless $point->geohash =~ /\A[0-9bcdefghjkmnpqrstuvwxyz]+\z/i; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 2 | return $self->name; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | # geohash to lat/lng | ||||||||||
| 27 | 2 | ▶ | sub to { | ||||||||
|
Subroutine
to: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 28 | 2 | my($self, $point) = @_; | |||||||||
| 29 | |||||||||||
| 30 | 2 | my($lat, $lng) = $self->{geohash}->decode($point->{geohash}); | |||||||||
| 31 | 2 | $point->lat($lat); | |||||||||
| 32 | 2 | $point->lng($lng); | |||||||||
| 33 | 2 | $point->geohash(undef); | |||||||||
| 34 | |||||||||||
| 35 | 2 | $point; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | # lat/lng to geohash | ||||||||||
| 39 | 2 | ▶ | sub from { | ||||||||
|
Subroutine
from: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 40 | 2 | my($self, $point) = @_; | |||||||||
| 41 | |||||||||||
| 42 | # re-bless to geohash point package | ||||||||||
| 43 | # because i want ->geohash method | ||||||||||
| 44 | 2 | ▶ | bless $point, 'Geo::Coordinates::Converter::Point::Geohash' unless $point->isa(__PACKAGE__); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | |||||||||||
| 46 | 2 | my $geohash = $self->{geohash}->encode($point->lat, $point->lng); | |||||||||
| 47 | 2 | $point->geohash($geohash); | |||||||||
| 48 | 2 | $point->lat(undef); | |||||||||
| 49 | 2 | $point->lng(undef); | |||||||||
| 50 | |||||||||||
| 51 | 2 | $point; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 3 | 1; | |||||||||
| 55 | __END__ | ||||||||||