Travel::Status::DE::HAFAS - Interface to HAFAS-based online arrival/departure monitors
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 6.11
Travel::Status::DE::HAFAS is an interface to HAFAS-based arrival/departure monitors using the mgate.exe interface.
It can report departures/arrivals at a specific station, search for stations, or provide details about a specific journey. It supports non-blocking operation via promises.
Requests item(s) as specified by opt and returns a new Travel::Status::DE::HAFAS element with the results. Dies if the wrong opt were passed.
opt must contain either a station, geoSearch, locationSearch, journey, or journeyMatch flag:
Request station board (arrivals or departures) for station, e.g. "Essen HBf" or
"Alfredusbad, Essen (Ruhr)". The station must be specified either by name or by
EVA ID (e.g. 8000080 for Dortmund Hbf).
Results are available via $status->results
.
Search for stations near latitude, longitude.
Results are available via $status->results
.
Search for stations whose name is similar to query.
Results are available via $status->results
.
Request details about the journey identified by tripid and line.
The result is available via $status->result
.
Request journeys that match query (e.g. "ICE 205" or "S 31111").
Results are available via $status->results
.
In contrast to journey, the results typically only contain a minimal amount
of information: trip ID, train/line identifier, and first and last stop. There
is no real-time data.
The following optional flags may be set. Values in brackets indicate flags that are only relevant in certain request modes, e.g. geoSearch or journey.
Request arrivals (if bool is true) rather than departures (if bool is false or arrivals is not specified).
Store HAFAS replies in the provided cache object. This module works with real-time data, so the object should be configured for an expiry of one to two minutes.
Date and time to report for. Defaults to now.
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.
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.
Request text messages to be provided in language. Supported languages depend on service, use get_services or get_service to get the supported values. Providing an unsupported or invalid value may lead to garbage output.
Request arrivals/departures that occur up to int minutes after the specified datetime. Default: -1 (do not limit results by time).
Passed on to LWP::UserAgent->new
. Defaults to { timeout => 10 }
,
pass an empty hashref to call the LWP::UserAgent constructor without arguments.
Request up to count results. Default: 30.
Request results from service, defaults to "DB".
See get_services (and hafas-m --list
) for a list of supported
services.
Request a polyline (series of geo-coordinates) indicating the train's route.
Returns a promise that resolves into a Travel::Status::DE::HAFAS instance ($status) on success and rejects with an error message on failure. If the failure occured after receiving a response from the HAFAS backend, the rejected promise contains a Travel::Status::DE::HAFAS instance as a second argument. This instance can be used e.g. to call similar_stops_p in case of an ambiguous location specifier. In addition to the arguments of new, the following mandatory arguments must be set.
Promises implementation to use for internal promises as well as new_p return value. Recommended: Mojo::Promise(3pm).
User agent instance to use for asynchronous requests. The object must implement a post_p function. Recommended: Mojo::UserAgent(3pm).
In case of an error in the HAFAS backend, returns the corresponding error code as string. If no backend error occurred, returns undef.
In case of an error in the HTTP request or HAFAS backend, returns a string describing it. If no error occurred, returns undef.
Returns a list of stop locations. Each list element is a Travel::Status::DE::HAFAS::Location(3pm) object.
If no matching results were found or the parser / http request failed, returns an empty list.
Returns a list of arrivals/departures. Each list element is a Travel::Status::DE::HAFAS::Journey(3pm) object.
If no matching results were found or the parser / http request failed, returns undef.
Returns a list of Travel::Status::DE::HAFAS::Journey(3pm) object that describe matching journeys. In general, these objects lack real-time data, intermediate stops, and more.
Returns a single Travel::Status::DE::HAFAS::Journey(3pm) object that describes the requested journey.
If no result was found or the parser / http request failed, returns undef.
Returns a list of Travel::Status::DE::HAFAS::Message(3pm) objects with service messages. Each message belongs to at least one arrival/departure (station, journey) or to at least stop alongside its route (journey).
Returns a hashref describing the departure stations in all requested journeys. The hashref contains four entries: names (station names), name (most common name), evas (UIC / EVA IDs), and eva (most common UIC / EVA ID). These are subject to change.
Note that the most common name and ID may be different from the station for which departures were requested, as HAFAS uses different identifiers for train stations, bus stops, and other modes of transit even if they are interlinked.
Not available in journey mode.
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 'LOCATION', 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.
Returns a promise resolving to 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 'LOCATION', 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 resolved values.
If $status has been created using new_p, this function does not require arguments. Otherwise, the caller must specify promise and user_agent (see new_p above).
Returns a hashref describing the active service when a service is active and nothing otherwise. The hashref contains the following keys.
Area in which the service provides near-optimal coverage. Typically, this means a (nearly) complete list of departures and real-time data. The hashref contains two optional keys: area (GeoJSON) and regions (list of strings, e.g. "DE" or "CH-BE").
Homepage URL of the service provider.
Languages supported by the backend; see the constructor's language argument.
Service name, e.g. Bay Area Rapid Transit or Deutsche Bahn.
HAFAS backend URL
MOT bits supported by the backend. arrayref contains either strings (one string per mode of transit) or arrayrefs (one string pair per mode of transit, with the first entry referring to the MOT identifier and the second one containing a slightly longer description of it).
The time zone this service reports arrival/departure times in. If this key is not present, it is safe to assume that it uses Europe/Berlin.
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, e.g. BART or DB.
Returns a hashref describing the service $service. Returns nothing if $service is not supported. See get_active_service for the hashref layout.
None.
The non-default services (anything other than DB) are not well tested.
Copyright (C) 2015-2024 by Birte Kristina Friesel <derf@finalrewind.org>
This module is licensed under the same terms as Perl itself.