From 476b70b9f883bd89d7f6470470d1f08a9402c468 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 30 Apr 2016 09:34:48 +0200 Subject: get_station: Prevent endless while loop --- lib/Travel/Status/DE/IRIS.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm index 4e3cad4..6cdf092 100644 --- a/lib/Travel/Status/DE/IRIS.pm +++ b/lib/Travel/Status/DE/IRIS.pm @@ -159,13 +159,15 @@ sub get_with_cache { sub get_station { my ( $self, %opt ) = @_; + my $iter_depth = 0; my @ret; my @queue = ( $opt{name} ); my @seen; - while (@queue) { + while ( @queue and $iter_depth < 12 ) { my $station = shift(@queue); push( @seen, $station ); + $iter_depth++; my ( $raw, $err ) = $self->get_with_cache( $self->{main_cache}, @@ -212,6 +214,11 @@ sub get_station { } } + if (@queue) { + cluck( "Reached $iter_depth iterations when tracking station IDs. " + . "This is probably a bug" ); + } + @ret = uniq_by { $_->{uic} } @ret; return @ret; -- cgit v1.2.3