diff options
author | Daniel Friesel <derf@finalrewind.org> | 2017-02-05 17:46:46 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2017-02-05 17:46:46 +0100 |
commit | 1a102045353dba1a512a4be8e4de58f65ba04b0f (patch) | |
tree | b2cf69aef60314c2da22d3d161b77c306bd48a5a /lib | |
parent | d464e7ba8cec21c9e0ec7b418cf7414fa7942c97 (diff) |
IRIS: Only create UserAgent and strptime obj once
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Travel/Status/DE/IRIS.pm | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm index fbf449e..4cee47d 100644 --- a/lib/Travel/Status/DE/IRIS.pm +++ b/lib/Travel/Status/DE/IRIS.pm @@ -21,10 +21,6 @@ use XML::LibXML; sub new { my ( $class, %opt ) = @_; - my %lwp_options = %{ $opt{lwp_options} // { timeout => 10 } }; - - my $ua = LWP::UserAgent->new(%lwp_options); - if ( not $opt{station} ) { confess('station flag must be passed'); } @@ -40,10 +36,10 @@ sub new { main_cache => $opt{main_cache}, rt_cache => $opt{realtime_cache}, serializable => $opt{serializable}, - user_agent => $ua, + user_agent => $opt{user_agent}, with_related => $opt{with_related}, departure_by_id => {}, - strptime_obj => DateTime::Format::Strptime->new( + strptime_obj => $opt{strptime_obj} // DateTime::Format::Strptime->new( pattern => '%y%m%d%H%M', time_zone => 'Europe/Berlin', ), @@ -52,7 +48,11 @@ sub new { bless( $self, $class ); - $ua->env_proxy; + if ( not $self->{user_agent} ) { + my %lwp_options = %{ $opt{lwp_options} // { timeout => 10 } }; + $self->{user_agent} = LWP::UserAgent->new(%lwp_options); + $self->{user_agent}->env_proxy; + } my ( $station, @related_stations ) = $self->get_station( name => $opt{station}, @@ -72,6 +72,8 @@ sub new { station => $ref->{uic}, main_cache => $self->{main_cache}, realtime_cache => $self->{rt_cache}, + strptime_obj => $self->{strptime_obj}, + user_agent => $self->{user_agent}, with_related => 0, ); if ( not $ref_status->errstr ) { |