line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::Renderer::Xslate; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
13966
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
73
|
|
4
|
3
|
|
|
3
|
|
10
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
66
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
12
|
use File::Spec (); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
62
|
|
7
|
3
|
|
|
3
|
|
442
|
use Mojo::Base -base; |
|
3
|
|
|
|
|
7364
|
|
|
3
|
|
|
|
|
24
|
|
8
|
3
|
|
|
3
|
|
924
|
use Mojo::Loader qw(data_section); |
|
3
|
|
|
|
|
97796
|
|
|
3
|
|
|
|
|
175
|
|
9
|
3
|
|
|
3
|
|
1962
|
use Text::Xslate (); |
|
3
|
|
|
|
|
23397
|
|
|
3
|
|
|
|
|
1867
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
12
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'xslate'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub build { |
17
|
3
|
|
|
3
|
1
|
52
|
my $self = shift->SUPER::new(@_); |
18
|
3
|
|
|
|
|
20
|
$self->_init(@_); |
19
|
3
|
|
|
21
|
|
9
|
return sub { $self->_render(@_) }; |
|
21
|
|
|
|
|
276297
|
|
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
|
|
|
|
|
3
|
my $cache_dir; |
27
|
3
|
|
|
|
|
12
|
my @path = $app->home->rel_file('templates'); |
28
|
|
|
|
|
|
|
|
29
|
3
|
50
|
|
|
|
99
|
if ($app) { |
30
|
3
|
|
|
|
|
8
|
$cache_dir = $app->home->rel_file('tmp/compiled_templates'); |
31
|
3
|
|
|
|
|
49
|
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
|
|
|
|
308
|
%{$args{template_options} || {}}, |
|
3
|
|
|
|
|
29
|
|
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
3
|
|
|
|
|
17
|
$self->xslate(Text::Xslate->new(\%config)); |
48
|
|
|
|
|
|
|
|
49
|
3
|
|
|
|
|
470
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _render { |
53
|
21
|
|
|
21
|
|
39
|
my ($self, $renderer, $c, $output, $options) = @_; |
54
|
|
|
|
|
|
|
|
55
|
21
|
|
33
|
|
|
49
|
my $name = $c->stash->{'template_name'} |
56
|
|
|
|
|
|
|
|| $renderer->template_name($options); |
57
|
21
|
|
|
|
|
394
|
my %params = (%{$c->stash}, c => $c); |
|
21
|
|
|
|
|
92
|
|
58
|
|
|
|
|
|
|
|
59
|
21
|
|
|
|
|
190
|
my $orig_err = $@; |
60
|
21
|
|
|
|
|
18
|
my $xslate_err; |
61
|
|
|
|
|
|
|
|
62
|
21
|
|
|
|
|
21
|
local $@; |
63
|
21
|
50
|
|
|
|
62
|
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
|
|
|
|
|
30
|
eval { |
71
|
21
|
|
|
12
|
|
150
|
local $SIG{__DIE__} = sub { $xslate_err = shift }; |
|
12
|
|
|
|
|
59537
|
|
72
|
21
|
|
|
|
|
79
|
$$output = $self->xslate->render($name, \%params); |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
} |
75
|
21
|
100
|
|
|
|
77009
|
$@ = $xslate_err if $xslate_err; |
76
|
|
|
|
|
|
|
|
77
|
21
|
100
|
|
|
|
55
|
if ($@) { |
78
|
12
|
|
|
|
|
18
|
$$output = undef; |
79
|
12
|
100
|
100
|
|
|
71
|
if ( ( index( $@, 'Text::Xslate: LoadError: Cannot find \'exception.' ) < 0 ) |
80
|
|
|
|
|
|
|
&& ( index( $@, 'Text::Xslate: LoadError: Cannot find \'not_found.' ) < 0 ) |
81
|
|
|
|
|
|
|
) { |
82
|
4
|
50
|
|
|
|
53
|
die $@ unless $orig_err; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
17
|
|
|
|
|
72
|
return 1; # return value needed for Mojolicious <= 6.32 |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |