aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Geocode.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-08-10 17:08:41 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-08-10 17:08:41 +0100
commit4faf6b08b07bf450d87db10df786f2b7ff8a802c (patch)
treea3c0f7de00a73c5fce730461c3faac477a26327e /perllib/FixMyStreet/Geocode.pm
parent5d2426e0ca4dfee5f85fd5857f0db3276ed6d6c8 (diff)
parent6f6fc8b2d15b253bd455661a38d41ece11a547c0 (diff)
Merge branch '1474-absolutely-fabulous'
Diffstat (limited to 'perllib/FixMyStreet/Geocode.pm')
-rw-r--r--perllib/FixMyStreet/Geocode.pm14
1 files changed, 7 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm
index 257a8d4a3..b5bb7249c 100644
--- a/perllib/FixMyStreet/Geocode.pm
+++ b/perllib/FixMyStreet/Geocode.pm
@@ -9,10 +9,9 @@ package FixMyStreet::Geocode;
use strict;
use Digest::MD5 qw(md5_hex);
use Encode;
-use File::Slurp;
-use File::Path ();
use JSON::MaybeXS;
use LWP::Simple qw($ua);
+use Path::Tiny;
use URI::Escape;
use FixMyStreet::Geocode::Bing;
use FixMyStreet::Geocode::Google;
@@ -69,19 +68,20 @@ sub escape {
sub cache {
my ($type, $url, $args, $re) = @_;
- my $cache_dir = FixMyStreet->config('GEO_CACHE') . $type . '/';
- my $cache_file = $cache_dir . md5_hex($url);
+
+ my $cache_dir = path(FixMyStreet->config('GEO_CACHE'), $type)->absolute(FixMyStreet->path_to());
+ my $cache_file = $cache_dir->child(md5_hex($url));
my $js;
if (-s $cache_file && -M $cache_file <= 7 && !FixMyStreet->config('STAGING_SITE')) {
- $js = File::Slurp::read_file($cache_file);
+ $js = $cache_file->slurp;
} else {
$url .= '&' . $args if $args;
$ua->timeout(15);
$js = LWP::Simple::get($url);
$js = encode_utf8($js) if utf8::is_utf8($js);
- File::Path::mkpath($cache_dir);
+ $cache_dir->mkpath;
if ($js && (!$re || $js !~ $re) && !FixMyStreet->config('STAGING_SITE')) {
- File::Slurp::write_file($cache_file, $js);
+ $cache_file->spew($js);
}
}
$js = JSON->new->utf8->allow_nonref->decode($js) if $js;