From 4c0dc86a3fd165ae2fa2c48286056c9ea13a2352 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 12 Aug 2011 01:21:40 +0200 Subject: cgi: Error handling --- cgi/index.pl | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'cgi/index.pl') diff --git a/cgi/index.pl b/cgi/index.pl index 3051f94..96dd488 100644 --- a/cgi/index.pl +++ b/cgi/index.pl @@ -9,20 +9,20 @@ sub get_results_for { my ($station) = @_; my $cache = Cache::File->new( - cache_root => '/tmp/db-fake', + cache_root => '/tmp/db-fake', default_expires => '900 sec' ); my $results = $cache->thaw($station); - if (not $results) { - my $status = Travel::Status::DE::DeutscheBahn->new( station => $station - ); - $results = [$status->results]; - $cache->freeze($station, $results); + if ( not $results ) { + my $status + = Travel::Status::DE::DeutscheBahn->new( station => $station ); + $results = [ $status->results ]; + $cache->freeze( $station, $results ); } - return @{ $results }; + return @{$results}; } get '/' => sub { @@ -43,8 +43,14 @@ get '/multi/:station' => sub { filename => dist_file( 'db-fakedisplay', 'multi-lcd.html' ), loop_context_vars => 1, ); + my @results = get_results_for($station); + + if ( not @results ) { + $self->render( 'index', error => "Got no results for '$station'", ); + return; + } - for my $result ( get_results_for($station) ) { + for my $result (@results) { push( @params, { @@ -68,7 +74,7 @@ __DATA__ @@ index.html.ep % title 'DB Fakedisplay'; -<% if (my $error = flash 'error' ) { %> +<% if (my $error = stash 'error') { %> Error: <%= $error %>
<% } %> <%= form_for index => begin %> -- cgit v1.2.3