From 51a2b02fe0e4269314ae697bf4705d8ab138e87f Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 14 Sep 2025 21:28:44 +0200 Subject: HAFAS->new: run service check before accessing sub-keys Thu subsequent $hafas_instance->{$service}{...} checks create $hafas_instance->{$service}, so at that point checking for it is moot. --- lib/Travel/Status/DE/HAFAS.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index 4d20270..83ad45b 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -41,6 +41,10 @@ sub new { my $ua = $conf{user_agent}; + if ( defined $service and not exists $hafas_instance->{$service} ) { + confess("The service '$service' is not supported"); + } + if ( not $ua ) { my %lwp_options = %{ $conf{lwp_options} // { timeout => 10 } }; if ( $service and $hafas_instance->{$service}{ua_string} ) { @@ -79,10 +83,6 @@ sub new { confess("You must specify a service"); } - if ( defined $service and not exists $hafas_instance->{$service} ) { - confess("The service '$service' is not supported"); - } - my $now = DateTime->now( time_zone => $hafas_instance->{$service}{time_zone} // 'Europe/Berlin' ); my $self = { -- cgit v1.2.3