From 53fcd15fe7667628f4d5c4f2c1b2dc49f174d67c Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 28 Sep 2015 18:06:25 +0200 Subject: EFA: Handle ambiguous input properly (explicit accessors for candidate lists) --- lib/Travel/Status/DE/EFA.pm | 47 +++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) (limited to 'lib/Travel') diff --git a/lib/Travel/Status/DE/EFA.pm b/lib/Travel/Status/DE/EFA.pm index 5b1e36a..c9123df 100644 --- a/lib/Travel/Status/DE/EFA.pm +++ b/lib/Travel/Status/DE/EFA.pm @@ -167,6 +167,24 @@ sub errstr { return $self->{errstr}; } +sub name_candidates { + my ($self) = @_; + + if ( $self->{name_candidates} ) { + return @{ $self->{name_candidates} }; + } + return; +} + +sub place_candidates { + my ($self) = @_; + + if ( $self->{place_candidates} ) { + return @{ $self->{place_candidates} }; + } + return; +} + sub sprintf_date { my ($e) = @_; @@ -222,21 +240,16 @@ sub check_for_ambiguous { my $s_name = $e_name->getAttribute('state'); if ( $s_place eq 'list' ) { - $self->{errstr} = sprintf( - 'Ambiguous place input: %s', - join( q{ | }, - map { decode( 'UTF-8', $_->textContent ) } - @{ $e_place->findnodes($xp_place_elem) } ) - ); + $self->{place_candidates} = [ map { decode( 'UTF-8', $_->textContent ) } + @{ $e_place->findnodes($xp_place_elem) } ]; + $self->{errstr} = 'ambiguous place parameter'; return; } if ( $s_name eq 'list' ) { - $self->{errstr} = sprintf( - 'Ambiguous name input: %s', - join( q{ | }, - map { decode( 'UTF-8', $_->textContent ) } - @{ $e_name->findnodes($xp_name_elem) } ) - ); + $self->{name_candidates} = [ map { decode( 'UTF-8', $_->textContent ) } + @{ $e_name->findnodes($xp_name_elem) } ]; + + $self->{errstr} = 'ambiguous name parameter'; return; } if ( $s_place eq 'notidentified' ) { @@ -704,6 +717,16 @@ will return ("Essen", "Martinstr."). Returns a list of Travel::Status::DE::EFA::Line(3pm) objects, each one describing one line servicing the selected station. +=item $status->name_candidates + +Returns a list of B candidates if I is ambiguous. Returns +nothing (undef / empty list) otherwise. + +=item $status->place_candidates + +Returns a list of B candidates if I is ambiguous. Returns +nothing (undef / empty list) otherwise. + =item $status->results Returns a list of Travel::Status::DE::EFA::Result(3pm) objects, each one describing -- cgit v1.2.3