script/remarkpl

filter: Statementstmt 88.5% 31 / 35 Branchbran 25.0% 3 / 12 Conditioncond 31.2% 5 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 57.6% 45 / 78 CC 2 SCAR 2.8
CC
2
Cov
62%
read_presentation
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
↑ Summary lib/App/remarkpl.pm »
1 #!/usr/bin/env perl
2 1 ▶use Mojolicious::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use if -e 'lib/App/remarkpl', qw(lib lib);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use App::remarkpl;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Mojo::File qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
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 1 ▶my $presentation = shift @ARGV || $ENV{REMARK_PRESENTATION} || 'example.markdown';
Condition40%2/5
shift @ARGV || $ENV{'REMARK_PRESENTATION'} || 'example.markdown'
l!l
01
shift @ARGV or $ENV{"REMARK_PRESENTATION"}
l!l&&r!l&&!r
001
MC/DC0%0/2
shift @ARGV || $ENV{'REMARK_PRESENTATION'} || 'example.markdown'
shift @ARGV $ENV{"REMARK_PRESENTATION"}
Truth table33%1/3
A or B
A= shift @ARGVB= $ENV{"REMARK_PRESENTATION"}
ABresult
1X1
011
000
11 1 ▶unless ($ENV{MOJO_APP_LOADER}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"MOJO_APP_LOADER"}) 0 1 1
12 0 ▶ exec perldoc => -tT => $INC{'App/remarkpl.pm'} if $presentation =~ m!^-*(h|help|man)$!;
Branch: 1 branch
BranchTrueFalseTotal
if $presentation =~ /^-*(h|help|man)$/u 0 0 0
13 0 ▶ die qq(Cannot read presentation file "$presentation".\n)
Branch: 1 branch
BranchTrueFalseTotal
unless $presentation eq "example.markdown" or -r $presentation 0 0 0
Condition0%0/3
$presentation eq "example.markdown" or -r $presentation
l!l&&r!l&&!r
000
MC/DC0%0/2
$presentation eq "example.markdown" or -r $presentation
$presentation eq "example.markdown" -r $presentation
Truth table0%0/3
A or B
A= $presentation eq "example.markdown"B= -r $presentation
ABresult
1X1
011
000
14 unless $presentation eq 'example.markdown' or -r $presentation;
15 0 unshift @ARGV, 'daemon';
16 }
17  
18 1 $presentation = path $presentation;
19  
20 # Include static assets and templates
21 app->renderer->paths(
22 1 ▶ [split /:/, ($ENV{REMARK_TEMPLATES} // $presentation->sibling('templates')->to_abs)]);
Condition33%1/3
$ENV{"REMARK_TEMPLATES"} // $presentation->sibling("templates")->to_abs
l!l&&r!l&&!r
010
MC/DC0%0/2
$ENV{"REMARK_TEMPLATES"} // $presentation->sibling("templates")->to_abs
$ENV{"REMARK_TEMPLATES"} $presentation->sibling("templates")->to_abs
Truth table33%1/3
A // B
A= $ENV{"REMARK_TEMPLATES"}B= $presentation->sibling("templates")->to_abs
ABresult
1X1
011
000
23 1 ▶app->static->paths([split /:/, ($ENV{REMARK_STATIC} // $presentation->dirname)]);
Condition33%1/3
$ENV{"REMARK_STATIC"} // $presentation->dirname
l!l&&r!l&&!r
010
MC/DC0%0/2
$ENV{"REMARK_STATIC"} // $presentation->dirname
$ENV{"REMARK_STATIC"} $presentation->dirname
Truth table33%1/3
A // B
A= $ENV{"REMARK_STATIC"}B= $presentation->dirname
ABresult
1X1
011
000
24 1 push @{app->static->paths},
25 1 path(path($INC{'App/remarkpl.pm'})->dirname, qw(remarkpl public))->to_abs;
26  
27 # Custom switch to show example presentation file
28 0 ▶exit(print(read_presentation()) ? 0 : $!) if grep {/^--print/} @ARGV;
Branch: 2 branches
BranchTrueFalseTotal
if grep {/^--print/u;} @ARGV 0 1 1
print(read_presentation()) ? : 0 0 0
29  
30 1 app->log->info(qq(Looking for static files in ) . join ', ', @{app->static->paths});
31 1 app->log->info(qq(Looking for templates in ) . join ', ', @{app->renderer->paths});
32 1 app->log->info(qq(Serving presentation "$presentation"));
33  
34 1 ▶get '/' => sub { shift->render(template => 'remarkpl', presentation => read_presentation()) };
Subroutine __ANON__: called CC=1 SCAR=0.0
35  
36 1 ▶app->defaults(remarkjs => $ENV{REMARK_JS} || '/remark.min.js');
Condition50%1/2
$ENV{'REMARK_JS'} || '/remark.min.js'
l!l
01
MC/DC0%0/1
$ENV{'REMARK_JS'} || '/remark.min.js'
$ENV{'REMARK_JS'}
Truth table50%1/2
A
A= $ENV{'REMARK_JS'}
Aresult
11
00
37 1 app->defaults(title => $presentation->basename);
38 1 app->start;
39  
40 1 ▶sub read_presentation {
Subroutine read_presentation: called CC=2 SCAR=7.6
41 1 ▶ Mojo::Util::decode('UTF-8',
Branch: 1 branch
BranchTrueFalseTotal
-e $presentation ? : 0 1 1
42 -e $presentation
43 ? $presentation->slurp
44 : Mojo::Loader::data_section(__PACKAGE__, $presentation));
45 }
46  
47 __DATA__
↑ Summary lib/App/remarkpl.pm »