summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-09-17 17:51:45 +0200
committerDaniel Friesel <derf@finalrewind.org>2015-09-17 17:51:45 +0200
commit12888c2cfe2494f51df8d661e692c292e6f26b61 (patch)
tree2da2509125af2efb5110afd771e74945783e1e02
parent01da3afd1e14ddeeb9cb2244e42f98bd60c10972 (diff)
StopFinder: Re-use HAFAS.pm User Agent if possible
-rw-r--r--lib/Travel/Status/DE/HAFAS.pm6
-rw-r--r--lib/Travel/Status/DE/HAFAS/StopFinder.pm11
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;