summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cgi/index.pl24
1 files changed, 15 insertions, 9 deletions
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 %><br/>
<% } %>
<%= form_for index => begin %>