| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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'} || {}
MC/DC0%0/1
$conf->{'tmpl_new_opts'} || {}
$conf->{'tmpl_new_opts'}
Truth table0%0/2
A
A= $conf->{'tmpl_new_opts'}
| |||||||||||||||
| 46 | 0 | ▶ | %{delete $tmpl_params{tmpl_new_opts} || {}}); | ||||||||||||
|
Condition0%0/2
delete $tmpl_params{'tmpl_new_opts'} || {}
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'}
| |||||||||||||||
| 47 | |||||||||||||||
| 48 | 0 | ▶ | unless($t) { $r->render_exception("ERROR: No template created"); } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | |||||||||||||||
| 50 | 0 | $t->param(%tmpl_params); | |||||||||||||
| 51 | |||||||||||||||
| 52 | 0 | $$output = $t->output(); | |||||||||||||
| 53 | } | ||||||||||||||
| 54 | 1 | ); | |||||||||||||
| 55 | } | ||||||||||||||
| 56 | |||||||||||||||
| 57 | 1 | 1; | |||||||||||||
| 58 | __END__ | ||||||||||||||