From 41b232d84b944d3c6e3abe99153528dd02951a93 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 11 Sep 2011 13:40:51 +0200 Subject: VRR.pm: Only die when getting invalid arguments, set ->errstr for request errors --- lib/Travel/Status/DE/VRR.pm | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3