summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-04-29 17:39:40 +0200
committerDaniel Friesel <derf@finalrewind.org>2015-04-29 17:39:40 +0200
commit506b66a84c4ec39d69c74f9a42d4f100909ac4a0 (patch)
tree11f36cc625cbbb7975f0dcc1563ccf75c250b019
parent8a904bc1d3601ea72593b90f514354b08b832ccc (diff)
add support for timeouts, do not die if XML tree parsing failed
-rwxr-xr-xbin/efa-m3
-rw-r--r--lib/Travel/Status/DE/EFA.pm16
2 files changed, 16 insertions, 3 deletions
diff --git a/bin/efa-m b/bin/efa-m
index 8c4341c..5b7a1b6 100755
--- a/bin/efa-m
+++ b/bin/efa-m
@@ -16,6 +16,7 @@ use Travel::Status::DE::EFA;
my $efa_url = 'http://efa.vrr.de/vrr/XSLT_DM_REQUEST';
my ( $date, $time, $input_type, $list_lines, $offset, $relative_times );
+my ($timeout);
my ( @grep_lines, @grep_platforms );
@ARGV = map { decode( 'UTF-8', $_ ) } @ARGV;
@@ -29,6 +30,7 @@ GetOptions(
'p|platform=s@' => \@grep_platforms,
'r|relative' => \$relative_times,
't|time=s' => \$time,
+ 'timeout=i' => \$timeout,
'u|efa-url=s' => \$efa_url,
'V|version' => \&show_version,
@@ -55,6 +57,7 @@ my $status = Travel::Status::DE::EFA->new(
name => $input,
time => $time,
type => $input_type,
+ timeout => $timeout // 10,
);
sub show_help {
diff --git a/lib/Travel/Status/DE/EFA.pm b/lib/Travel/Status/DE/EFA.pm
index a895ca6..f8ea9f7 100644
--- a/lib/Travel/Status/DE/EFA.pm
+++ b/lib/Travel/Status/DE/EFA.pm
@@ -114,7 +114,9 @@ sub new {
$self->{xml} = $response->decoded_content;
- $self->{tree} = XML::LibXML->load_xml( string => $self->{xml}, );
+ $self->{tree} = XML::LibXML->load_xml(
+ string => $self->{xml},
+ );
#say $self->{tree}->toString(1);
@@ -126,9 +128,13 @@ sub new {
sub new_from_xml {
my ( $class, %opt ) = @_;
- my $self = { xml => $opt{xml}, };
+ my $self = {
+ xml => $opt{xml},
+ };
- $self->{tree} = XML::LibXML->load_xml( string => $self->{xml}, );
+ $self->{tree} = XML::LibXML->load_xml(
+ string => $self->{xml},
+ );
return bless( $self, $class );
}
@@ -277,6 +283,10 @@ sub results {
my ($self) = @_;
my @results;
+ if ( not $self->{tree} ) {
+ return;
+ }
+
my $xp_element = XML::LibXML::XPathExpression->new('//itdDeparture');
my $xp_date = XML::LibXML::XPathExpression->new('./itdDateTime/itdDate');