| 1 | package Mojolicious::Plugin::HTMLTemplateProRenderer; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use HTML::Template::Pro; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use HTML::Template::Pro::Extension; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | sub register { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | my ( $self, $app, $conf ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | $self->{plugin_config} = $conf; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | ▶ | $app->renderer->add_handler( tmpl => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | my ($r, $c, $out, $opt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 16 | # Fallback to ep template if pages raise exceptions | ||||||||||||||||||||||||||||||||||||||||||
| 17 | return $r->handlers->{ep} | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | ▶ | if ($opt->{template} =~ /(exception)|(not_found)|(development)/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | $self->render_tmpl(@_) | |||||||||||||||||||||||||||||||||||||||||
| 20 | 4 | } ); | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | sub render_tmpl { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_tmpl: called CC=21 SCAR=56.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 7 | my ( $self, $r, $c, $output, $options ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | my $conf = $self->{plugin_config}; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 7 | my %tmpl_params = %{ $c->stash }; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | unshift @{ $r->paths }, $c->app->home | |||||||||||||||||||||||||||||||||||||||||
| 29 | if ( $conf->{tmpl_opts}->{use_home_template} | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | ▶ | || delete $tmpl_params{use_home_template} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$conf->{"tmpl_opts"}{"use_home_template"} or delete $tmpl_params{"use_home_template"}
MC/DC100%2/2
$conf->{"tmpl_opts"}{"use_home_template"} or delete $tmpl_params{"use_home_template"}
$conf->{"tmpl_opts"}{"use_home_template"}
delete $tmpl_params{"use_home_template"}
Truth table100%3/3
A or B
A= $conf->{"tmpl_opts"}{"use_home_template"}B= delete $tmpl_params{"use_home_template"}
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 7 | my $controller = $c->stash('controller'); | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 7 | my @template_dirs; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | push @template_dirs, $c->app->home->rel_dir('templates'); | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ($controller) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | push @template_dirs, $c->app->home->rel_dir("templates/$controller"); | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $t; | |||||||||||||||||||||||||||||||||||||||||
| 43 | my %t_options; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ( $conf->{tmpl_opts}->{use_extension} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$conf->{"tmpl_opts"}{"use_extension"} or delete $tmpl_params{"use_extension"}
MC/DC0%0/2
$conf->{"tmpl_opts"}{"use_extension"} or delete $tmpl_params{"use_extension"}
$conf->{"tmpl_opts"}{"use_extension"}
delete $tmpl_params{"use_extension"}
Truth table0%0/3
A or B
A= $conf->{"tmpl_opts"}{"use_extension"}B= delete $tmpl_params{"use_extension"}
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | || delete $tmpl_params{use_extension} ) | ||||||||||||||||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ( defined( $options->{inline} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $t_options{tmplfile} = \$options->{inline}; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | elsif ( defined( $options->{template} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ( defined( my $path = $r->template_path($options) ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $t_options{tmplfile} = $path; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $t_options{cache} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $t_options{tmplfile} = \$r->get_data_template($options); | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | my $plugins = $conf->{tmpl_opts}->{plugins} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$conf->{'tmpl_opts'}{'plugins'} || []
MC/DC0%0/1
$conf->{'tmpl_opts'}{'plugins'} || []
$conf->{'tmpl_opts'}{'plugins'}
Truth table0%0/2
A
A= $conf->{'tmpl_opts'}{'plugins'}
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $plugins = [ @$plugins, @{ $tmpl_params{plugins} } ] | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if exists $tmpl_params{plugins}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $t_options{plugins} = $plugins; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $t = new HTML::Template::Pro::Extension(%t_options); | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $t_options{die_on_bad_params} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $t_options{global_vars} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $t_options{loop_context_vars} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $t_options{path} = \@template_dirs; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $t_options{search_path_on_include} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ( defined( $options->{inline} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $t_options{scalarref} = \$options->{inline}; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | elsif ( defined( $options->{template} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ( defined( my $path = $r->template_path($options) ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $t_options{filename} = $path; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $t_options{cache} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $t_options{scalarref} = $r->get_data_template($options); | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | $t = HTML::Template::Pro->new( | ||||||||||||||||||||||||||||||||||||||||||
| 89 | %t_options, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | %{ $conf->{tmpl_opts} || {} }, | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$conf->{'tmpl_opts'} || {}
MC/DC0%0/1
$conf->{'tmpl_opts'} || {}
$conf->{'tmpl_opts'}
Truth table0%0/2
A
A= $conf->{'tmpl_opts'}
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | %{ delete $tmpl_params{tmpl_opts} || {} } | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $tmpl_params{'tmpl_opts'} || {}
MC/DC0%0/1
delete $tmpl_params{'tmpl_opts'} || {}
delete $tmpl_params{'tmpl_opts'}
Truth table0%0/2
A
A= delete $tmpl_params{'tmpl_opts'}
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | unless ($t) { $r->render_exception("ERROR: No template created"); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | # sanity params removing scalar inside arrayref | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | foreach ( keys %tmpl_params ) { | |||||||||||||||||||||||||||||||||||||||||
| 99 | delete $tmpl_params{$_} | ||||||||||||||||||||||||||||||||||||||||||
| 100 | if ( ( ref $tmpl_params{$_} eq 'ARRAY' ) | ||||||||||||||||||||||||||||||||||||||||||
| 101 | && $tmpl_params{$_} > 0 | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | && ref($tmpl_params{$_}->[0]) ne 'HASH' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $tmpl_params{$_} eq "ARRAY" and $tmpl_params{$_} > 0 and ref $tmpl_params{$_}[0] ne "HASH"
ref $tmpl_params{$_} eq "ARRAY" and $tmpl_params{$_} > 0
MC/DC0%0/3
ref $tmpl_params{$_} eq "ARRAY" and $tmpl_params{$_} > 0 and ref $tmpl_params{$_}[0] ne "HASH"
ref $tmpl_params{$_} eq "ARRAY"
$tmpl_params{$_} > 0
ref $tmpl_params{$_}[0] ne "HASH"
Truth table0%0/4
A and B and C
A= ref $tmpl_params{$_} eq "ARRAY"B= $tmpl_params{$_} > 0C= ref $tmpl_params{$_}[0] ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $t->param(%tmpl_params); | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $$output = $t->output(); | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 111 | __END__ | ||||||||||||||||||||||||||||||||||||||||||