From be8fb91dbc4d494a27f96ca2c55eaca80a98b910 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 16 Sep 2015 15:05:12 +0200 Subject: HAFAS: error handling for get_(active_)service --- lib/Travel/Status/DE/HAFAS.pm | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index 21b0684..26c68d6 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -345,7 +345,7 @@ sub get_services { sub get_service { my ($service) = @_; - if ( defined $service ) { + if ( defined $service and exists $hafas_instance{$service}) { return %{ $hafas_instance{$service} }; } return; @@ -354,7 +354,10 @@ sub get_service { sub get_active_service { my ($self) = @_; - return %{ $hafas_instance{ $self->{active_service} } }; + if (defined $self->{active_service}) { + return %{ $hafas_instance{ $self->{active_service} } }; + } + return; } 1; @@ -504,10 +507,11 @@ on the return value. =item $status->get_active_service -Returns a hash describing the active service. Contains the keys -B (URL to the station board service), B (URL to the -stopfinder service, if supported), B, and B -(arrayref describing the supported modes of transport, may contain duplicates). +Returns a hash describing the active service when a service is active and +nothing otherwise. The hash contains the keys B (URL to the station board +service), B (URL to the stopfinder service, if supported), B, +and B (arrayref describing the supported modes of transport, may +contain duplicates). =item Travel::Status::DE::HAFAS::get_services() @@ -518,7 +522,8 @@ the constructor's B parameter. =item Travel::Status::DE::HAFAS::get_service(I<$service>) -Returns a hash describing the service I<$service>. See +Returns a hash describing the service I<$service>. Returns nothing +if I<$service> is not supported. See B for the hash layout. =back -- cgit v1.2.3