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