line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::Renderer::Xslate; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
12974
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
83
|
|
4
|
3
|
|
|
3
|
|
11
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
74
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
10
|
use File::Spec (); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
55
|
|
7
|
3
|
|
|
3
|
|
407
|
use Mojo::Base -base; |
|
3
|
|
|
|
|
6759
|
|
|
3
|
|
|
|
|
23
|
|
8
|
3
|
|
|
3
|
|
888
|
use Mojo::Loader qw(data_section); |
|
3
|
|
|
|
|
38865
|
|
|
3
|
|
|
|
|
175
|
|
9
|
3
|
|
|
3
|
|
1958
|
use Text::Xslate (); |
|
3
|
|
|
|
|
26122
|
|
|
3
|
|
|
|
|
1783
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
12
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'xslate'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub build { |
17
|
3
|
|
|
3
|
1
|
50
|
my $self = shift->SUPER::new(@_); |
18
|
3
|
|
|
|
|
20
|
$self->_init(@_); |
19
|
3
|
|
|
21
|
|
12
|
return sub { $self->_render(@_) }; |
|
21
|
|
|
|
|
220490
|
|
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _init { |
23
|
3
|
|
|
3
|
|
5
|
my ($self, %args) = @_; |
24
|
|
|
|
|
|
|
|
25
|
3
|
|
66
|
|
|
10
|
my $app = $args{mojo} || $args{app}; |
26
|
3
|
|
|
|
|
1
|
my $cache_dir; |
27
|
3
|
|
|
|
|
19
|
my @path = $app->home->rel_dir('templates'); |
28
|
|
|
|
|
|
|
|
29
|
3
|
50
|
|
|
|
113
|
if ($app) { |
30
|
3
|
|
|
|
|
7
|
$cache_dir = $app->home->rel_dir('tmp/compiled_templates'); |
31
|
3
|
|
|
|
|
34
|
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
|
|
|
|
278
|
%{$args{template_options} || {}}, |
|
3
|
|
|
|
|
28
|
|
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
3
|
|
|
|
|
16
|
$self->xslate(Text::Xslate->new(\%config)); |
48
|
|
|
|
|
|
|
|
49
|
3
|
|
|
|
|
466
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _render { |
53
|
21
|
|
|
21
|
|
38
|
my ($self, $renderer, $c, $output, $options) = @_; |
54
|
|
|
|
|
|
|
|
55
|
21
|
|
33
|
|
|
59
|
my $name = $c->stash->{'template_name'} |
56
|
|
|
|
|
|
|
|| $renderer->template_name($options); |
57
|
21
|
|
|
|
|
344
|
my %params = (%{$c->stash}, c => $c); |
|
21
|
|
|
|
|
89
|
|
58
|
|
|
|
|
|
|
|
59
|
21
|
|
|
|
|
173
|
my $orig_err = $@; |
60
|
21
|
|
|
|
|
21
|
my $xslate_err; |
61
|
|
|
|
|
|
|
|
62
|
21
|
|
|
|
|
25
|
local $@; |
63
|
21
|
50
|
|
|
|
55
|
if (defined(my $inline = $options->{inline})) { |
64
|
0
|
|
|
|
|
0
|
eval { |
65
|
0
|
|
|
0
|
|
0
|
local $SIG{__DIE__} = sub { $xslate_err = shift }; |
|
0
|
|
|
|
|
0
|
|
66
|
0
|
|
|
|
|
0
|
$$output = $self->xslate->render_string($inline, \%params); |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
21
|
|
|
|
|
34
|
eval { |
71
|
21
|
|
|
12
|
|
133
|
local $SIG{__DIE__} = sub { $xslate_err = shift }; |
|
12
|
|
|
|
|
64235
|
|
72
|
21
|
|
|
|
|
56
|
$$output = $self->xslate->render($name, \%params); |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
} |
75
|
21
|
100
|
|
|
|
72297
|
$@ = $xslate_err if $xslate_err; |
76
|
|
|
|
|
|
|
|
77
|
21
|
100
|
|
|
|
51
|
if ($@) { |
78
|
12
|
|
|
|
|
17
|
$$output = undef; |
79
|
12
|
100
|
100
|
|
|
69
|
if ( ( index( $@, 'Text::Xslate: LoadError: Cannot find \'exception.' ) < 0 ) |
80
|
|
|
|
|
|
|
&& ( index( $@, 'Text::Xslate: LoadError: Cannot find \'not_found.' ) < 0 ) |
81
|
|
|
|
|
|
|
) { |
82
|
4
|
50
|
|
|
|
38
|
die $@ unless $orig_err; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
17
|
|
|
|
|
74
|
return 1; # return value needed for Mojolicious <= 6.32 |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |