summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-11-20 12:42:44 +0100
committerDaniel Friesel <derf@finalrewind.org>2011-11-20 12:42:44 +0100
commitd146e44ff3a8b3304e6603a2238c40034c4b91a1 (patch)
tree8e34dd730d76d273e36f782bff218d1e8aec2f42 /lib
parenta32aaf5392f222c120e00eb556897d435993c8e2 (diff)
VRR.pm: Check for 'ambiguous input' error condition
Diffstat (limited to 'lib')
-rw-r--r--lib/Travel/Status/DE/VRR.pm44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/Travel/Status/DE/VRR.pm b/lib/Travel/Status/DE/VRR.pm
index 3fe437f..3efb1e8 100644
--- a/lib/Travel/Status/DE/VRR.pm
+++ b/lib/Travel/Status/DE/VRR.pm
@@ -109,6 +109,8 @@ sub new {
$self->{tree} = XML::LibXML->load_xml( string => $self->{xml}, );
+ $self->check_for_ambiguous();
+
return $self;
}
@@ -147,6 +149,48 @@ sub sprintf_time {
);
}
+sub check_for_ambiguous {
+ my ($self) = @_;
+
+ my $xml = $self->{tree};
+
+ my $xp_place = XML::LibXML::XPathExpression->new('//itdOdv/itdOdvPlace');
+ my $xp_name = XML::LibXML::XPathExpression->new('//itdOdv/itdOdvName');
+
+ my $xp_place_elem = XML::LibXML::XPathExpression->new('./odvPlaceElem');
+ my $xp_name_elem = XML::LibXML::XPathExpression->new('./odvNameElem');
+
+ my $e_place = ( $xml->findnodes($xp_place) )[0];
+ my $e_name = ( $xml->findnodes($xp_name) )[0];
+
+ if ( not( $e_place and $e_name ) ) {
+
+ # this should not happen[tm]
+ cluck('skipping ambiguity check- itdOdvPlace/itdOdvName missing');
+ return;
+ }
+
+ if ( $e_place->getAttribute('state') eq 'list' ) {
+ $self->{errstr} = sprintf(
+ 'Ambiguous place input: %s',
+ join( q{ | },
+ map { $_->textContent }
+ @{ $e_place->findnodes($xp_place_elem) } )
+ );
+ return;
+ }
+ if ( $e_name->getAttribute('state') eq 'list' ) {
+ $self->{errstr} = sprintf(
+ 'Ambiguous name input: %s',
+ join( q{ | },
+ map { $_->textContent } @{ $e_name->findnodes($xp_name_elem) } )
+ );
+ return;
+ }
+
+ return;
+}
+
sub lines {
my ($self) = @_;
my @lines;