File Coverage

script/remarkpl
Criterion Covered Total %
statement 13 13 100.0
branch 1 2 50.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 19 20 95.0


line stmt bran cond sub pod time code
1             #!/usr/bin/env perl
2 1     1   1019 use Mojolicious::Lite;
  1         62140  
  1         6  
3              
4 1     1   21165 use if -e 'lib/App/remarkpl', qw(lib lib);
  1         12  
  1         22  
5 1     1   1482 use App::remarkpl;
  1         3  
  1         27  
6 1     1   5 use Mojo::File qw(path);
  1         3  
  1         524  
7              
8             # Read in the presentation when running the script from command line,
9             # show the manual or an error message in case of an invalid file.
10             my $presentation = shift @ARGV || $ENV{REMARK_PRESENTATION} || 'example.markdown';
11             unless ($ENV{MOJO_APP_LOADER}) {
12             exec perldoc => -tT => $INC{'App/remarkpl.pm'} if $presentation =~ m!^-*(h|help|man)$!;
13             die qq(Cannot read presentation file "$presentation".\n)
14             unless $presentation eq 'example.markdown' or -r $presentation;
15             unshift @ARGV, 'daemon';
16             }
17              
18             $presentation = path $presentation;
19              
20             # Include static assets and templates
21             app->renderer->paths(
22             [split /:/, ($ENV{REMARK_TEMPLATES} // $presentation->sibling('templates')->to_abs)]);
23             app->static->paths([split /:/, ($ENV{REMARK_STATIC} // $presentation->dirname)]);
24             push @{app->static->paths},
25             path(path($INC{'App/remarkpl.pm'})->dirname, qw(remarkpl public))->to_abs;
26              
27             # Custom switch to show example presentation file
28             exit(print(read_presentation()) ? 0 : $!) if grep {/^--print/} @ARGV;
29              
30             app->log->info(qq(Looking for static files in ) . join ', ', @{app->static->paths});
31             app->log->info(qq(Looking for templates in ) . join ', ', @{app->renderer->paths});
32             app->log->info(qq(Serving presentation "$presentation"));
33              
34             get '/' => sub { shift->render(template => 'remarkpl', presentation => read_presentation()) };
35              
36             app->defaults(remarkjs => $ENV{REMARK_JS} || '/remark.min.js');
37             app->defaults(title => $presentation->basename);
38             app->start;
39              
40             sub read_presentation {
41 1 50   1   5 Mojo::Util::decode('UTF-8',
42             -e $presentation
43             ? $presentation->slurp
44             : Mojo::Loader::data_section(__PACKAGE__, $presentation));
45             }
46              
47             __DATA__