diff options
author | Matthew Somerville <matthew@mysociety.org> | 2016-08-10 12:42:24 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2016-08-10 12:42:24 +0100 |
commit | 6f6fc8b2d15b253bd455661a38d41ece11a547c0 (patch) | |
tree | 77bddd693a6de069e67c9a8eabad7b78931067ae /perllib/FixMyStreet/Geocode.pm | |
parent | e5d85c495f28be97b8f94487dee26646dcd13ebb (diff) |
Make UPLOAD_DIR/GEO_CACHE relative to project root
If they are absolute already, do nothing.
Switch a couple of uses to Path::Tiny as well.
Diffstat (limited to 'perllib/FixMyStreet/Geocode.pm')
-rw-r--r-- | perllib/FixMyStreet/Geocode.pm | 14 |
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; |