From 2f8567d38b418dba31111e6886b2558548790496 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 10 Sep 2015 10:41:32 +0200 Subject: add -s/-u support --- lib/Travel/Status/DE/HAFAS.pm | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index fe8cf2e..6589359 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -27,9 +27,9 @@ sub new { my $date = $conf{date} // strftime( '%d.%m.%Y', localtime(time) ); my $time = $conf{time} // strftime( '%H:%M', localtime(time) ); - my $lang = $conf{language} // 'd'; - my $mode = $conf{mode} // 'dep'; - my $service = $conf{service} // 'DB'; + my $lang = $conf{language} // 'd'; + my $mode = $conf{mode} // 'dep'; + my $service = $conf{service}; my %lwp_options = %{ $conf{lwp_options} // { timeout => 10 } }; @@ -43,6 +43,10 @@ sub new { confess('You need to specify a station'); } + if ( not defined $service and not defined $conf{url} ) { + $service = 'DB'; + } + my $ref = { active_service => $service, developer_mode => $conf{developer_mode}, @@ -60,7 +64,7 @@ sub new { $ref->set_productfilter; - my $url = $hafas_instance{$service}{url} . '/' . $lang . 'n'; + my $url = ( $conf{url} // $hafas_instance{$service}{url} ) . "/${lang}n"; $reply = $ua->post( $url, $ref->{post} ); @@ -100,8 +104,10 @@ sub set_productfilter { my $service = $self->{active_service}; - $self->{post}{productsFilter} - = '1' x ( scalar @{ $hafas_instance{$service}{productbits} } ); + if ($service) { + $self->{post}{productsFilter} + = '1' x ( scalar @{ $hafas_instance{$service}{productbits} } ); + } } sub check_input_error { @@ -207,7 +213,7 @@ sub get_services { sub get_service { my ($self) = @_; - return %{ $hafas_instance{ $self->active_service } }; + return %{ $hafas_instance{ $self->{active_service} } }; } 1; -- cgit v1.2.3