summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Net/Travel/DE/VRR.pm25
-rw-r--r--lib/Net/Travel/DE/VRR/Route.pm72
-rw-r--r--lib/Net/Travel/DE/VRR/Route/Part.pm69
3 files changed, 154 insertions, 12 deletions
diff --git a/lib/Net/Travel/DE/VRR.pm b/lib/Net/Travel/DE/VRR.pm
index 5d330fd..7948194 100644
--- a/lib/Net/Travel/DE/VRR.pm
+++ b/lib/Net/Travel/DE/VRR.pm
@@ -5,6 +5,7 @@ use warnings;
use 5.010;
use Carp qw(confess);
+use Net::Travel::DE::VRR::Route;
use LWP::UserAgent;
use XML::LibXML;
@@ -319,7 +320,7 @@ sub parse_initial {
sub parse_pretty {
my ($con_parts) = @_;
- my $elements;
+ my @elements;
my @next_extra;
for my $con ( @{$con_parts} ) {
@@ -370,10 +371,10 @@ sub parse_pretty {
$hash->{arr_stop} = $con->[6];
$hash->{train_dest} = $con->[7];
- push( @{$elements}, $hash );
+ push( @elements, $hash );
}
- return $elements;
+ return Net::Travel::DE::VRR::Route->new(@elements);
}
sub new {
@@ -416,7 +417,7 @@ sub parse {
my $raw_cons = parse_initial($tree);
for my $raw_con ( @{$raw_cons} ) {
- push( @{ $self->{connections} }, parse_pretty($raw_con) );
+ push( @{ $self->{routes} }, parse_pretty($raw_con) );
}
$self->{tree} = $tree;
@@ -470,10 +471,10 @@ sub check_no_connections {
return;
}
-sub connections {
+sub routes {
my ($self) = @_;
- return @{ $self->{connections} };
+ return @{ $self->{routes} };
}
1;
@@ -496,12 +497,12 @@ Net::Travel::DE::VRR - inofficial interface to the efa.vrr.de German itinerary s
$efa->submit();
$efa->parse();
- for my $con ($efa->connections()) {
- for my $c (@{$con}) {
+ for my $route ($efa->routes()) {
+ for my $part (@{$route}) {
printf(
- "%-5s ab %-30s %-20s %s\n%-5s an %-30s\n\n",,
- @{$c}{'dep_time', 'dep_stop', 'train_line', 'train_dest'},
- @{$c}{'arr_time', 'arr_stop'},
+ "%-5s ab %-30s %-20s %s\n%-5s an %-30s\n\n",
+ $part->dep_time, $part->dep_stop, $part->train_line,
+ $part->train_dest, $part->arr_time, $part->arr_stop,
);
}
print "\n\n";
@@ -602,7 +603,7 @@ I<%opts> is passed on to LWP::UserAgent->new(%opts).
Parse the B<efa.vrr.de> reply.
returns a true value on success.
-=item $efa->connections()
+=item $efa->routes()
Returns an array of connection elements. Each connection element is an
arrayref of connection part, and each connecton part is a hash containing the
diff --git a/lib/Net/Travel/DE/VRR/Route.pm b/lib/Net/Travel/DE/VRR/Route.pm
new file mode 100644
index 0000000..1b71097
--- /dev/null
+++ b/lib/Net/Travel/DE/VRR/Route.pm
@@ -0,0 +1,72 @@
+package Net::Travel::DE::VRR::Route;
+
+use strict;
+use warnings;
+use 5.010;
+
+use Net::Travel::DE::VRR::Route::Part;
+
+our $VERSION = '1.3';
+
+sub new {
+ my ( $obj, @parts ) = @_;
+
+ my $ref = {};
+
+ for my $part (@parts) {
+ push(
+ @{ $ref->{parts} },
+ Net::Travel::DE::VRR::Route::Part->new( %{$part} )
+ );
+ }
+
+ return bless( $ref, $obj );
+}
+
+sub parts {
+ my ($self) = @_;
+
+ return @{ $self->{parts} };
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Net::Travel::DE::VRR::Route - Single route (connection) between two points
+
+=head1 SYNOPSIS
+
+=head1 VERSION
+
+version 1.3
+
+=head1 DESCRIPTION
+
+=head1 METHODS
+
+=over
+
+=back
+
+=head1 DIAGNOSTICS
+
+=head1 DEPENDENCIES
+
+=over
+
+=back
+
+=head1 BUGS AND LIMITATIONS
+
+=head1 SEE ALSO
+
+=head1 AUTHOR
+
+Copyright (C) 2011 by Daniel Friesel E<lt>derf@finalrewind.orgE<gt>
+
+=head1 LICENSE
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
diff --git a/lib/Net/Travel/DE/VRR/Route/Part.pm b/lib/Net/Travel/DE/VRR/Route/Part.pm
new file mode 100644
index 0000000..d512fbb
--- /dev/null
+++ b/lib/Net/Travel/DE/VRR/Route/Part.pm
@@ -0,0 +1,69 @@
+package Net::Travel::DE::VRR::Route::Part;
+
+use strict;
+use warnings;
+use 5.010;
+
+use parent 'Class::Accessor';
+
+our $VERSION = '1.3';
+
+Net::Travel::DE::VRR::Route::Part->mk_ro_accessors(
+ qw(arr_stop arr_time dep_stop dep_time train_line train_dest));
+
+sub new {
+ my ( $obj, %conf ) = @_;
+
+ my $ref = \%conf;
+
+ return bless( $ref, $obj );
+}
+
+sub extra {
+ my ($self) = @_;
+
+ return @{ $self->{extra} // [] };
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Net::Travel::DE::VRR::Route::Part - Describes one connection between two
+points, without interchanges
+
+=head1 SYNOPSIS
+
+=head1 VERSION
+
+version 0.3
+
+=head1 DESCRIPTION
+
+=head1 METHODS
+
+=over
+
+=back
+
+=head1 DIAGNOSTICS
+
+=head1 DEPENDENCIES
+
+=over
+
+=back
+
+=head1 BUGS AND LIMITATIONS
+
+=head1 SEE ALSO
+
+=head1 AUTHOR
+
+Copyright (C) 2011 by Daniel Friesel E<lt>derf@finalrewind.orgE<gt>
+
+=head1 LICENSE
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.