From 60a889227272419d388312f788756f421f489dc7 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 27 Jun 2011 21:57:24 +0200 Subject: Travel::Status::DE::DeutscheBahn::{Departure -> Result} --- bin/db-ris | 4 +- lib/Travel/Status/DE/DeutscheBahn.pm | 45 +++---- lib/Travel/Status/DE/DeutscheBahn/Departure.pm | 149 -------------------- lib/Travel/Status/DE/DeutscheBahn/Result.pm | 179 +++++++++++++++++++++++++ 4 files changed, 202 insertions(+), 175 deletions(-) delete mode 100644 lib/Travel/Status/DE/DeutscheBahn/Departure.pm create mode 100644 lib/Travel/Status/DE/DeutscheBahn/Result.pm diff --git a/bin/db-ris b/bin/db-ris index 3d829b0..f3e3beb 100755 --- a/bin/db-ris +++ b/bin/db-ris @@ -61,7 +61,7 @@ sub display_result { return; } -for my $d ( $status->departures() ) { +for my $d ( $status->results() ) { my ( @via, @via_main, @via_show ); @@ -130,7 +130,7 @@ version 0.0 =head1 DESCRIPTION -db-riss is an interface to the DeutscheBahn arrival/departure monitor +db-ris is an interface to the DeutscheBahn departure monitor available at L. It requests all departures at I (optionally filtered by date, time, diff --git a/lib/Travel/Status/DE/DeutscheBahn.pm b/lib/Travel/Status/DE/DeutscheBahn.pm index 447715e..577f72a 100644 --- a/lib/Travel/Status/DE/DeutscheBahn.pm +++ b/lib/Travel/Status/DE/DeutscheBahn.pm @@ -7,7 +7,7 @@ use 5.010; use Carp qw(confess); use LWP::UserAgent; use POSIX qw(strftime); -use Travel::Status::DE::DeutscheBahn::Departure; +use Travel::Status::DE::DeutscheBahn::Result; use XML::LibXML; our $VERSION = '0.0'; @@ -81,7 +81,7 @@ sub new_from_html { return bless( $ref, $obj ); } -sub departures { +sub results { my ($self) = @_; my $mode = $self->{post}->{boardType}; @@ -139,20 +139,20 @@ sub departures { } push( - @{ $self->{departures} }, - Travel::Status::DE::DeutscheBahn::Departure->new( - time => $time, - train => $train, - route_raw => $route, - route => \@via, - destination => $dest, - platform => $platform, - info => $info, + @{ $self->{results} }, + Travel::Status::DE::DeutscheBahn::Result->new( + time => $time, + train => $train, + route_raw => $route, + route => \@via, + route_end => $dest, + platform => $platform, + info => $info, ) ); } - return @{ $self->{departures} }; + return @{ $self->{results} }; } 1; @@ -162,7 +162,7 @@ __END__ =head1 NAME Travel::Status::DE::DeutscheBahn - Interface to the DeutscheBahn online -departure monitor +arrival/departure monitor =head1 SYNOPSIS @@ -172,7 +172,7 @@ departure monitor station => 'Essen Hbf', ); - for my $departure ($status->departures) { + for my $departure ($status->results) { printf( "At %s: %s to %s from platform %s\n", $departure->time, @@ -192,9 +192,9 @@ 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. +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). =head1 METHODS @@ -223,9 +223,6 @@ Time to report for. Defaults to now. By default, Travel::Status::DE::DeutscheBahn reports train departures (B). Set this to B to get arrivals instead. -For arrivals, the C method will report the arrival time, the -train's origin and their route until the selected I. - =item B => I<\%hashref> Modes of transport to show. Accepted keys are: B (ICE trains), B @@ -240,10 +237,10 @@ By default, the following are shown: ice, ic_ec, d, nv, s. =back -=item $status->departures() +=item $status->results() -Returns a list of departures (20 by default). Each list element is a -Travel::Status::DE::DeutscheBahn::Departure(3pm) object. +Returns a list of arrivals/departures. Each list element is a +Travel::Status::DE::DeutscheBahn::Result(3pm) object. =back @@ -269,7 +266,7 @@ Unknown. =head1 SEE ALSO -mris(1), Travel::Status::DE::DeutscheBahn::Departure(3pm). +mris(1), Travel::Status::DE::DeutscheBahn::Result(3pm). =head1 AUTHOR diff --git a/lib/Travel/Status/DE/DeutscheBahn/Departure.pm b/lib/Travel/Status/DE/DeutscheBahn/Departure.pm deleted file mode 100644 index d4487ac..0000000 --- a/lib/Travel/Status/DE/DeutscheBahn/Departure.pm +++ /dev/null @@ -1,149 +0,0 @@ -package Travel::Status::DE::DeutscheBahn::Departure; - -use strict; -use warnings; -use 5.010; - -use parent 'Class::Accessor'; - -our $VERSION = '0.0'; - -Travel::Status::DE::DeutscheBahn::Departure->mk_ro_accessors( - qw(time train destination platform info)); - -sub new { - my ( $obj, %conf ) = @_; - - my $ref = \%conf; - - return bless( $ref, $obj ); -} - -sub route { - my ($self) = @_; - - return @{ $self->{route} }; -} - -1; - -__END__ - -=head1 NAME - -Travel::Status::DE::DeutscheBahn::Departure - Information about a single -departure received by Travel::Status::DE::DeutscheBahn - -=head1 SYNOPSIS - - 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::Departure describes a single departure as -obtained by Travel::Status::DE::DeutscheBahn. It contains information about -the platform, departure time, destination and more. - -=head1 ACCESSORS - -=over - -=item $departure->destination - -Returns the name of the destination station, e.g. "Dortmund Hbf". - -=item $departure->info - -Returns additional information, usually wether the train is on time or -delayed. - -=item $departure->platform - -Returns the platform from which the train will depart. - -=item $departure->route - -Returns a list of station names the train will pass between the selected -station and its destination. - -=item $departure->time - -Returns the departure time as string in "hh:mm" format. - -=item $departure->train - -Returns the line / train name, either in a format like "S 1" (S-Bahn line 1) -or "RE 10111" (RegionalExpress train 10111, no line information). - -=back - -=head1 METHODS - -=over - -=item $departure = Travel::Status::DE::DeutscheBahn::Departure->new(I<%data>) - -Returns a new Travel::Status::DE::DeutscheBahn::Departure object. -You usually do not need to call this. - -Required I: - -=over - -=item B