summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/efa-m5
-rw-r--r--lib/Travel/Status/DE/VRR.pm26
2 files changed, 28 insertions, 3 deletions
diff --git a/bin/efa-m b/bin/efa-m
index def9f07..a094de2 100755
--- a/bin/efa-m
+++ b/bin/efa-m
@@ -88,6 +88,11 @@ sub display_result {
return;
}
+if ( my $err = $status->errstr ) {
+ say STDERR "Request error: ${err}";
+ exit 2;
+}
+
for my $d ( $status->results ) {
push( @output,
diff --git a/lib/Travel/Status/DE/VRR.pm b/lib/Travel/Status/DE/VRR.pm
index a108425..02985a7 100644
--- a/lib/Travel/Status/DE/VRR.pm
+++ b/lib/Travel/Status/DE/VRR.pm
@@ -59,14 +59,22 @@ sub new {
},
};
+ bless( $self, $class );
+
$mech->post( 'http://efa.vrr.de/vrr/XSLT_DM_REQUEST', $self->{post} );
if ( $mech->response->is_error ) {
- confess( $mech->response->status_line );
+ $self->{errstr} = $mech->response->status_line;
+ return $self;
}
my $form = $mech->form_number(1);
+ if ( not $form ) {
+ $self->{errstr} = 'Unable to find the form - no lines returned?';
+ return $self;
+ }
+
for my $input ( $form->find_input( 'dmLineSelection', 'option' ) ) {
$input->check();
}
@@ -74,7 +82,8 @@ sub new {
$mech->click('submitButton');
if ( $mech->response->is_error ) {
- confess( $mech->response->status_line );
+ $self->{errstr} = $mech->response->status_line;
+ return $self;
}
$self->{html} = $mech->response->decoded_content;
@@ -86,7 +95,13 @@ sub new {
suppress_warnings => 1,
);
- return bless( $self, $class );
+ return $self;
+}
+
+sub errstr {
+ my ($self) = @_;
+
+ return $self->{errstr};
}
sub results {
@@ -188,6 +203,11 @@ address / poi / stop name to list departures for.
=back
+=item $status->errstr
+
+In case of an error in the HTTP requests, returns a string describing it. If
+no error occured, returns undef.
+
=item $status->results
Returns a list of Travel::Status::DE::VRR::Result(3pm) objects, each one describing