| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::ToolkitRenderer; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Template Toolkit Renderer Mojolicious Plugin |
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
699
|
use 5.010; |
|
|
1
|
|
|
|
|
7
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
18
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
22
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
9
|
1
|
|
|
1
|
|
193
|
use Mojo::Exception; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
81
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
BEGIN { |
|
12
|
1
|
|
|
1
|
|
6
|
local $SIG{__WARN__} = sub {}; |
|
13
|
1
|
|
|
|
|
890
|
require Template; |
|
14
|
1
|
|
|
|
|
16490
|
Template->import; |
|
15
|
|
|
|
|
|
|
} |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '1.11'; # VERSION |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub register { |
|
20
|
1
|
|
|
1
|
1
|
68
|
my ( $self, $app, $settings ) = @_; |
|
21
|
|
|
|
|
|
|
|
|
22
|
1
|
|
50
|
|
|
6
|
$settings->{config}{RELATIVE} //= 1; |
|
23
|
1
|
|
50
|
|
|
4
|
$settings->{config}{EVAL_PERL} //= 0; |
|
24
|
1
|
|
33
|
|
|
11
|
$settings->{config}{INCLUDE_PATH} //= $app->renderer->paths; |
|
25
|
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
26
|
my $template = Template->new( $settings->{config} ); |
|
27
|
|
|
|
|
|
|
|
|
28
|
1
|
50
|
|
|
|
22251
|
$settings->{context}->( $template->context ) if ( $settings->{context} ); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$app->renderer->add_handler( tt => sub { |
|
31
|
1
|
|
|
1
|
|
179
|
my ( $renderer, $controller, $output, $options ) = @_; |
|
32
|
1
|
|
50
|
|
|
7
|
my $inline = $settings->{settings}{inline_template} || 'inline'; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$template->process( |
|
35
|
|
|
|
|
|
|
( ( $options->{$inline} ) ? \$options->{$inline} : $renderer->template_name($options) ), |
|
36
|
|
|
|
|
|
|
{ |
|
37
|
|
|
|
|
|
|
content => $controller->content, |
|
38
|
1
|
|
|
|
|
43
|
%{ $controller->stash }, |
|
39
|
|
|
|
|
|
|
( $settings->{settings}{controller} || 'c' ) => $controller, |
|
40
|
|
|
|
|
|
|
}, |
|
41
|
|
|
|
|
|
|
$output, |
|
42
|
1
|
50
|
50
|
|
|
10
|
) || do { |
|
|
|
50
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
0
|
if ( ref( $settings->{settings}{error_handler} ) eq 'CODE' ) { |
|
44
|
0
|
|
|
|
|
0
|
$settings->{settings}{error_handler}->( $controller, $renderer, $app, $template ); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
else { |
|
47
|
0
|
0
|
0
|
|
|
0
|
unless ( |
|
|
|
|
0
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$template->error and ( |
|
49
|
|
|
|
|
|
|
$template->error eq 'file error - exception.html.tt: not found' or |
|
50
|
|
|
|
|
|
|
$template->error eq 'file error - exception.' . $app->mode . '.html.tt: not found' |
|
51
|
|
|
|
|
|
|
) |
|
52
|
|
|
|
|
|
|
) { |
|
53
|
0
|
|
|
|
|
0
|
$$output = $template->error; |
|
54
|
0
|
|
|
|
|
0
|
$controller->res->headers->content_type('text/plain'); |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
$controller->log->error( $template->error ); |
|
57
|
0
|
0
|
0
|
|
|
0
|
$controller->rendered( |
|
58
|
|
|
|
|
|
|
( $template->error and $template->error =~ /not found/ ) ? 404 : 500 |
|
59
|
|
|
|
|
|
|
); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
}; |
|
63
|
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
26572
|
return $$output; |
|
65
|
1
|
|
|
|
|
42
|
} ); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$app->helper( |
|
68
|
|
|
|
|
|
|
render_tt => sub { |
|
69
|
1
|
|
|
1
|
|
19106
|
shift->render( handler => 'tt', @_ ); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
1
|
|
|
|
|
35
|
); |
|
72
|
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
131
|
return; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |