-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from Pear-Trading/Release-v0.9.5
Update for 0.9.5
- Loading branch information
Showing
14 changed files
with
405 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package Pear::LocalLoop::Plugin::Postcodes; | ||
use Mojo::Base 'Mojolicious::Plugin'; | ||
|
||
use Geo::UK::Postcode::Regex; | ||
use GIS::Distance; | ||
|
||
sub register { | ||
my ( $plugin, $app, $conf ) = @_; | ||
|
||
$app->helper( get_location_from_postcode => sub { | ||
my ( $c, $postcode, $usertype ) = @_; | ||
my $postcode_obj = Geo::UK::Postcode::Regex->parse( $postcode ); | ||
|
||
my $location; | ||
|
||
unless ( defined $postcode_obj && $postcode_obj->{non_geographical} ) { | ||
my $pc_result = $c->schema->resultset('GbPostcode')->find({ | ||
incode => $postcode_obj->{incode}, | ||
outcode => $postcode_obj->{outcode}, | ||
}); | ||
if ( defined $pc_result ) { | ||
# Force truncation here as SQLite is stupid | ||
$location = { | ||
latitude => ( | ||
$usertype eq 'customer' | ||
? int($pc_result->latitude * 100 ) / 100 | ||
: $pc_result->latitude | ||
), | ||
longitude => ( | ||
$usertype eq 'customer' | ||
? int($pc_result->longitude * 100 ) / 100 | ||
: $pc_result->longitude | ||
), | ||
}; | ||
} | ||
} | ||
return $location; | ||
}); | ||
|
||
$app->helper( get_distance_from_coords => sub { | ||
my ( $c, $buyer, $seller ) = @_; | ||
|
||
my $gis = GIS::Distance->new(); | ||
|
||
my $buyer_lat = $buyer->latitude; | ||
my $buyer_long = $buyer->longitude; | ||
my $seller_lat = $seller->latitude; | ||
my $seller_long = $seller->longitude; | ||
|
||
if ( $buyer_lat && $buyer_long | ||
&& $seller_lat && $seller_long ) { | ||
return int( $gis->distance( $buyer_lat, $buyer_long => $seller_lat, $seller_long )->meters ); | ||
} | ||
return; | ||
}); | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.