summaryrefslogtreecommitdiff
path: root/index.pl
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-06-06 21:30:45 +0200
committerDaniel Friesel <derf@finalrewind.org>2015-06-06 21:30:45 +0200
commit13f462df94edcdb87058e4939181dc416f1a6c1a (patch)
tree00bc885e7afa04eb3eb3071c13bc10443d7f532c /index.pl
parent1725719f07c99e7de67fa6b2981d060c1a385d81 (diff)
make cache data easier to extend
Diffstat (limited to 'index.pl')
-rw-r--r--index.pl26
1 files changed, 17 insertions, 9 deletions
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('*');