From d33460918190bef8259b19f5793d4fce0e7fe485 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 23 Jun 2011 16:16:41 +0200 Subject: Documentation --- bin/mris | 2 +- lib/Travel/Status/DE/DeutscheBahn.pm | 77 ++++++++++++++++++++++++ lib/Travel/Status/DE/DeutscheBahn/Departure.pm | 82 +++++++++++++++++++++++++- 3 files changed, 159 insertions(+), 2 deletions(-) diff --git a/bin/mris b/bin/mris index c6e34c7..95e1c6e 100755 --- a/bin/mris +++ b/bin/mris @@ -47,7 +47,7 @@ for my $d ( $status->departures() ) { printf( "%5s %-10s %-80s %-20s %-2d %s\n", - $d->time, $d->train, join( q{ }, @via_show ), + $d->time, $d->train, join( q{ }, @via_show ), $d->destination, $d->platform, $d->info ); } diff --git a/lib/Travel/Status/DE/DeutscheBahn.pm b/lib/Travel/Status/DE/DeutscheBahn.pm index 499f540..748184c 100644 --- a/lib/Travel/Status/DE/DeutscheBahn.pm +++ b/lib/Travel/Status/DE/DeutscheBahn.pm @@ -53,6 +53,21 @@ sub new { return bless( $ref, $obj ); } +sub new_from_html { + my ( $obj, $html ) = @_; + + my $ref = { html => $html, }; + + $ref->{tree} = XML::LibXML->load_html( + string => $ref->{html}, + recover => 2, + suppress_errors => 1, + suppress_warnings => 1, + ); + + return bless( $ref, $obj ); +} + sub departures { my ($self) = @_; @@ -137,30 +152,92 @@ departure monitor =head1 SYNOPSIS + use Travel::Status::DE::DeutscheBahn; + + my $status = Travel::Status::DE::DeutscheBahn->new( + station => 'Essen Hbf', + ); + + for my $departure ($status->departures) { + printf( + "At %s: %s to %s from platform %s\n", + $departure->time, + $departure->train, + $departure->destination, + $departure->platform, + ); + } + =head1 VERSION version 0.0 =head1 DESCRIPTION +Travel::Status::DE::DeutscheBahn is an interface to the DeutscheBahn +arrival/departure monitor available at +L. + +It takes a station name and (optional) date and time and reports all +departures at that station starting at the specified point in time (now if +unspecified). By default, it will list the next 20 departures. + =head1 METHODS =over +=item my $status = Travel::Status::DE::DeutscheBahn->new(I<%opts>) + +Returns a new Travel::Status::DE::DeutscheBahn element. Supported I are: + +=over + +=item B => I + +The train station to report for, e.g. "Essen HBf". Mandatory. + +=item B => I
.I.I + +Date to report for. Defaults to the current day. + +=item B