line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::EPLRenderer; |
2
|
49
|
|
|
49
|
|
385
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
49
|
|
|
|
|
131
|
|
|
49
|
|
|
|
|
432
|
|
3
|
|
|
|
|
|
|
|
4
|
49
|
|
|
49
|
|
411
|
use Mojo::Template; |
|
49
|
|
|
|
|
133
|
|
|
49
|
|
|
|
|
551
|
|
5
|
49
|
|
|
49
|
|
392
|
use Mojo::Util qw(encode md5_sum); |
|
49
|
|
|
|
|
170
|
|
|
49
|
|
|
|
|
36333
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub register { |
8
|
105
|
|
|
105
|
1
|
441
|
my ($self, $app) = @_; |
9
|
105
|
|
|
75
|
|
523
|
$app->renderer->add_handler(epl => sub { _render(@_, Mojo::Template->new, $_[1]) }); |
|
75
|
|
|
|
|
484
|
|
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _render { |
13
|
584
|
|
|
584
|
|
1886
|
my ($renderer, $c, $output, $options, $mt, @args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Cached |
16
|
584
|
100
|
|
|
|
2040
|
if ($mt->compiled) { |
17
|
166
|
|
|
|
|
595
|
$c->helpers->log->trace("Rendering cached @{[$mt->name]}"); |
|
166
|
|
|
|
|
714
|
|
18
|
166
|
|
|
|
|
1088
|
$$output = $mt->process(@args); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Not cached |
22
|
|
|
|
|
|
|
else { |
23
|
418
|
|
|
|
|
1092
|
my $inline = $options->{inline}; |
24
|
418
|
100
|
|
|
|
1310
|
my $name = defined $inline ? md5_sum encode('UTF-8', $inline) : undef; |
25
|
418
|
50
|
66
|
|
|
1802
|
return unless defined($name //= $renderer->template_name($options)); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Inline |
28
|
418
|
100
|
|
|
|
1287
|
if (defined $inline) { |
29
|
24
|
|
|
|
|
104
|
$c->helpers->log->trace(qq{Rendering inline template "$name"}); |
30
|
24
|
|
|
|
|
259
|
$$output = $mt->name(qq{inline template "$name"})->render($inline, @args); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# File |
34
|
|
|
|
|
|
|
else { |
35
|
394
|
100
|
|
|
|
1157
|
if (my $encoding = $renderer->encoding) { $mt->encoding($encoding) } |
|
389
|
|
|
|
|
1370
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Try template |
38
|
394
|
100
|
|
|
|
1364
|
if (defined(my $path = $renderer->template_path($options))) { |
|
|
100
|
|
|
|
|
|
39
|
52
|
|
|
|
|
402
|
$c->helpers->log->trace(qq{Rendering template "$name"}); |
40
|
52
|
|
|
|
|
455
|
$$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
|
154
|
|
|
|
|
658
|
$c->helpers->log->trace(qq{Rendering template "$name" from DATA section}); |
46
|
154
|
|
|
|
|
5431
|
$$output = $mt->name(qq{template "$name" from DATA section})->render($d, @args); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# No template |
50
|
188
|
|
|
|
|
822
|
else { $c->helpers->log->trace(qq{Template "$name" not found}) } |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Exception |
55
|
584
|
100
|
|
|
|
4570
|
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 |