summaryrefslogtreecommitdiff
path: root/lib/WebService/TFL/TubeStatus.pm
blob: 3b69997bdf31fd4e9da6cfe6d1332aeac8470ba2 (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 WebService::TFL::TubeStatus; 
use Moo;
use Type::Utils -all;
use Types::URI 'Uri';
use XML::LibXML;
use XML::LibXML::XPathContext;
use WebService::TFL::TubeStatus::Response;
use namespace::autoclean;
 
has user_agent => (
    isa => duck_type(['get']),
    is => 'lazy',
);
sub _build_user_agent {
    require LWP::UserAgent;
    my $ua = LWP::UserAgent->new();
    $ua->env_proxy;
    return $ua;
}
 
has uri => (
    isa => Uri,
    is => 'ro',
    coerce => Uri->coercion,
    default => 'http://cloud.tfl.gov.uk/TrackerNet/LineStatus',
);
 
sub request {
    my ($self) = @_;
 
    my $doc = XML::LibXML->load_xml(location => $self->uri)
        or die "Couldn't fetch tube status";
    my $xpath=XML::LibXML::XPathContext->new($doc);
    $xpath->registerNs('ws','http://webservices.lul.co.uk/');
 
    return WebService::TFL::TubeStatus::Response->new_from_xml($doc,$xpath);
}
 
1;