line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::EPLRenderer; |
2
|
48
|
|
|
48
|
|
413
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
48
|
|
|
|
|
120
|
|
|
48
|
|
|
|
|
342
|
|
3
|
|
|
|
|
|
|
|
4
|
48
|
|
|
48
|
|
390
|
use Mojo::Template; |
|
48
|
|
|
|
|
116
|
|
|
48
|
|
|
|
|
405
|
|
5
|
48
|
|
|
48
|
|
362
|
use Mojo::Util qw(encode md5_sum); |
|
48
|
|
|
|
|
128
|
|
|
48
|
|
|
|
|
33824
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub register { |
8
|
104
|
|
|
104
|
1
|
361
|
my ($self, $app) = @_; |
9
|
104
|
|
|
75
|
|
464
|
$app->renderer->add_handler(epl => sub { _render(@_, Mojo::Template->new, $_[1]) }); |
|
75
|
|
|
|
|
457
|
|
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _render { |
13
|
570
|
|
|
570
|
|
1824
|
my ($renderer, $c, $output, $options, $mt, @args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Cached |
16
|
570
|
100
|
|
|
|
1937
|
if ($mt->compiled) { |
17
|
163
|
|
|
|
|
573
|
$c->helpers->log->trace("Rendering cached @{[$mt->name]}"); |
|
163
|
|
|
|
|
571
|
|
18
|
163
|
|
|
|
|
1006
|
$$output = $mt->process(@args); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Not cached |
22
|
|
|
|
|
|
|
else { |
23
|
407
|
|
|
|
|
947
|
my $inline = $options->{inline}; |
24
|
407
|
100
|
|
|
|
1066
|
my $name = defined $inline ? md5_sum encode('UTF-8', $inline) : undef; |
25
|
407
|
50
|
66
|
|
|
1822
|
return unless defined($name //= $renderer->template_name($options)); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Inline |
28
|
407
|
100
|
|
|
|
1125
|
if (defined $inline) { |
29
|
24
|
|
|
|
|
94
|
$c->helpers->log->trace(qq{Rendering inline template "$name"}); |
30
|
24
|
|
|
|
|
198
|
$$output = $mt->name(qq{inline template "$name"})->render($inline, @args); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# File |
34
|
|
|
|
|
|
|
else { |
35
|
383
|
100
|
|
|
|
1048
|
if (my $encoding = $renderer->encoding) { $mt->encoding($encoding) } |
|
378
|
|
|
|
|
1276
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Try template |
38
|
383
|
100
|
|
|
|
1224
|
if (defined(my $path = $renderer->template_path($options))) { |
|
|
100
|
|
|
|
|
|
39
|
51
|
|
|
|
|
318
|
$c->helpers->log->trace(qq{Rendering template "$name"}); |
40
|
51
|
|
|
|
|
400
|
$$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
|
152
|
|
|
|
|
653
|
$c->helpers->log->trace(qq{Rendering template "$name" from DATA section}); |
46
|
152
|
|
|
|
|
1092
|
$$output = $mt->name(qq{template "$name" from DATA section})->render($d, @args); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# No template |
50
|
180
|
|
|
|
|
710
|
else { $c->helpers->log->trace(qq{Template "$name" not found}) } |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Exception |
55
|
570
|
100
|
|
|
|
4262
|
die $$output if ref $$output; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
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 is a renderer for C templates, which are pretty much just raw |
77
|
|
|
|
|
|
|
L. |
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 for a list of plugins that are available by default. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 METHODS |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
L inherits all methods from L and implements the following new |
87
|
|
|
|
|
|
|
ones. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 register |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$plugin->register(Mojolicious->new); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Register renderer in L application. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SEE ALSO |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
L, L, L. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |