summaryrefslogtreecommitdiff
path: root/lib/Travel
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-11-16 11:46:19 +0100
committerDaniel Friesel <derf@finalrewind.org>2011-11-16 11:46:19 +0100
commitf1922960a0aa9ad3cede1f7267e31d736895f134 (patch)
tree9169dd590b4622f8bb1820928b76bc58b82b2553 /lib/Travel
parent7a825f4ef1eb36847233959109ae69085b2ef578 (diff)
Detect ambiguous input errors
Diffstat (limited to 'lib/Travel')
-rw-r--r--lib/Travel/Status/DE/DeutscheBahn.pm27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/Travel/Status/DE/DeutscheBahn.pm b/lib/Travel/Status/DE/DeutscheBahn.pm
index bf7ba56..4e9004d 100644
--- a/lib/Travel/Status/DE/DeutscheBahn.pm
+++ b/lib/Travel/Status/DE/DeutscheBahn.pm
@@ -73,6 +73,8 @@ sub new {
suppress_warnings => 1,
);
+ $ref->check_input_error();
+
return $ref;
}
@@ -96,6 +98,31 @@ sub new_from_html {
return bless( $ref, $obj );
}
+sub check_input_error {
+ my ($self) = @_;
+
+ my $xp_errdiv = XML::LibXML::XPathExpression->new(
+ '//div[@class = "errormsg leftMargin"]');
+ my $xp_opts
+ = XML::LibXML::XPathExpression->new('//select[@class = "error"]');
+ my $xp_values = XML::LibXML::XPathExpression->new('./option');
+
+ my $e_errdiv = ( $self->{tree}->findnodes($xp_errdiv) )[0];
+ my $e_opts = ( $self->{tree}->findnodes($xp_opts) )[0];
+
+ if ($e_errdiv) {
+ $self->{errstr} = $e_errdiv->textContent;
+
+ if ($e_opts) {
+ my @nodes = ( $e_opts->findnodes($xp_values) );
+ $self->{errstr}
+ .= join( q{}, map { "\n" . $_->textContent } @nodes );
+ }
+ }
+
+ return;
+}
+
sub errstr {
my ($self) = @_;