From d146e44ff3a8b3304e6603a2238c40034c4b91a1 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 20 Nov 2011 12:42:44 +0100 Subject: VRR.pm: Check for 'ambiguous input' error condition --- lib/Travel/Status/DE/VRR.pm | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'lib') 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; -- cgit v1.2.3