Mojolicious/Plugin/EPLRenderer.pm

filter: Statementstmt 100% 33 / 33 Branchbran 87.5% 14 / 16 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 91.8% 56 / 61 CC 10 SCAR 19.5
CC
10
Cov
94%
_render
10.0
BEGIN
1.0
BEGIN
1.0
CRAP 7.0
« Mojo/Transaction/HTTP.pm ↑ Summary Mojo/JSON.pm »
1 package Mojolicious::Plugin::EPLRenderer;
2 18 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 18 ▶use Mojo::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 18 ▶use Mojo::Util qw(encode md5_sum);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 83 ▶sub register {
Subroutine register: called CC=1 SCAR=0.0
Pod documented
8 83 my ($self, $app) = @_;
9 83 ▶ $app->renderer->add_handler(epl => sub { _render(@_, Mojo::Template->new, $_[1]) });
Subroutine __ANON__: called CC=1 SCAR=0.0
10 }
11  
12 150 ▶sub _render {
Subroutine _render: called CC=10 SCAR=23.1
13 150 my ($renderer, $c, $output, $options, $mt, @args) = @_;
14  
15 # Cached
16 150 ▶ if ($mt->compiled) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mt->compiled) { } 25 125 150
17 25 $c->helpers->log->trace("Rendering cached @{[$mt->name]}");
18 25 $$output = $mt->process(@args);
19 }
20  
21 # Not cached
22 else {
23 125 my $inline = $options->{inline};
24 125 ▶ my $name = defined $inline ? md5_sum encode('UTF-8', $inline) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $inline ? : 4 121 125
25 125 ▶ return unless defined($name //= $renderer->template_name($options));
Branch: 1 branch
BranchTrueFalseTotal
unless defined($name //= $renderer->template_name($options)) 0 125 125
Condition66%2/3
$name //= $renderer->template_name($options)
l!l&&r!l&&!r
41210
MC/DC0%0/2
$name //= $renderer->template_name($options)
$name $renderer->template_name($options)
Truth table66%2/3
A //= B
A= $nameB= $renderer->template_name($options)
ABresult
1X1
011
000
26  
27 # Inline
28 125 ▶ if (defined $inline) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $inline) { } 4 121 125
29 4 $c->helpers->log->trace(qq{Rendering inline template "$name"});
30 4 $$output = $mt->name(qq{inline template "$name"})->render($inline, @args);
31 }
32  
33 # File
34 else {
35 121 ▶ if (my $encoding = $renderer->encoding) { $mt->encoding($encoding) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $encoding = $renderer->encoding) 121 0 121
36  
37 # Try template
38 121 ▶ if (defined(my $path = $renderer->template_path($options))) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $path = $renderer->template_path($options))) { } 51 70 121
elsif (defined(my $d = $renderer->get_data_template($options))) { } 10 60 70
39 51 $c->helpers->log->trace(qq{Rendering template "$name"});
40 51 $$output = $mt->name(qq{template "$name"})->render_file($path, @args);
41 }
42  
43 # Try DATA section
44 elsif (defined(my $d = $renderer->get_data_template($options))) {
45 10 $c->helpers->log->trace(qq{Rendering template "$name" from DATA section});
46 10 $$output = $mt->name(qq{template "$name" from DATA section})->render($d, @args);
47 }
48  
49 # No template
50 60 else { $c->helpers->log->trace(qq{Template "$name" not found}) }
51 }
52 }
53  
54 # Exception
55 150 ▶ die $$output if ref $$output;
Branch: 1 branch
BranchTrueFalseTotal
if ref $$output 3 147 150
56 }
57  
58 18 1;
59  
60 =encoding utf8
61  
62 =head1 NAME
63  
64 Mojolicious::Plugin::EPLRenderer - Embedded Perl Lite renderer plugin
65  
66 =head1 SYNOPSIS
67  
68 # Mojolicious
69 $app->plugin('EPLRenderer');
70  
71 # Mojolicious::Lite
72 plugin 'EPLRenderer';
73  
74 =head1 DESCRIPTION
75  
76 L<Mojolicious::Plugin::EPLRenderer> is a renderer for C<epl> templates, which are pretty much just raw
77 L<Mojo::Template>.
78  
79 This is a core plugin, that means it is always enabled and its code a good example for learning to build new plugins,
80 you're welcome to fork it.
81  
82 See L<Mojolicious::Plugins/"PLUGINS"> for a list of plugins that are available by default.
83  
84 =head1 METHODS
85  
86 L<Mojolicious::Plugin::EPLRenderer> inherits all methods from L<Mojolicious::Plugin> and implements the following new
87 ones.
88  
89 =head2 register
90  
91 $plugin->register(Mojolicious->new);
92  
93 Register renderer in L<Mojolicious> application.
94  
95 =head1 SEE ALSO
96  
97 L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
98  
99 =cut
« Mojo/Transaction/HTTP.pm ↑ Summary Mojo/JSON.pm »