<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package t::Mock::GoogleGeocoder;

use JSON::MaybeXS;
use Web::Simple;
use LWP::Protocol::PSGI;

has json =&gt; (
    is =&gt; 'lazy',
    default =&gt; sub {
        JSON-&gt;new-&gt;utf8-&gt;pretty-&gt;allow_blessed-&gt;convert_blessed;
    },
);

sub dispatch_request {
    my $self = shift;

    sub (GET + /maps/api/geocode/json + ?*) {
        my ($self, $args) = @_;
        my $response = {};
        if ($args-&gt;{address} =~ /result/) {
            $response-&gt;{status} = 'OK';
            push @{$response-&gt;{results}}, { formatted_address =&gt; 'High Street, Old Town, City of Edinburgh, Scotland', geometry =&gt; { location =&gt; { lng =&gt; -3.1858425, lat =&gt; 55.9504009 } } };
        }
        if ($args-&gt;{address} eq 'two results') {
            push @{$response-&gt;{results}}, { geometry =&gt; { location =&gt; { lat =&gt; "55.8596449", "lng" =&gt; "-4.240377" } }, formatted_address =&gt; "High Street, Collegelands, Merchant City, Glasgow, Scotland" };
        }
        my $json = mySociety::Locale::in_gb_locale {
            $self-&gt;json-&gt;encode($response);
        };
        return [ 200, [ 'Content-Type' =&gt; 'application/json' ], [ $json ] ];
    },
}

LWP::Protocol::PSGI-&gt;register(t::Mock::GoogleGeocoder-&gt;to_psgi_app, host =&gt; 'maps.googleapis.com');

__PACKAGE__-&gt;run_if_script;
</pre></body></html>