From 224bdfc68ee626995dbfec357be1268177d02cc9 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 19 Aug 2011 01:00:47 +0200 Subject: Remove script, convert template from HTML::Template to Mojolicious .ep template --- Build.PL | 25 ------ README | 13 +-- bin/db-fakedisplay | 246 ----------------------------------------------------- cgi/index.pl | 175 +++++++++++++++++++++++++++++++++---- 4 files changed, 160 insertions(+), 299 deletions(-) delete mode 100755 Build.PL delete mode 100755 bin/db-fakedisplay diff --git a/Build.PL b/Build.PL deleted file mode 100755 index 747146d..0000000 --- a/Build.PL +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; -use Module::Build; - -Module::Build->new( - - build_requires => { - 'Module::Build' => '0.36', - }, - dist_name => 'db-fakedisplay', - dist_version_from => 'bin/db-fakedisplay', - license => 'unrestricted', - requires => { - 'perl' => '5.10.0', - 'File::ShareDir' => 0, - 'HTML::Template' => 0, - 'List::Util' => 0, - 'Travel::Status::DE::DeutscheBahn' => '0.04', - }, - share_dir => 'share', - sign => 1, - -)->create_build_script(); diff --git a/README b/README index 9ca21a4..a42bcd0 100644 --- a/README +++ b/README @@ -7,16 +7,5 @@ Dependencies ------------ * perl >= 5.10 - * File::ShareDir - * Module::Build >= 0.36 - * HTML::Template + * Mojolicious * Travel::Status::DE::DeutscheBahn >= 0.04 - -Installation ------------- - -$ perl Build.PL -$ perl Build -$ sudo perl Build install - -You can then run 'man db-fakedisplay' for more information diff --git a/bin/db-fakedisplay b/bin/db-fakedisplay deleted file mode 100755 index 3a3b0f9..0000000 --- a/bin/db-fakedisplay +++ /dev/null @@ -1,246 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; -use 5.010; - -use File::ShareDir qw(dist_file); -use Getopt::Long qw(:config no_ignore_case); -use HTML::Template; -use List::Util qw(first); -use Travel::Status::DE::DeutscheBahn; - -our $VERSION = '0.00'; - -my @params; -my ( $station, @platforms ); -my $mode = 'single'; -my $template_file; -my $template; - -GetOptions( - - 'h|help' => sub { show_help(0) }, - 'm|mode=s' => \$mode, - 't|template=s' => \&handle_template, - 'V|version' => sub { say "db-fakedisplay version ${VERSION}"; exit 0 }, - -) or show_help(1); - -if ( $mode eq 'single' and not $template_file ) { - $template_file = dist_file( 'db-fakedisplay', 'single-lcd.html' ); -} - -( $station, @platforms ) = @ARGV; -$template_file //= dist_file( 'db-fakedisplay', 'multi-lcd.html' ); -$template = HTML::Template->new( - filename => $template_file, - loop_context_vars => 1 -); - -if ( not defined $station ) { - show_help(1); -} - -my $status = Travel::Status::DE::DeutscheBahn->new( station => $station ); - -sub handle_template { - my ( undef, $template_name ) = @_; - - if ( -e $template_name ) { - $template_file = $template_name; - } - else { - $template_file = dist_file( 'db-fakedisplay', $template_name ); - } - - return; -} - -sub show_help { - my ($exit_status) = @_; - - say 'Usage: db-fakedisplay [-t template] [platforms ...]'; - say 'See also: man db-fakedisplay'; - - exit $exit_status; -} - -sub add_result { - my ($result) = @_; - - 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, - } - ); - - return; -} - -if ( $mode eq 'single' ) { - if ( not @platforms ) { - for my $result ( $status->results ) { - if ( $result->platform ~~ \@platforms ) { - next; - } - push( @platforms, $result->platform ); - } - @platforms = sort { $a <=> $b } @platforms; - } - - for my $platform (@platforms) { - my $result = first { $_->platform =~ m{ ^ $platform (?: \s | $ )}x } - $status->results; - - if ( not defined $result ) { - push( @params, { platform => $platform } ); - } - else { - add_result($result); - } - } -} -else { - for my $result ( $status->results ) { - add_result($result); - } -} - -$template->param( - departures => \@params, - version => $VERSION -); - -say $template->output; - -__END__ - -=head1 NAME - -db-fakedisplay - Show train departures, as seen on the displays on most main stations - -=head1 SYNOPSIS - -B [-t I