Loading bin/db-fakedisplay +43 −22 Original line number Diff line number Diff line Loading @@ -14,19 +14,25 @@ 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', 'single-lcd.html' ); $template_file //= dist_file( 'db-fakedisplay', 'multi-lcd.html' ); $template = HTML::Template->new( filename => $template_file ); if ( not defined $station ) { Loading Loading @@ -57,6 +63,25 @@ sub show_help { 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 ) { Loading @@ -73,23 +98,19 @@ for my $platform (@platforms) { if ( not defined $result ) { push( @params, { platform => $platform } ); next; } 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, else { add_result($result); } } } else { for my $result ( $status->results ) { add_result($result); } ); } $template->param( platform => \@params, ); $template->param( departures => \@params, ); say $template->output; Loading Loading @@ -137,9 +158,9 @@ Show version information. B<db-fakedisplay> uses HTML::Template(3pm) to create the display. In case you want to create a custom template, the following variables are available: =head2 platform =head2 departures This is a loop variable, use it with C<< <TMPL_LOOP platform> foo <TMPL_VAR This is a loop variable, use it with C<< <TMPL_LOOP departures> foo <TMPL_VAR bar> ... </TMPL_LOOP> >>. This loop runs once for each requested platform. Inside it, you can use the Loading share/single-lcd.html +1 −1 Original line number Diff line number Diff line Loading @@ -80,7 +80,7 @@ </head> <body> <TMPL_LOOP platform> <TMPL_LOOP departures> <div class="display"> <div class="platform"> Loading Loading
bin/db-fakedisplay +43 −22 Original line number Diff line number Diff line Loading @@ -14,19 +14,25 @@ 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', 'single-lcd.html' ); $template_file //= dist_file( 'db-fakedisplay', 'multi-lcd.html' ); $template = HTML::Template->new( filename => $template_file ); if ( not defined $station ) { Loading Loading @@ -57,6 +63,25 @@ sub show_help { 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 ) { Loading @@ -73,23 +98,19 @@ for my $platform (@platforms) { if ( not defined $result ) { push( @params, { platform => $platform } ); next; } 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, else { add_result($result); } } } else { for my $result ( $status->results ) { add_result($result); } ); } $template->param( platform => \@params, ); $template->param( departures => \@params, ); say $template->output; Loading Loading @@ -137,9 +158,9 @@ Show version information. B<db-fakedisplay> uses HTML::Template(3pm) to create the display. In case you want to create a custom template, the following variables are available: =head2 platform =head2 departures This is a loop variable, use it with C<< <TMPL_LOOP platform> foo <TMPL_VAR This is a loop variable, use it with C<< <TMPL_LOOP departures> foo <TMPL_VAR bar> ... </TMPL_LOOP> >>. This loop runs once for each requested platform. Inside it, you can use the Loading
share/single-lcd.html +1 −1 Original line number Diff line number Diff line Loading @@ -80,7 +80,7 @@ </head> <body> <TMPL_LOOP platform> <TMPL_LOOP departures> <div class="display"> <div class="platform"> Loading