line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Handlebars; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
14
|
|
|
14
|
|
630502
|
$Text::Handlebars::AUTHORITY = 'cpan:DOY'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
$Text::Handlebars::VERSION = '0.04'; |
6
|
14
|
|
|
14
|
|
133
|
use strict; |
|
14
|
|
|
|
|
31
|
|
|
14
|
|
|
|
|
882
|
|
7
|
14
|
|
|
14
|
|
83
|
use warnings; |
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
697
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: http://handlebarsjs.com/ for Text::Xslate |
9
|
|
|
|
|
|
|
|
10
|
14
|
|
|
14
|
|
21250
|
use Text::Xslate 2.0000; |
|
14
|
|
|
|
|
331570
|
|
|
14
|
|
|
|
|
1057
|
|
11
|
14
|
|
|
14
|
|
174
|
use base 'Text::Xslate'; |
|
14
|
|
|
|
|
30
|
|
|
14
|
|
|
|
|
32306
|
|
12
|
|
|
|
|
|
|
|
13
|
14
|
|
|
14
|
|
164
|
use Scalar::Util 'weaken'; |
|
14
|
|
|
|
|
31
|
|
|
14
|
|
|
|
|
13294
|
|
14
|
14
|
|
|
14
|
|
335
|
use Try::Tiny; |
|
14
|
|
|
|
|
31
|
|
|
14
|
|
|
|
|
21230
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub default_helpers { |
18
|
160
|
|
|
160
|
0
|
339
|
my $class = shift; |
19
|
|
|
|
|
|
|
return { |
20
|
|
|
|
|
|
|
with => sub { |
21
|
3
|
|
|
3
|
|
7
|
my ($context, $new_context, $options) = @_; |
22
|
3
|
|
|
|
|
16
|
return $options->{fn}->($new_context); |
23
|
|
|
|
|
|
|
}, |
24
|
|
|
|
|
|
|
each => sub { |
25
|
13
|
|
|
13
|
|
26
|
my ($context, $list, $options) = @_; |
26
|
13
|
|
|
|
|
36
|
return join '', map { $options->{fn}->($_) } @$list; |
|
29
|
|
|
|
|
35262
|
|
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
if => sub { |
29
|
8
|
|
|
8
|
|
22
|
my ($context, $conditional, $options) = @_; |
30
|
8
|
100
|
|
|
|
48
|
return $conditional |
31
|
|
|
|
|
|
|
? $options->{fn}->($context) |
32
|
|
|
|
|
|
|
: $options->{inverse}->($context); |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
unless => sub { |
35
|
2
|
|
|
2
|
|
5
|
my ($context, $conditional, $options) = @_; |
36
|
2
|
100
|
|
|
|
12
|
return $conditional |
37
|
|
|
|
|
|
|
? $options->{inverse}->($context) |
38
|
|
|
|
|
|
|
: $options->{fn}->($context); |
39
|
|
|
|
|
|
|
}, |
40
|
160
|
|
|
|
|
3807
|
}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub default_functions { |
44
|
80
|
|
|
80
|
0
|
491
|
my $class = shift; |
45
|
|
|
|
|
|
|
return { |
46
|
80
|
|
|
|
|
521
|
%{ $class->SUPER::default_functions(@_) }, |
|
80
|
|
|
|
|
713
|
|
47
|
80
|
|
|
|
|
141
|
%{ $class->default_helpers }, |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub options { |
52
|
80
|
|
|
80
|
0
|
1238781
|
my $class = shift; |
53
|
|
|
|
|
|
|
|
54
|
80
|
|
|
|
|
641
|
my $options = $class->SUPER::options(@_); |
55
|
|
|
|
|
|
|
|
56
|
80
|
|
|
|
|
9588
|
$options->{compiler} = 'Text::Handlebars::Compiler'; |
57
|
80
|
|
|
|
|
265
|
$options->{helpers} = {}; |
58
|
|
|
|
|
|
|
|
59
|
80
|
|
|
|
|
329
|
return $options; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _register_builtin_methods { |
63
|
80
|
|
|
80
|
|
18344
|
my $self = shift; |
64
|
80
|
|
|
|
|
176
|
my ($funcs) = @_; |
65
|
|
|
|
|
|
|
|
66
|
80
|
|
|
|
|
477
|
weaken(my $weakself = $self); |
67
|
|
|
|
|
|
|
$funcs->{'(render_string)'} = sub { |
68
|
3
|
|
|
3
|
|
33685
|
my ($to_render, $vars) = @_; |
69
|
3
|
|
|
|
|
21
|
return $weakself->render_string($to_render, $vars); |
70
|
80
|
|
|
|
|
546
|
}; |
71
|
|
|
|
|
|
|
$funcs->{'(make_block_helper)'} = sub { |
72
|
33
|
|
|
33
|
|
111511
|
my ($vars, $code, $raw_text, $else_raw_text, $hash) = @_; |
73
|
|
|
|
|
|
|
|
74
|
33
|
|
|
|
|
91
|
my $options = {}; |
75
|
|
|
|
|
|
|
$options->{fn} = sub { |
76
|
47
|
|
|
|
|
8811
|
my ($new_vars) = @_; |
77
|
47
|
|
|
|
|
147
|
$new_vars = { |
78
|
47
|
|
|
|
|
73
|
%{ canonicalize_vars($new_vars) }, |
79
|
|
|
|
|
|
|
'..' => $vars, |
80
|
|
|
|
|
|
|
}; |
81
|
47
|
|
|
|
|
448
|
return $weakself->render_string($raw_text, $new_vars); |
82
|
33
|
|
|
|
|
6170
|
}; |
83
|
|
|
|
|
|
|
$options->{inverse} = sub { |
84
|
7
|
|
|
|
|
27
|
my ($new_vars) = @_; |
85
|
7
|
|
|
|
|
26
|
$new_vars = { |
86
|
7
|
|
|
|
|
15
|
%{ canonicalize_vars($new_vars) }, |
87
|
|
|
|
|
|
|
'..' => $vars, |
88
|
|
|
|
|
|
|
}; |
89
|
7
|
|
|
|
|
32
|
return $weakself->render_string($else_raw_text, $new_vars); |
90
|
33
|
|
|
|
|
250
|
}; |
91
|
33
|
|
|
|
|
105
|
$options->{hash} = $hash; |
92
|
|
|
|
|
|
|
|
93
|
33
|
|
|
|
|
274
|
return sub { $code->(@_, $options); }; |
|
33
|
|
|
|
|
178
|
|
94
|
80
|
|
|
|
|
500
|
}; |
95
|
|
|
|
|
|
|
|
96
|
80
|
|
|
|
|
177
|
for my $helper (keys %{ $self->{helpers} }) { |
|
80
|
|
|
|
|
543
|
|
97
|
19
|
|
|
|
|
103
|
$funcs->{$helper} = $self->{helpers}{$helper}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _compiler { |
102
|
142
|
|
|
142
|
|
59348
|
my $self = shift; |
103
|
|
|
|
|
|
|
|
104
|
142
|
100
|
|
|
|
895
|
if (!ref($self->{compiler})) { |
105
|
80
|
|
|
|
|
522
|
my $compiler = $self->SUPER::_compiler(@_); |
106
|
80
|
|
|
|
|
1089
|
$compiler->define_helper(keys %{ $self->{helpers} }); |
|
80
|
|
|
|
|
742
|
|
107
|
80
|
|
|
|
|
149
|
$compiler->define_helper(keys %{ $self->default_helpers }); |
|
80
|
|
|
|
|
325
|
|
108
|
80
|
|
|
|
|
1974
|
return $compiler; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
else { |
111
|
62
|
|
|
|
|
321
|
return $self->SUPER::_compiler(@_); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub render_string { |
116
|
136
|
|
|
136
|
1
|
8221
|
my $self = shift; |
117
|
136
|
|
|
|
|
301
|
my ($string, $vars) = @_; |
118
|
|
|
|
|
|
|
|
119
|
136
|
|
|
|
|
414
|
return $self->SUPER::render_string($string, canonicalize_vars($vars)); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub render { |
123
|
176
|
|
|
176
|
1
|
58734
|
my $self = shift; |
124
|
176
|
|
|
|
|
750
|
my ($name, $vars) = @_; |
125
|
|
|
|
|
|
|
|
126
|
176
|
|
|
|
|
431
|
return $self->SUPER::render($name, canonicalize_vars($vars)); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub canonicalize_vars { |
130
|
366
|
|
|
366
|
0
|
566
|
my ($vars) = @_; |
131
|
366
|
100
|
66
|
|
|
2099
|
if (ref($vars) && ref($vars) eq 'HASH') { |
132
|
169
|
|
|
|
|
1702
|
return $vars; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
else { |
135
|
197
|
|
|
|
|
4026
|
return { '.' => $vars }; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
__END__ |