summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Travel/Status/DE/DeutscheBahn.pm45
-rw-r--r--lib/Travel/Status/DE/DeutscheBahn/Departure.pm149
-rw-r--r--lib/Travel/Status/DE/DeutscheBahn/Result.pm179
3 files changed, 200 insertions, 173 deletions
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<http://reiseauskunft.bahn.de/bin/bhftafel.exe/dn>.
-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<dep>). Set this to B<arr> to get arrivals instead.
-For arrivals, the C<departures()> method will report the arrival time, the
-train's origin and their route until the selected I<station>.
-
=item B<mot> => I<\%hashref>
Modes of transport to show. Accepted keys are: B<ice> (ICE trains), B<ic_ec>
@@ -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<data>:
-
-=over
-
-=item B<time> => I<hh:mm>
-
-=item B<train> => I<string>
-
-=item B<route_raw> => I<string>
-
-=item B<route> => I<arrayref>
-
-=item B<destination> => I<string>
-
-=item B<platform> => I<string>
-
-=item B<info> => I<string>
-
-=back
-
-=back
-
-=head1 DIAGNOSTICS
-
-None.
-
-=head1 DEPENDENCIES
-
-=over
-
-=item Class::Accessor(3pm)
-
-=back
-
-=head1 BUGS AND LIMITATIONS
-
-Unknown.
-
-=head1 SEE ALSO
-
-Travel::Status::DE::DeutscheBahn(3pm).
-
-=head1 AUTHOR
-
-Copyright (C) 2011 by Daniel Friesel E<lt>derf@finalrewind.orgE<gt>
-
-=head1 LICENSE
-
-This module is licensed under the same terms as Perl itself.
diff --git a/lib/Travel/Status/DE/DeutscheBahn/Result.pm b/lib/Travel/Status/DE/DeutscheBahn/Result.pm
new file mode 100644
index 0000000..d3ae8d2
--- /dev/null
+++ b/lib/Travel/Status/DE/DeutscheBahn/Result.pm
@@ -0,0 +1,179 @@
+package Travel::Status::DE::DeutscheBahn::Result;
+
+use strict;
+use warnings;
+use 5.010;
+
+use parent 'Class::Accessor';
+
+our $VERSION = '0.0';
+
+Travel::Status::DE::DeutscheBahn::Result->mk_ro_accessors(
+ qw(time train route_end platform info));
+
+sub new {
+ my ( $obj, %conf ) = @_;
+
+ my $ref = \%conf;
+
+ return bless( $ref, $obj );
+}
+
+sub destination {
+ my ($self) = @_;
+
+ return $self->{route_end};
+}
+
+sub origin {
+ my ($self) = @_;
+
+ return $self->{route_end};
+}
+
+sub route {
+ my ($self) = @_;
+
+ return @{ $self->{route} };
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Travel::Status::DE::DeutscheBahn::Result - Information about a single
+arrival/departure received by Travel::Status::DE::DeutscheBahn
+
+=head1 SYNOPSIS
+
+ for my $departure ($status->results) {
+ printf(
+ "At %s: %s to %s from platform %s\n",
+ $departure->time,
+ $departure->train,
+ $departure->destination,
+ $departure->platform,
+ );
+ }
+
+ # or (depending on module setup)
+ for my $arrival ($status->results) {
+ printf(
+ "At %s: %s from %s on platform %s\n",
+ $arrival->time,
+ $arrival->train,
+ $arrival->origin,
+ $arrival->platform,
+ );
+ }
+
+=head1 VERSION
+
+version 0.0
+
+=head1 DESCRIPTION
+
+Travel::Status::DE::DeutscheBahn::Result describes a single arrival/departure
+as obtained by Travel::Status::DE::DeutscheBahn. It contains information about
+the platform, time, route and more.
+
+=head1 METHODS
+
+=head2 ACCESSORS
+
+=over
+
+=item $result->route_end
+
+Returns the last element of the route. Depending on how you set up
+Travel::Status::DE::DeutscheBahn (arrival or departure listing), this is
+either the train's destination or its origin station.
+
+For convenienc, this method can also be called as B<destination> or B<origin>.
+
+=item $result->info
+
+Returns additional information, usually wether the train is on time or
+delayed.
+
+=item $result->platform
+
+Returns the platform from which the train will depart / at which it will
+arrive.
+
+=item $result->route
+
+Returns a list of station names the train will pass between the selected
+station and its origin/destination.
+
+=item $result->time
+
+Returns the arrival/departure time as string in "hh:mm" format.
+
+=item $result->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
+
+=head2 INTERNAL
+
+=over
+
+=item $result = Travel::Status::DE::DeutscheBahn::Result->new(I<%data>)
+
+Returns a new Travel::Status::DE::DeutscheBahn::Result object.
+You usually do not need to call this.
+
+Required I<data>:
+
+=over
+
+=item B<time> => I<hh:mm>
+
+=item B<train> => I<string>
+
+=item B<route_raw> => I<string>
+
+=item B<route> => I<arrayref>
+
+=item B<route_end> => I<string>
+
+=item B<platform> => I<string>
+
+=item B<info> => I<string>
+
+=back
+
+=back
+
+=head1 DIAGNOSTICS
+
+None.
+
+=head1 DEPENDENCIES
+
+=over
+
+=item Class::Accessor(3pm)
+
+=back
+
+=head1 BUGS AND LIMITATIONS
+
+Unknown.
+
+=head1 SEE ALSO
+
+Travel::Status::DE::DeutscheBahn(3pm).
+
+=head1 AUTHOR
+
+Copyright (C) 2011 by Daniel Friesel E<lt>derf@finalrewind.orgE<gt>
+
+=head1 LICENSE
+
+This module is licensed under the same terms as Perl itself.