summaryrefslogtreecommitdiff
path: root/cgi/index.pl
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-07-22 13:25:19 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-07-22 13:25:19 +0200
commitb25d3239cffb6ddc6810d3b61ada6b0e46502d44 (patch)
tree1f6f014fe9d43d55a744c1d8d2d5e9c5bd67319c /cgi/index.pl
parent89526fb1e996ccc9710af9c1268eaf4359c4bc2a (diff)
Add first try at CGI version
Diffstat (limited to 'cgi/index.pl')
-rw-r--r--cgi/index.pl58
1 files changed, 58 insertions, 0 deletions
diff --git a/cgi/index.pl b/cgi/index.pl
new file mode 100644
index 0000000..cbc2f0b
--- /dev/null
+++ b/cgi/index.pl
@@ -0,0 +1,58 @@
+#!/usr/bin/env perl
+use Mojolicious::Lite;
+use File::ShareDir qw(dist_file);
+use HTML::Template;
+use Travel::Status::DE::DeutscheBahn;
+
+get '/' => sub {
+ my $self = shift;
+ my $station = $self->param('station');
+ if ( not $station ) {
+ return $self->render;
+ }
+ $self->redirect_to("/multi/${station}");
+} => 'index';
+
+get '/multi/:station' => sub {
+ my $self = shift;
+ my $station = $self->stash('station');
+
+ my @params;
+ my $status = Travel::Status::DE::DeutscheBahn->new( station => $station );
+ my $template = HTML::Template->new(
+ filename => dist_file( 'db-fakedisplay', 'multi-lcd.html' ),
+ loop_context_vars => 1,
+ );
+
+ for my $result ( $status->results ) {
+ push(
+ @params,
+ {
+ time => $result->time,
+ train => $result->train,
+ via => [ map { { stop => $_ } } $result->route_interesting(3) ],
+ destination => $result->destination,
+ platform => ( split( / /, $result->platform ) )[0],
+ info => $result->info,
+ }
+ );
+ }
+ $template->param( departures => \@params );
+
+ $self->render( text => $template->output );
+};
+
+app->start();
+
+__DATA__
+
+@@ index.html.ep
+% title 'DB Fakedisplay';
+<% if (my $error = flash 'error' ) { %>
+ Error: <%= $error %><br/>
+<% } %>
+<%= form_for index => begin %>
+ Stop:<br/>
+ <%= text_field 'station' %><br/>
+ <%= submit_button 'Display' %>
+<% end %>