aboutsummaryrefslogtreecommitdiffstats
path: root/t/Mock/Tilma.pm
blob: 5a11209e3deebf25c04ef7e8a11fced33cec0d4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package t::Mock::Tilma;

use JSON::MaybeXS;
use Web::Simple;

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

sub dispatch_request {
    my $self = shift;

    sub (GET + /mapserver/tfl + ?*) {
        my ($self, $args) = @_;
        my $features = [];
        if ($args->{Filter} =~ /540512,169141/) {
            $features = [
                { type => "Feature", properties => { HA_ID => "19" }, geometry => { type => "Polygon", coordinates => [ [
                    [ 539408.94, 170607.58 ],
                    [ 539432.81, 170627.93 ],
                    [ 539437.24, 170623.48 ],
                    [ 539408.94, 170607.58 ],
                ] ] } } ];
        }
        my $json = mySociety::Locale::in_gb_locale {
            $self->json->encode({
                type => "FeatureCollection",
                crs => { type => "name", properties => { name => "urn:ogc:def:crs:EPSG::27700" } },
                features => $features,
            });
        };
        return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
    },
}

__PACKAGE__->run_if_script;