From 3e6db67758d71ed9f2474d2cc3d4e760814ed346 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 19 Jan 2025 14:08:26 +0100 Subject: DBRIS: Add documentation --- lib/Travel/Routing/DE/DBRIS.pm | 159 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 158 insertions(+), 1 deletion(-) (limited to 'lib/Travel') diff --git a/lib/Travel/Routing/DE/DBRIS.pm b/lib/Travel/Routing/DE/DBRIS.pm index deba8ad..70b71ba 100644 --- a/lib/Travel/Routing/DE/DBRIS.pm +++ b/lib/Travel/Routing/DE/DBRIS.pm @@ -25,7 +25,6 @@ Travel::Routing::DE::DBRIS->mk_ro_accessors(qw(earlier later)); sub new { my ( $obj, %conf ) = @_; - my $service = $conf{service}; my $ua = $conf{user_agent}; @@ -278,3 +277,161 @@ sub connections { # }}} 1; + +__END__ + +=head1 NAME + +Travel::Routing::DE::DBRIS - Interface to the bahn.de itinerary service + +=head1 SYNOPSIS + + use Travel::Routing::DE::DBRIS; + + # use Travel::Status::DE::DBRIS to obtain $from and $to objects + # (must be Travel::Status::DE::DBRIS::Location instances) + + my $ris = Travel::Routing::DE::DBRIS->new( + from => $from_location, + to => $to_location, + ); + + if (my $err = $ris->errstr) { + die("Request error: ${err}\n"); + } + + for my $con ( $ris->connections ) { + for my $seg ($con->segments) { + if ( not ($seg->is_transfer or $seg->is_walk) ) { + printf("%s -> %s\n%s ab %s\n%s an %s\n\n", + $seg->train_mid, + $seg->direction, + $seg->dep->strftime('%H:%M'), + $seg->dep_name, + $seg->arr->strftime('%H:%M'), + $seg->arr_name, + ); + } + } + print "\n\n"; + } + +=head1 VERSION + +version 0.01 + +=head1 DESCRIPTION + +Travel::Routing::DE::DBRIS is an interface to the bahn.de itinerary service. + +=head1 METHODS + +=over + +=item $ris = Travel::Routing::DE::DBRIS->new(I<%opt>) + +Request connections as specified by I<%opt> and return a new +Travel::Routing::DE::DBRIS instance with the results. Dies if the wrong I<%opt> +were passed. The B and B keys are mandatory. + +=over + +=item B => I (mandatory) + +A Travel::Status::DE::DBRIS::Location(3pm) instance describing the origin of +the requested itinerary. + +=item B => I (mandatory) + +A Travel::Status::DE::DBRIS::Location(3pm) instance describing the destination +of the requested itinerary. + +=item B => I + +A Cache::File(3pm) instance used for caching bahn.de requests. + +=item B => I + +Request departures on or after I (DateTime(3pm) instance). +Default: now. + +=item B => I + +Request text components to be provided in I (ISO 639-1 language code). +Known supported languages are: cs da de en es fr it nl pl. +Default: de. + +=item B => I + +Only request connections using the modes of transit specified in I. +Default: ICE, EC_IC, IR, REGIONAL, SBAHN, BUS, SCHIFF, UBAHN, TRAM, ANRUFPFLICHTIG. + +=item B => I + +Consider discounts specified in I when determining offer prices. +Supported items: bc25, bs25-first, bc50, bc50-first, bc100, bc100-first. +Default: none. + +=item B => I + +Use I for requests. +Default: A new LWP::UserAgent(3pm) object with env_proxy enabled and a timeout +of ten seconds. + +=item B => I + +Pass I to C<< LWP::UserAgent->new >>. +Default: C<< { timeout => 10 } >>. + +=back + +=item $ris->errstr + +Returns a string describing a HTTP or bahn.de error, if any such error occured. +Returns undef otherwise. + +=item $ris->connections + +Returns a list of Travel::Routing::DE::DBRIS::Connection(3pm) objects, each of +which describes a singre connction from I to I. + +=back + +=head1 DIAGNOSTICS + +when the B argument to B is set to a true value, +Travel::Routing::DE::DBRIS prints raw bahn.de requests and responses to stdout. + +None. + +=head1 DEPENDENCIES + +=over + +=item * Class::Accessor(3pm) + +=item * DateTime(3pm) + +=item * DateTime::Format::Strptime(3pm) + +=item * LWP::UserAgent(3pm) + +=item * Travel::Status::DE::DBRIS(3pm) + +=back + +=head1 BUGS AND LIMITATIONS + +This module is very much work-in-progress. + +=head1 SEE ALSO + +Travel::Routing::DE::DBRIS::Connection(3pm) + +=head1 AUTHOR + +Copyright (C) 2025 by Birte Kristina Friesel Ederf@finalrewind.orgE + +=head1 LICENSE + +This module is licensed under the same terms as Perl itself. -- cgit v1.2.3