line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::EPRenderer; |
2
|
49
|
|
|
203
|
|
406
|
use Mojo::Base 'Mojolicious::Plugin::EPLRenderer'; |
|
49
|
|
|
|
|
127
|
|
|
49
|
|
|
|
|
412
|
|
3
|
|
|
|
|
|
|
|
4
|
49
|
|
|
179
|
|
412
|
use Mojo::Template; |
|
49
|
|
|
|
|
124
|
|
|
49
|
|
|
|
|
324
|
|
5
|
49
|
|
|
179
|
|
296
|
use Mojo::Util qw(encode md5_sum monkey_patch); |
|
49
|
|
|
|
|
147
|
|
|
49
|
|
|
|
|
18882
|
|
6
|
|
|
|
|
|
|
|
7
|
38
|
|
|
168
|
|
5923
|
sub DESTROY { Mojo::Util::_teardown(shift->{namespace}) } |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub register { |
10
|
106
|
|
|
236
|
1
|
468
|
my ($self, $app, $conf) = @_; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Auto escape by default to prevent XSS attacks |
13
|
106
|
|
100
|
|
|
279
|
my $ep = {auto_escape => 1, %{$conf->{template} // {}}, vars => 1}; |
|
106
|
|
|
|
|
1016
|
|
14
|
106
|
|
66
|
|
|
1568
|
my $ns = $self->{namespace} = $ep->{namespace} //= 'Mojo::Template::Sandbox::' . md5_sum "$self"; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Make "$self" and "$c" available in templates |
17
|
106
|
|
100
|
|
|
769
|
$ep->{prepend} = 'my $self = my $c = _C;' . ($ep->{prepend} // ''); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Add "ep" handler and make it the default |
20
|
|
|
|
|
|
|
$app->renderer->default_handler('ep')->add_handler( |
21
|
|
|
|
|
|
|
$conf->{name} || 'ep' => sub { |
22
|
509
|
|
|
639
|
|
1326
|
my ($renderer, $c, $output, $options) = @_; |
23
|
|
|
|
|
|
|
|
24
|
509
|
|
66
|
|
|
2021
|
my $name = $options->{inline} // $renderer->template_name($options); |
25
|
509
|
50
|
|
|
|
1505
|
return unless defined $name; |
26
|
509
|
|
|
|
|
1645
|
my $key = md5_sum encode 'UTF-8', $name; |
27
|
|
|
|
|
|
|
|
28
|
509
|
|
|
|
|
2355
|
my $cache = $renderer->cache; |
29
|
509
|
|
|
|
|
1777
|
my $mt = $cache->get($key); |
30
|
509
|
100
|
|
|
|
2840
|
$cache->set($key => $mt = Mojo::Template->new($ep)) unless $mt; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Export helpers only once |
33
|
509
|
100
|
33
|
|
|
2188
|
++$self->{helpers} and _helpers($ns, $renderer->helpers) unless $self->{helpers}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Make current controller available and render with "epl" handler |
36
|
49
|
|
|
179
|
|
450
|
no strict 'refs'; |
|
49
|
|
|
|
|
152
|
|
|
49
|
|
|
|
|
2402
|
|
37
|
49
|
|
|
179
|
|
400
|
no warnings 'redefine'; |
|
49
|
|
|
|
|
149
|
|
|
49
|
|
|
|
|
20827
|
|
38
|
509
|
|
|
|
|
2453
|
local *{"${ns}::_C"} = sub {$c}; |
|
509
|
|
|
|
|
3292
|
|
|
2558
|
|
|
|
|
10117
|
|
39
|
509
|
|
|
|
|
1988
|
Mojolicious::Plugin::EPLRenderer::_render($renderer, $c, $output, $options, $mt, $c->stash); |
40
|
|
|
|
|
|
|
} |
41
|
106
|
|
100
|
|
|
429
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _helpers { |
45
|
39
|
|
|
169
|
|
183
|
my ($class, $helpers) = @_; |
46
|
39
|
|
|
|
|
968
|
for my $method (grep {/^\w+$/} keys %$helpers) { |
|
3419
|
|
|
|
|
7293
|
|
47
|
2638
|
|
|
|
|
5562
|
my $sub = $helpers->{$method}; |
48
|
2638
|
|
|
2368
|
|
11819
|
monkey_patch $class, $method, sub { $class->_C->$sub(@_) }; |
|
2238
|
|
|
2207
|
|
22263
|
|
|
|
|
|
2207
|
|
|
|
|
|
|
|
2361
|
|
|
|
|
|
|
|
2491
|
|
|
|
|
|
|
|
2621
|
|
|
|
|
|
|
|
2751
|
|
|
|
|
|
|
|
2881
|
|
|
|
|
|
|
|
3011
|
|
|
|
|
|
|
|
3141
|
|
|
|
|
|
|
|
3271
|
|
|
|
|
|
|
|
3401
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3561
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3661
|
|
|
|
|
|
|
|
3661
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3709
|
|
|
|
|
|
|
|
3709
|
|
|
|
|
|
|
|
3687
|
|
|
|
|
|
|
|
3661
|
|
|
|
|
|
|
|
3661
|
|
|
|
|
|
|
|
3661
|
|
|
|
|
|
|
|
3661
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
|
1354
|
|
|
|
|
|
|
|
1170
|
|
|
|
|
|
|
|
1040
|
|
|
|
|
|
|
|
910
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
893
|
|
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=encoding utf8 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 NAME |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Mojolicious::Plugin::EPRenderer - Embedded Perl renderer plugin |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 SYNOPSIS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Mojolicious |
63
|
|
|
|
|
|
|
$app->plugin('EPRenderer'); |
64
|
|
|
|
|
|
|
$app->plugin(EPRenderer => {name => 'foo'}); |
65
|
|
|
|
|
|
|
$app->plugin(EPRenderer => {name => 'bar', template => {line_start => '.'}}); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Mojolicious::Lite |
68
|
|
|
|
|
|
|
plugin 'EPRenderer'; |
69
|
|
|
|
|
|
|
plugin EPRenderer => {name => 'foo'}; |
70
|
|
|
|
|
|
|
plugin EPRenderer => {name => 'bar', template => {line_start => '.'}}; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 DESCRIPTION |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
L is a renderer for Embedded Perl templates. For more information see |
75
|
|
|
|
|
|
|
L. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This is a core plugin, that means it is always enabled and its code a good example for learning to build new plugins, |
78
|
|
|
|
|
|
|
you're welcome to fork it. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
See L for a list of plugins that are available by default. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 OPTIONS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
L supports the following options. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 name |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Mojolicious::Lite |
89
|
|
|
|
|
|
|
plugin EPRenderer => {name => 'foo'}; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Handler name, defaults to C. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 template |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# Mojolicious::Lite |
96
|
|
|
|
|
|
|
plugin EPRenderer => {template => {line_start => '.'}}; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Attribute values passed to L objects used to render templates. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 METHODS |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
L inherits all methods from L and implements the |
103
|
|
|
|
|
|
|
following new ones. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 register |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
$plugin->register(Mojolicious->new); |
108
|
|
|
|
|
|
|
$plugin->register(Mojolicious->new, {name => 'foo'}); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Register renderer in L application. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 SEE ALSO |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L, L, L. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |