From 13f462df94edcdb87058e4939181dc416f1a6c1a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 6 Jun 2015 21:30:45 +0200 Subject: make cache data easier to extend --- index.pl | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'index.pl') diff --git a/index.pl b/index.pl index b1c61dd..a835c69 100644 --- a/index.pl +++ b/index.pl @@ -30,9 +30,9 @@ sub get_results_for { my $cache_str = "${backend}_${cstation}"; - my $results = $cache->thaw($cache_str); + my $data = $cache->thaw($cache_str); - if ( not $results ) { + if ( not $data ) { if ( $backend eq 'iris' ) { # requests with DS100 codes should be preferred (they avoid @@ -49,20 +49,26 @@ sub get_results_for { serializable => 1, %opt ); - $results = [ [ $status->results ], $status->errstr ]; - $cache->freeze( $cache_str, $results ); + $data = { + results => [ $status->results ], + errstr => $status->errstr, + }; + $cache->freeze( $cache_str, $data ); } else { my $status = Travel::Status::DE::DeutscheBahn->new( station => $station, %opt ); - $results = [ [ $status->results ], $status->errstr ]; - $cache->freeze( $cache_str, $results ); + $data = { + results => [ $status->results ], + errstr => $status->errstr, + }; + $cache->freeze( $cache_str, $data ); } } - return @{$results}; + return $data; } helper 'is_important' => sub { @@ -182,8 +188,10 @@ sub handle_request { } my @departures; - my ( $results_ref, $errstr ) = get_results_for( $backend, $station, %opt ); - my @results = @{$results_ref}; + my $data = get_results_for( $backend, $station, %opt ); + my $results_ref = $data->{results}; + my $errstr = $data->{errstr}; + my @results = @{$results_ref}; if ( not @results and $template ~~ [qw[json marudor_v1 marudor]] ) { $self->res->headers->access_control_allow_origin('*'); -- cgit v1.2.3