Commit eccf8ca2 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Move EFA logic to ::EFA, just set URL in ::VRR

parent 937a09c0
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ sub show_help {
sub handle_efa_exception {
	my ($e) = @_;

	if ( $e->isa('Travel::Routing::DE::VRR::Exception::Setup') ) {
	if ( $e->isa('Travel::Routing::DE::EFA::Exception::Setup') ) {
		if ( $e->message ) {
			printf STDERR (
				"Error: %s (option '%s'): %s\n",
@@ -59,23 +59,23 @@ sub handle_efa_exception {

		exit 1;
	}
	if ( $e->isa('Travel::Routing::DE::VRR::Exception::Net') ) {
	if ( $e->isa('Travel::Routing::DE::EFA::Exception::Net') ) {
		printf STDERR ( "Error: %s: %s\n", $e->description,
			$e->http_response->as_string );
		exit 2;
	}
	if ( $e->isa('Travel::Routing::DE::VRR::Exception::NoData') ) {
	if ( $e->isa('Travel::Routing::DE::EFA::Exception::NoData') ) {
		printf STDERR ( "Error: %s\n", $e->description );
		exit 3;
	}
	if ( $e->isa('Travel::Routing::DE::VRR::Exception::Ambiguous') ) {
	if ( $e->isa('Travel::Routing::DE::EFA::Exception::Ambiguous') ) {
		printf STDERR (
			"Error: %s for key %s. Specify one of %s\n",
			$e->description, $e->post_key, $e->possibilities
		);
		exit 4;
	}
	if ( $e->isa('Travel::Routing::DE::VRR::Exception::Other') ) {
	if ( $e->isa('Travel::Routing::DE::EFA::Exception::Other') ) {
		printf STDERR ( "Error: %s: %s\n", $e->description, $e->message );
		exit 5;
	}
@@ -90,17 +90,17 @@ sub check_for_error {
	if ( not defined $efa ) {
		if (    $eval_error
			and ref($eval_error)
			and $eval_error->isa('Travel::Routing::DE::VRR::Exception') )
			and $eval_error->isa('Travel::Routing::DE::EFA::Exception') )
		{
			handle_efa_exception($eval_error);
		}
		elsif ($eval_error) {
			printf STDERR
			  "Unknown Travel::Routing::DE::VRR error:\n${eval_error}";
			  "Unknown Travel::Routing::DE::EFA error:\n${eval_error}";
			exit 10;
		}
		else {
			say STDERR 'Travel::Routing::DE::VRR failed to return an object';
			say STDERR 'Travel::Routing::DE::EFA failed to return an object';
			exit 10;
		}
	}
+899 −0

File added.

Preview size limit exceeded, changes collapsed.

+12 −12
Original line number Diff line number Diff line
=head1 NAME

Travel::Routing::DE::VRR::Exception - Travel::Routing::DE::VRR Exceptions
Travel::Routing::DE::EFA::Exception - Travel::Routing::DE::EFA Exceptions

=head1 DESCRIPTION

All Exceptions throws by Travel::Routing::DE::VRR are
Travel::Routing::DE::VRR::Exception objects created by Exception::Class(3pm).
All Exceptions thrown by Travel::Routing::DE::EFA are
Travel::Routing::DE::EFA::Exception objects created by Exception::Class(3pm).

See Exception::Class::Base(3pm) for their common methods.

=head1 LIST OF EXCEPTIONS

=head2 Travel::Routing::DE::VRR::Exception::Setup
=head2 Travel::Routing::DE::EFA::Exception::Setup

An argument to B<new> had an invalid format.

@@ -33,25 +33,25 @@ What kind of argument we want.

=back

=head2 Travel::Routing::DE::VRR::Exception::Net
=head2 Travel::Routing::DE::EFA::Exception::Net

The HTTP request to the efa interface failed. Contains an HTTP::Response(3pm)
object describing the error in B<http_response>.

=head2 Travel::Routing::DE::VRR::Exception::NoData
=head2 Travel::Routing::DE::EFA::Exception::NoData

We got no parsable data from efa.vrr.de
We got no parsable data from the EFA service

=head2 Travel::Routing::DE::VRR::Exception::Ambiguous
=head2 Travel::Routing::DE::EFA::Exception::Ambiguous

Our request contained ambiguous data. B<post_key> contains the relevant POST
key, B<possibilities> is a comma-separated string of possible key values (as
reported by efa.vrr.de).
reported by the EFA service).

=head2 Travel::Routing::DE::VRR::Exception::NoConnections
=head2 Travel::Routing::DE::EFA::Exception::NoConnections

efa.vrr.de found no connections for our request.
The EFA service found no connections for our request.

=head1 SEE ALSO

Travel::Routing::DE::VRR(3pm)
Travel::Routing::DE::EFA(3pm)
+10 −10
Original line number Diff line number Diff line
package Travel::Routing::DE::VRR::Route;
package Travel::Routing::DE::EFA::Route;

use strict;
use warnings;
@@ -6,11 +6,11 @@ use 5.010;

use parent 'Class::Accessor';

use Travel::Routing::DE::VRR::Route::Part;
use Travel::Routing::DE::EFA::Route::Part;

our $VERSION = '2.04';

Travel::Routing::DE::VRR::Route->mk_ro_accessors(
Travel::Routing::DE::EFA::Route->mk_ro_accessors(
	qw(duration ticket_text ticket_type fare_adult fare_child vehicle_time));

sub new {
@@ -21,7 +21,7 @@ sub new {
	for my $part (@parts) {
		push(
			@{ $ref->{parts} },
			Travel::Routing::DE::VRR::Route::Part->new( %{$part} )
			Travel::Routing::DE::EFA::Route::Part->new( %{$part} )
		);
	}

@@ -40,13 +40,13 @@ __END__

=head1 NAME

Travel::Routing::DE::VRR::Route - Single route (connection) between two points
Travel::Routing::DE::EFA::Route - Single route (connection) between two points

=head1 SYNOPSIS

	for my $route ( $efa->routes ) {
		for my $part ( $route->parts ) {
			# $part is a Travel::Routing::DE::VRR::Route::Part object
			# $part is a Travel::Routing::DE::EFA::Route::Part object
		}
	}

@@ -56,8 +56,8 @@ version 2.04

=head1 DESCRIPTION

Travel::Routing::DE::VRR::Route describes a single method of getting from one
point to another.  It holds a bunch of Travel::Routing::DE::VRR::Route::Part(3pm)
Travel::Routing::DE::EFA::Route describes a single method of getting from one
point to another.  It holds a bunch of Travel::Routing::DE::EFA::Route::Part(3pm)
objects describing the parts of the route in detail.  Each part depends on the
previous one.

@@ -75,7 +75,7 @@ route duration as string in HH:MM format

=item $route->parts

Returns a list of Travel::Routing::DE::VRR::Route::Part(3pm) elements describing
Returns a list of Travel::Routing::DE::EFA::Route::Part(3pm) elements describing
the actual route

=item $route->ticket_type
@@ -110,7 +110,7 @@ None known.

=head1 SEE ALSO

Travel::Routing::DE::VRR(3pm), Travel::Routing::DE::VRR::Route::Part(3pm).
Travel::Routing::DE::EFA(3pm), Travel::Routing::DE::EFA::Route::Part(3pm).

=head1 AUTHOR

+6 −6
Original line number Diff line number Diff line
package Travel::Routing::DE::VRR::Route::Part;
package Travel::Routing::DE::EFA::Route::Part;

use strict;
use warnings;
@@ -8,7 +8,7 @@ use parent 'Class::Accessor';

our $VERSION = '2.04';

Travel::Routing::DE::VRR::Route::Part->mk_ro_accessors(
Travel::Routing::DE::EFA::Route::Part->mk_ro_accessors(
	qw(arrival_platform arrival_stop
	  arrival_date arrival_time arrival_sdate arrival_stime
	  delay departure_platform departure_stop
@@ -65,7 +65,7 @@ __END__

=head1 NAME

Travel::Routing::DE::VRR::Route::Part - Describes one connection between two
Travel::Routing::DE::EFA::Route::Part - Describes one connection between two
points, without interchanges

=head1 SYNOPSIS
@@ -90,11 +90,11 @@ version 2.04

=head1 DESCRIPTION

B<Travel::Routing::DE::VRR::Route::Part> holds one specific connection (without
B<Travel::Routing::DE::EFA::Route::Part> holds one specific connection (without
interchanges) between two points.  It specifies the start/stop point and time,
the train line and its destination, and optional additional data.

It is usually obtained by a call to Travel::Routing::DE::VRR::Route(3pm)'s
It is usually obtained by a call to Travel::Routing::DE::EFA::Route(3pm)'s
B<parts> method.

=head1 METHODS
@@ -206,7 +206,7 @@ $part->via does not work reliably.

=head1 SEE ALSO

Travel::Routing::DE::VRR(3pm), Class::Accessor(3pm).
Travel::Routing::DE::EFA(3pm), Class::Accessor(3pm).

=head1 AUTHOR

Loading