summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-10-03 18:43:25 +0200
committerDaniel Friesel <derf@finalrewind.org>2022-10-03 18:43:25 +0200
commit071db7ee1ce1d2d022f192e80cf2f7c7aff4e176 (patch)
treea04e786f372d50e6ac90d3f702c382f22539ef45
parent571f956830a4b7e937490bef7d3643600055ddca (diff)
allow overriding ua via constructor
-rw-r--r--lib/Travel/Status/DE/HAFAS.pm24
1 files changed, 7 insertions, 17 deletions
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm
index a1660c8..105bf0f 100644
--- a/lib/Travel/Status/DE/HAFAS.pm
+++ b/lib/Travel/Status/DE/HAFAS.pm
@@ -180,7 +180,7 @@ sub new {
my %lwp_options = %{ $conf{lwp_options} // { timeout => 10 } };
- my $ua = LWP::UserAgent->new(%lwp_options);
+ my $ua = $conf{user_agent} // LWP::UserAgent->new(%lwp_options);
$ua->env_proxy;
@@ -188,7 +188,7 @@ sub new {
confess('You need to specify a station');
}
- if ( not defined $service and not defined $conf{url} ) {
+ if ( not defined $service ) {
$service = $conf{service} = 'DB';
}
@@ -196,7 +196,8 @@ sub new {
confess("The service '$service' is not supported");
}
- my $ref = {
+ my $now = DateTime->now( time_zone => 'Europe/Berlin' );
+ my $self = {
active_service => $service,
arrivals => $conf{arrivals},
developer_mode => $conf{developer_mode},
@@ -206,23 +207,12 @@ sub new {
results => [],
station => $conf{station},
ua => $ua,
- now => DateTime->now( time_zone => 'Europe/Berlin' ),
+ now => $now,
};
- bless( $ref, $obj );
+ bless( $self, $obj );
- if ( $hafas_instance{$service}{mgate} ) {
- return $ref->new_mgate(%conf);
- }
- return $ref->new_legacy(%conf);
-}
-
-sub new_mgate {
- my ( $self, %conf ) = @_;
- my $json = JSON->new->utf8;
- my $service = $conf{service};
-
- my $now = $self->{now};
+ my $json = JSON->new->utf8;
my $date = ( $conf{datetime} // $now )->strftime('%Y%m%d');
my $time = ( $conf{datetime} // $now )->strftime('%H%M%S');