NAME
Travel::Status::DE::HAFAS - Interface to HAFAS-based online arrival/departure monitors
SYNOPSIS
use Travel::Status::DE::HAFAS;
my $status = Travel::Status::DE::HAFAS->new(
station => 'Essen Hbf',
);
if (my $err = $status->errstr) {
die("Request error: ${err}\n");
}
for my $departure ($status->results) {
printf(
"At %s: %s to %s from platform %s\n",
$departure->time,
$departure->line,
$departure->destination,
$departure->platform,
);
}
VERSION
version 2.01
DESCRIPTION
Travel::Status::DE::HAFAS is an interface to HAFAS-based arrival/departure monitors, for instance the one available at http://reiseauskunft.bahn.de/bin/bhftafel.exe/dn.
It takes a station name and (optional) date and time and reports all arrivals or departures at that station starting at the specified point in time (now if unspecified).
METHODS
- my $status = Travel::Status::DE::HAFAS->new(%opts)
-
Requests the departures/arrivals as specified by opts and returns a new Travel::Status::DE::HAFAS element with the results. Dies if the wrong opts were passed.
Supported opts are:
- station => station
-
The station or stop to report for, e.g. "Essen HBf" or "Alfredusbad, Essen (Ruhr)". Mandatory.
- date => dd.mm.yyyy
-
Date to report for. Defaults to the current day.
- excluded_mots => [mot1, mot2, ...]
-
By default, all modes of transport (trains, trams, buses etc.) are returned. If this option is set, all modes appearing in mot1, mot2, ... will be excluded. The supported modes depend on service, use get_services or get_service to get the supported values.
Note that this parameter does not work if the url parameter is set.
- exclusive_mots => [mot1, mot2, ...]
-
If this option is set, only the modes of transport appearing in mot1, mot2, ... will be returned. The supported modes depend on service, use get_services or get_service to get the supported values.
Note that this parameter does not work if the url parameter is set.
- language => language
-
Set language for additional information. Accepted arguments are deutsch, english, italian and n (dutch), depending on the used service.
- lwp_options => \%hashref
-
Passed on to
LWP::UserAgent->new
. Defaults to{ timeout => 10 }
, you can use an empty hashref to override it. - mode => arr|dep
-
By default, Travel::Status::DE::HAFAS reports train departures (dep). Set this to arr to get arrivals instead.
- service => service
-
Request results from service, defaults to "DB". See get_services (and
hafas-m --list
) for a list of supported services. - time => hh:mm
-
Time to report for. Defaults to now.
- url => url
-
Request results from url, defaults to the one belonging to service.
- $status->errcode
-
In case of an error in the HAFAS backend, returns the corresponding error code as string. If no backend error occurred, returns undef.
- $status->errstr
-
In case of an error in the HTTP request or HAFAS backend, returns a string describing it. If no error occurred, returns undef.
- $status->results
-
Returns a list of arrivals/departures. Each list element is a Travel::Status::DE::HAFAS::Result(3pm) object.
If no matching results were found or the parser / http request failed, returns undef.
- $status->similar_stops
-
Returns a list of hashrefs describing stops whose name is similar to the one requested in the constructor's station parameter. Returns nothing if the active service does not support this feature. This is most useful if errcode returns 'H730', which means that the HAFAS backend could not identify the stop.
See Travel::Status::DE::HAFAS::StopFinder(3pm)'s results method for details on the return value.
- $status->get_active_service
-
Returns a hashref describing the active service when a service is active and nothing otherwise. The hashref contains the keys url (URL to the station board service), stopfinder (URL to the stopfinder service, if supported), name, and productbits (arrayref describing the supported modes of transport, may contain duplicates).
- Travel::Status::DE::HAFAS::get_services()
-
Returns an array containing all supported HAFAS services. Each element is a hashref and contains all keys mentioned in get_active_service. It also contains a shortname key, which is the service name used by the constructor's service parameter.
- Travel::Status::DE::HAFAS::get_service($service)
-
Returns a hashref describing the service $service. Returns nothing if $service is not supported. See get_active_service for the hashref layout.
DIAGNOSTICS
None.
DEPENDENCIES
Class::Accessor(3pm)
LWP::UserAgent(3pm)
XML::LibXML(3pm)
BUGS AND LIMITATIONS
The non-default services (anything other than DB) are not well tested.
SEE ALSO
Travel::Status::DE::HAFAS::Result(3pm), Travel::Status::DE::HAFAS::StopFinder(3pm).
AUTHOR
Copyright (C) 2015 by Daniel Friesel <derf@finalrewind.org>
LICENSE
This module is licensed under the same terms as Perl itself.