summaryrefslogtreecommitdiff
path: root/index.pl
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2014-10-11 21:05:28 +0200
committerDaniel Friesel <derf@finalrewind.org>2014-10-11 21:05:28 +0200
commit9b1de3c6e23ec7835b87d053ac98ea04a4b3dbf1 (patch)
treece606759da7ef96431774717dd236cca1c46d14b /index.pl
parent8dfc0c027758929345f428c3a24f1b9221f9c81e (diff)
add json output
Diffstat (limited to 'index.pl')
-rw-r--r--index.pl29
1 files changed, 20 insertions, 9 deletions
diff --git a/index.pl b/index.pl
index 83a3e30..ac5be2b 100644
--- a/index.pl
+++ b/index.pl
@@ -67,7 +67,7 @@ sub handle_request {
$self->stash( title => 'db-fakedisplay' );
$self->stash( version => $VERSION );
- if ( not( $template ~~ [qw[clean multi single]] ) ) {
+ if ( not( $template ~~ [qw[clean json multi single]] ) ) {
$template = 'multi';
}
@@ -194,14 +194,25 @@ sub handle_request {
);
}
- $self->render(
- $template,
- departures => \@departures,
- version => $VERSION,
- title => "departures for ${station}",
- refresh_interval => $refresh_interval + 3,
- hide_opts => $hide_opts,
- );
+ if ( $template eq 'json' ) {
+ $self->render(
+ json => {
+ preformatted => \@departures,
+ version => $VERSION,
+ raw => \@results,
+ }
+ );
+ }
+ else {
+ $self->render(
+ $template,
+ departures => \@departures,
+ version => $VERSION,
+ title => "departures for ${station}",
+ refresh_interval => $refresh_interval + 3,
+ hide_opts => $hide_opts,
+ );
+ }
}
get '/_redirect' => sub {