blib/lib/Mojolicious/Plugin/HTMLTemplateRenderer.pm

filter: Statementstmt 41.6% 15 / 36 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 36.3% 20 / 55 CC 7 SCAR 33.2
CC
7
Cov
31%
__ANON__
39.1
register
1.6
BEGIN
1.0
CRAP 27.7
↑ Summary
1 package Mojolicious::Plugin::HTMLTemplateRenderer;
2  
3 1 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use HTML::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.04';
8  
9 1 ▶sub register {
Subroutine register: called CC=1 SCAR=4.5
Pod documented
10 1 my ($self, $app, $conf) = @_;
11  
12 $app->renderer->add_handler(
13 3 ▶ tmpl => sub {
Subroutine __ANON__: called CC=7 SCAR=36.7
14 3 my ($r, $c, $output, $options) = @_;
15  
16 3 my $path = $r->template_path($options);
17 3 my $controller = $c->stash('controller');
18  
19 3 my @template_dirs;
20  
21 3 push @template_dirs, $c->app->home->rel_dir('templates');
22  
23 0 ▶ if($controller) {
Branch: 1 branch
BranchTrueFalseTotal
if ($controller) 0 0 0
24 0 push @template_dirs, $c->app->home->rel_dir("templates/$controller");
25 }
26  
27 0 my %t_options;
28  
29 0 $t_options{die_on_bad_params} = 0;
30 0 $t_options{global_vars} = 1;
31 0 $t_options{loop_context_vars} = 1;
32 0 $t_options{path} = \@template_dirs;
33 0 $t_options{search_path_on_include} = 1;
34  
35 0 ▶ if(defined($options->{inline})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $options->{'inline'}) { } 0 0 0
elsif (defined $options->{'template'}) { } 0 0 0
36 0 $t_options{scalarref} = \$options->{inline};
37 } elsif(defined($options->{template})) {
38 0 $t_options{filename} = $path;
39 0 $t_options{cache} = 1;
40 }
41  
42 0 my %tmpl_params = %{$c->stash};
43  
44 my $t = HTML::Template->new(%t_options,
45 0 ▶ %{$conf->{tmpl_new_opts} || {}},
Condition0%0/2
$conf->{'tmpl_new_opts'} || {}
l!l
00
MC/DC0%0/1
$conf->{'tmpl_new_opts'} || {}
$conf->{'tmpl_new_opts'}
Truth table0%0/2
A
A= $conf->{'tmpl_new_opts'}
Aresult
11
00
46 0 ▶ %{delete $tmpl_params{tmpl_new_opts} || {}});
Condition0%0/2
delete $tmpl_params{'tmpl_new_opts'} || {}
l!l
00
MC/DC0%0/1
delete $tmpl_params{'tmpl_new_opts'} || {}
delete $tmpl_params{'tmpl_new_opts'}
Truth table0%0/2
A
A= delete $tmpl_params{'tmpl_new_opts'}
Aresult
11
00
47  
48 0 ▶ unless($t) { $r->render_exception("ERROR: No template created"); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($t) 0 0 0
49  
50 0 $t->param(%tmpl_params);
51  
52 0 $$output = $t->output();
53 }
54 1 );
55 }
56  
57 1 1;
58 __END__
↑ Summary