diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-09-11 13:40:51 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-09-11 13:41:15 +0200 |
commit | 41b232d84b944d3c6e3abe99153528dd02951a93 (patch) | |
tree | faa9dab207b3f6895dd230dbb977763e89a4cd71 | |
parent | 4ab8c3cc012f4154c79428243d62f94938d7563a (diff) |
VRR.pm: Only die when getting invalid arguments, set ->errstr for request errors
-rwxr-xr-x | bin/efa-m | 5 | ||||
-rw-r--r-- | lib/Travel/Status/DE/VRR.pm | 26 |
2 files changed, 28 insertions, 3 deletions
@@ -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 |