summaryrefslogtreecommitdiff
path: root/lib/WebService/TFL/Bus/Request.pm
blob: dda65866b76eb3b92235901724be78fb8c7f9a7b (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
package WebService::TFL::Bus::Request; 
use Moo;
use Types::Standard -all;
use WebService::TFL::Bus::Fields;
use namespace::autoclean;
 
for my $field (WebService::TFL::Bus::Fields->query_fields) {
    has $field => (
        is => 'rw',
        predicate => "has_$field",
    );
}
 
has ReturnList => (
    is => 'rw',
    isa => ArrayRef,
    predicate => 'has_ReturnList',
);
 
sub request_uri {
    my ($self,$base_uri) = @_;
 
    my $uri = $base_uri->clone;
    my %form;
    for my $field (WebService::TFL::Bus::Fields->query_fields) {
        my $pred = "has_$field";
        if ($self->$pred) {
            $form{$field} = $self->$field;
        }
    }
    if ($self->has_ReturnList) {
        $form{ReturnList}=join ',',@{$self->ReturnList}
    }
    $uri->query_form(\%form);
    return $uri;
}
 
1;