line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::Template::HtmlTemplate; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
239495
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
111
|
|
4
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
110
|
|
5
|
3
|
|
|
3
|
|
2994
|
use Dancer::ModuleLoader; |
|
3
|
|
|
|
|
15030
|
|
|
3
|
|
|
|
|
103
|
|
6
|
3
|
|
|
3
|
|
833
|
use Dancer::FileUtils 'path'; |
|
3
|
|
|
|
|
36154
|
|
|
3
|
|
|
|
|
193
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
23
|
use base 'Dancer::Template::Abstract'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2710
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub init { |
14
|
2
|
|
|
2
|
1
|
85
|
my ($self) = @_; |
15
|
|
|
|
|
|
|
|
16
|
2
|
50
|
|
|
|
20
|
die "HTML::Template is needed by Dancer::Template::HtmlTemplate" |
17
|
|
|
|
|
|
|
unless Dancer::ModuleLoader->load('HTML::Template'); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub render($$$) { |
21
|
2
|
|
|
2
|
1
|
37087
|
my ($self, $template, $tokens) = @_; |
22
|
2
|
50
|
33
|
|
|
103
|
die "'$template' is not a regular file" |
23
|
|
|
|
|
|
|
if !ref($template) && (!-f $template); |
24
|
|
|
|
|
|
|
|
25
|
2
|
50
|
|
|
|
17
|
_flatten($tokens) |
26
|
|
|
|
|
|
|
if ref $tokens eq 'HASH'; |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
34
|
my $config = $self->config; |
29
|
2
|
50
|
|
|
|
37
|
if ($config->{die_on_bad_params}) { |
30
|
0
|
|
|
|
|
0
|
Dancer::Logger::warning( |
31
|
|
|
|
|
|
|
"Ignoring die_on_bad_params setting supplied - see documentation" |
32
|
|
|
|
|
|
|
); |
33
|
0
|
|
|
|
|
0
|
delete $config->{die_on_bad_params}; |
34
|
|
|
|
|
|
|
} |
35
|
2
|
|
|
|
|
18
|
my $ht = HTML::Template->new( |
36
|
|
|
|
|
|
|
filename => $template, |
37
|
|
|
|
|
|
|
%$config, |
38
|
|
|
|
|
|
|
die_on_bad_params => 0, # Required, as we pass through other params too |
39
|
|
|
|
|
|
|
); |
40
|
2
|
|
|
|
|
1706
|
$ht->param($tokens); |
41
|
2
|
|
|
|
|
155
|
return $ht->output; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _flatten { |
46
|
2
|
|
|
2
|
|
4
|
my ($tokens) = @_; |
47
|
2
|
|
|
|
|
11
|
my @keys = keys %$tokens; |
48
|
2
|
|
|
|
|
9
|
while (@keys) { |
49
|
14
|
|
|
|
|
20
|
my $key = shift @keys; |
50
|
14
|
100
|
|
|
|
44
|
ref $tokens->{$key} eq 'HASH' |
51
|
|
|
|
|
|
|
or next; |
52
|
3
|
|
|
|
|
7
|
my $value = delete $tokens->{$key}; |
53
|
3
|
|
|
|
|
14
|
my @new_keys = map "$key.$_", keys %$value; |
54
|
3
|
|
|
|
|
11
|
@$tokens{@new_keys} = values %$value; |
55
|
3
|
|
|
|
|
10
|
push(@keys, @new_keys); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |