diff options
author | Daniel Friesel <derf@finalrewind.org> | 2014-10-11 21:05:28 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2014-10-11 21:05:28 +0200 |
commit | 9b1de3c6e23ec7835b87d053ac98ea04a4b3dbf1 (patch) | |
tree | ce606759da7ef96431774717dd236cca1c46d14b /index.pl | |
parent | 8dfc0c027758929345f428c3a24f1b9221f9c81e (diff) |
add json output
Diffstat (limited to 'index.pl')
-rw-r--r-- | index.pl | 29 |
1 files changed, 20 insertions, 9 deletions
@@ -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 { |