From bc207d520565dc9b140d44a0ac363d973d605f5f Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 28 Feb 2016 20:01:05 +0100 Subject: Partially fix excessive requests for stations with long "meta" tags --- lib/Travel/Status/DE/IRIS.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib/Travel') diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm index 937bb65..36237c9 100644 --- a/lib/Travel/Status/DE/IRIS.pm +++ b/lib/Travel/Status/DE/IRIS.pm @@ -12,6 +12,8 @@ use Carp qw(confess cluck); use DateTime; use Encode qw(encode decode); use List::Util qw(first); +use List::MoreUtils qw(uniq); +use List::UtilsBy qw(uniq_by); use LWP::UserAgent; use Travel::Status::DE::IRIS::Result; use XML::LibXML; @@ -197,11 +199,14 @@ sub get_station { printf( " -> %s (%s / %s)\n", @{ $ret[0] }{qw{name uic ds100}} ); } + # TODO this approach is flawed, iterative is probably better + if ( $opt{recursive} and $station_node->hasAttribute('meta') ) { my @recursion_blacklist = @{ $opt{recursion_blacklist} // [] }; - my @refs = split( m{ \| }x, $station_node->getAttribute('meta') ); + my @refs = uniq(split( m{ \| }x, $station_node->getAttribute('meta') )); + + push( @recursion_blacklist, map { $_->{uic} } @ret ); - push( @recursion_blacklist, $ret[0]{uic} ); for my $ref (@refs) { if ( not( $ref ~~ \@recursion_blacklist ) ) { push( @@ -217,6 +222,8 @@ sub get_station { } } + @ret = uniq_by { $_->{uic} } @ret; + return @ret; } -- cgit v1.2.3