line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::Renderer::Xslate; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
66825
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
87
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
71
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
21
|
use File::Spec (); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
76
|
|
7
|
3
|
|
|
3
|
|
502
|
use Mojo::Base -base; |
|
3
|
|
|
|
|
212552
|
|
|
3
|
|
|
|
|
22
|
|
8
|
3
|
|
|
3
|
|
1115
|
use Mojo::Loader qw(data_section); |
|
3
|
|
|
|
|
26717
|
|
|
3
|
|
|
|
|
168
|
|
9
|
3
|
|
|
3
|
|
1770
|
use Text::Xslate (); |
|
3
|
|
|
|
|
36935
|
|
|
3
|
|
|
|
|
2438
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.14'; |
12
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'xslate'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub build { |
17
|
3
|
|
|
3
|
1
|
54
|
my $self = shift->SUPER::new(@_); |
18
|
3
|
|
|
|
|
32
|
$self->_init(@_); |
19
|
3
|
|
|
21
|
|
16
|
return sub { $self->_render(@_) }; |
|
21
|
|
|
|
|
395898
|
|
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _init { |
23
|
3
|
|
|
3
|
|
8
|
my ($self, %args) = @_; |
24
|
|
|
|
|
|
|
|
25
|
3
|
|
66
|
|
|
17
|
my $app = $args{mojo} || $args{app}; |
26
|
3
|
|
|
|
|
5
|
my $cache_dir; |
27
|
3
|
|
|
|
|
18
|
my @path = $app->home->rel_file('templates'); |
28
|
|
|
|
|
|
|
|
29
|
3
|
50
|
|
|
|
188
|
if ($app) { |
30
|
3
|
|
|
|
|
21
|
$cache_dir = $app->home->rel_file('tmp/compiled_templates'); |
31
|
3
|
|
|
|
|
73
|
push @path, data_section( |
32
|
|
|
|
|
|
|
$app->renderer->classes->[0], |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
0
|
|
|
|
|
0
|
$cache_dir = File::Spec->tmpdir; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my %config = ( |
40
|
|
|
|
|
|
|
cache_dir => $cache_dir, |
41
|
|
|
|
|
|
|
path => \@path, |
42
|
|
|
|
2
|
|
|
warn_handler => sub { }, |
43
|
|
|
|
2
|
|
|
die_handler => sub { }, |
44
|
3
|
100
|
|
|
|
448
|
%{$args{template_options} || {}}, |
|
3
|
|
|
|
|
27
|
|
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
3
|
|
|
|
|
19
|
$self->xslate(Text::Xslate->new(\%config)); |
48
|
|
|
|
|
|
|
|
49
|
3
|
|
|
|
|
771
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _render { |
53
|
21
|
|
|
21
|
|
64
|
my ($self, $renderer, $c, $output, $options) = @_; |
54
|
|
|
|
|
|
|
|
55
|
21
|
|
33
|
|
|
65
|
my $name = $c->stash->{'template_name'} |
56
|
|
|
|
|
|
|
|| $renderer->template_name($options); |
57
|
21
|
|
|
|
|
511
|
my %params = (%{$c->stash}, c => $c); |
|
21
|
|
|
|
|
62
|
|
58
|
|
|
|
|
|
|
|
59
|
21
|
|
|
|
|
238
|
my $orig_err = $@; |
60
|
21
|
|
|
|
|
38
|
my $xslate_err; |
61
|
|
|
|
|
|
|
|
62
|
21
|
|
|
|
|
34
|
local $@; |
63
|
21
|
|
|
|
|
43
|
eval { |
64
|
21
|
|
|
4
|
|
164
|
local $SIG{__DIE__} = sub { $xslate_err = shift }; |
|
4
|
|
|
|
|
85303
|
|
65
|
|
|
|
|
|
|
|
66
|
21
|
50
|
|
|
|
71
|
if (defined(my $inline = $options->{inline})) { |
67
|
0
|
|
|
|
|
0
|
$$output = $self->xslate->render_string($inline, \%params); |
68
|
|
|
|
|
|
|
} else { |
69
|
21
|
100
|
|
|
|
65
|
if (defined ($renderer->template_path($options))) { |
|
|
100
|
|
|
|
|
|
70
|
2
|
|
|
|
|
197
|
$c->app->log->debug(qq{Rendering template "$name"}); |
71
|
2
|
|
|
|
|
80
|
$$output = $self->xslate->render($name, \%params); |
72
|
|
|
|
|
|
|
} elsif (defined (my $data_template = $renderer->get_data_template($options))) { |
73
|
11
|
|
|
|
|
1655
|
$c->app->log->debug(qq{Rendering template "$name" from DATA section}); |
74
|
11
|
|
|
|
|
751
|
$$output = $self->xslate->render_string($data_template, \%params); |
75
|
|
|
|
|
|
|
} else { |
76
|
8
|
|
|
|
|
1106
|
$c->app->log->debug(qq{Template "$name" not found}) |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
}; |
80
|
21
|
100
|
|
|
|
113982
|
$@ = $xslate_err if $xslate_err; |
81
|
|
|
|
|
|
|
|
82
|
21
|
100
|
|
|
|
70
|
if ($@) { |
83
|
4
|
|
|
|
|
9
|
$$output = undef; |
84
|
4
|
50
|
33
|
|
|
50
|
if ( ( index( $@, 'Text::Xslate: LoadError: Cannot find \'exception.' ) < 0 ) |
85
|
|
|
|
|
|
|
&& ( index( $@, 'Text::Xslate: LoadError: Cannot find \'not_found.' ) < 0 ) |
86
|
|
|
|
|
|
|
) { |
87
|
4
|
50
|
|
|
|
43
|
die $@ unless $orig_err; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
17
|
|
|
|
|
76
|
return 1; # return value needed for Mojolicious <= 6.32 |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |