From 12888c2cfe2494f51df8d661e692c292e6f26b61 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 17 Sep 2015 17:51:45 +0200 Subject: StopFinder: Re-use HAFAS.pm User Agent if possible --- lib/Travel/Status/DE/HAFAS.pm | 6 ++++-- lib/Travel/Status/DE/HAFAS/StopFinder.pm | 11 ++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index 26c68d6..b1ebad1 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -118,6 +118,7 @@ sub new { exclusive_mots => $conf{exclusive_mots}, excluded_mots => $conf{excluded_mots}, station => $conf{station}, + ua => $ua, post => { input => $conf{station}, date => $date, @@ -253,6 +254,7 @@ sub similar_stops { my $sf = Travel::Status::DE::HAFAS::StopFinder->new( url => $hafas_instance{$service}{stopfinder}, input => $self->{station}, + ua => $self->{ua}, ); if ( my $err = $sf->errstr ) { $self->{errstr} = $err; @@ -345,7 +347,7 @@ sub get_services { sub get_service { my ($service) = @_; - if ( defined $service and exists $hafas_instance{$service}) { + if ( defined $service and exists $hafas_instance{$service} ) { return %{ $hafas_instance{$service} }; } return; @@ -354,7 +356,7 @@ sub get_service { sub get_active_service { my ($self) = @_; - if (defined $self->{active_service}) { + if ( defined $self->{active_service} ) { return %{ $hafas_instance{ $self->{active_service} } }; } return; diff --git a/lib/Travel/Status/DE/HAFAS/StopFinder.pm b/lib/Travel/Status/DE/HAFAS/StopFinder.pm index c81c33a..3327af2 100644 --- a/lib/Travel/Status/DE/HAFAS/StopFinder.pm +++ b/lib/Travel/Status/DE/HAFAS/StopFinder.pm @@ -17,12 +17,13 @@ sub new { my ( $obj, %conf ) = @_; my $lang = $conf{language} // 'd'; + my $ua = $conf{ua}; - my %lwp_options = %{ $conf{lwp_options} // { timeout => 10 } }; - - my $ua = LWP::UserAgent->new(%lwp_options); - - $ua->env_proxy; + if ( not $ua ) { + my %lwp_options = %{ $conf{lwp_options} // { timeout => 10 } }; + $ua = LWP::UserAgent->new(%lwp_options); + $ua->env_proxy; + } my $reply; -- cgit v1.2.3