summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Travel/Status/DE/IRIS.pm34
1 files changed, 28 insertions, 6 deletions
diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm
index efb080d..e6dcda3 100644
--- a/lib/Travel/Status/DE/IRIS.pm
+++ b/lib/Travel/Status/DE/IRIS.pm
@@ -18,6 +18,19 @@ use LWP::UserAgent;
use Travel::Status::DE::IRIS::Result;
use XML::LibXML;
+sub try_load_xml {
+ my ($xml) = @_;
+
+ my $tree;
+
+ eval { $tree = XML::LibXML->load_xml( string => $xml ) };
+
+ if ($@) {
+ return ( undef, $@ );
+ }
+ return ( $tree, undef );
+}
+
sub new {
my ( $class, %opt ) = @_;
@@ -215,10 +228,9 @@ sub get_station {
}
}
- my $xml_st;
- eval { $xml_st = XML::LibXML->load_xml( string => $raw ) };
- if ($@) {
- $self->{errstr} = "Parse error: $@";
+ my ( $xml_st, $xml_err ) = try_load_xml($raw);
+ if ($xml_err) {
+ $self->{errstr} = 'Failed to parse station data: Invalid XML';
return;
}
@@ -353,7 +365,12 @@ sub get_timetable {
return $self;
}
- my $xml = XML::LibXML->load_xml( string => $raw );
+ my ( $xml, $xml_err ) = try_load_xml($raw);
+
+ if ($xml_err) {
+ $self->{warnstr} = 'Failed to parse a schedule part: Invalid XML';
+ return $self;
+ }
my $station = ( $xml->findnodes('/timetable') )[0]->getAttribute('station');
@@ -379,7 +396,12 @@ sub get_realtime {
return $self;
}
- my $xml = XML::LibXML->load_xml( string => $raw );
+ my ( $xml, $xml_err ) = try_load_xml($raw);
+
+ if ($xml_err) {
+ $self->{warnstr} = 'Failed to parse realtime data: Invalid XML';
+ return $self;
+ }
my $station = ( $xml->findnodes('/timetable') )[0]->getAttribute('station');