line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Hogan::Template; |
2
|
|
|
|
|
|
|
$Text::Hogan::Template::VERSION = '2.02'; |
3
|
4
|
|
|
4
|
|
61
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
132
|
|
4
|
4
|
|
|
4
|
|
26
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
151
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
42
|
use Scalar::Util qw(looks_like_number); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
226
|
|
7
|
4
|
|
|
4
|
|
1686
|
use Clone qw(clone); |
|
4
|
|
|
|
|
9826
|
|
|
4
|
|
|
|
|
8417
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
149
|
|
|
149
|
0
|
438
|
my ($orig, $code_obj, $text, $compiler, $options) = @_; |
11
|
|
|
|
|
|
|
|
12
|
149
|
|
100
|
|
|
419
|
$code_obj ||= {}; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
return bless { |
15
|
|
|
|
|
|
|
r => $code_obj->{'code'} || (ref($orig) && $orig->{'r'}), |
16
|
|
|
|
|
|
|
c => $compiler, |
17
|
|
|
|
|
|
|
buf => "", |
18
|
|
|
|
|
|
|
options => $options || {}, |
19
|
|
|
|
|
|
|
text => $text || "", |
20
|
|
|
|
|
|
|
partials => $code_obj->{'partials'} || {}, |
21
|
|
|
|
|
|
|
subs => $code_obj->{'subs'} || {}, |
22
|
149
|
|
66
|
|
|
2415
|
numeric_string_as_string => !!$options->{'numeric_string_as_string'}, |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
23
|
|
|
|
|
|
|
}, ref($orig)||$orig; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub r { |
27
|
163
|
|
|
163
|
0
|
302
|
my ($self, $context, $partials, $indent) = @_; |
28
|
|
|
|
|
|
|
|
29
|
163
|
50
|
|
|
|
415
|
if ($self->{'r'}) { |
30
|
163
|
|
|
|
|
3777
|
return $self->{'r'}->($self, $context, $partials, $indent); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
return ""; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my %mapping = ( |
37
|
|
|
|
|
|
|
'&' => '&', |
38
|
|
|
|
|
|
|
'<' => '<', |
39
|
|
|
|
|
|
|
'>' => '>', |
40
|
|
|
|
|
|
|
q{'} => ''', |
41
|
|
|
|
|
|
|
'"' => '"', |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub v { |
45
|
117
|
|
|
117
|
0
|
207
|
my ($self, $str) = @_; |
46
|
117
|
|
50
|
|
|
231
|
$str //= ""; |
47
|
|
|
|
|
|
|
|
48
|
117
|
|
|
|
|
561
|
my $re = join('', '[', ( sort keys %mapping ), ']'); |
49
|
|
|
|
|
|
|
|
50
|
117
|
|
|
|
|
527
|
$str =~ s/($re)/$mapping{$1}/ge; |
|
5
|
|
|
|
|
19
|
|
51
|
|
|
|
|
|
|
|
52
|
117
|
|
|
|
|
434
|
return $str; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub t { |
56
|
22
|
|
|
22
|
0
|
47
|
my ($self, $str) = @_; |
57
|
22
|
50
|
|
|
|
86
|
return defined($str) ? $str : ""; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub render { |
61
|
147
|
|
|
147
|
0
|
2413
|
my ($self, $context, $partials, $indent) = @_; |
62
|
147
|
|
100
|
|
|
733
|
return $self->ri([ $context ], $partials || {}, $indent); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub ri { |
66
|
163
|
|
|
163
|
0
|
346
|
my ($self, $context, $partials, $indent) = @_; |
67
|
163
|
|
|
|
|
348
|
return $self->r($context, $partials, $indent); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub ep { |
71
|
16
|
|
|
16
|
0
|
31
|
my ($self, $symbol, $partials) = @_; |
72
|
16
|
|
|
|
|
47
|
my $partial = $self->{'partials'}{$symbol}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# check to see that if we've instantiated this partial before |
75
|
16
|
|
|
|
|
49
|
my $template = $partials->{$partial->{'name'}}; |
76
|
16
|
50
|
33
|
|
|
49
|
if ($partial->{'instance'} && $partial->{'base'} eq $template) { |
77
|
0
|
|
|
|
|
0
|
return $partial->{'instance'}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
16
|
50
|
|
|
|
38
|
if (!ref($template)) { |
81
|
16
|
50
|
|
|
|
46
|
die "No compiler available" unless $self->{'c'}; |
82
|
|
|
|
|
|
|
|
83
|
16
|
|
|
|
|
50
|
$template = $self->{'c'}->compile($template, $self->{'options'}); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
16
|
50
|
|
|
|
39
|
return undef unless $template; |
87
|
|
|
|
|
|
|
|
88
|
16
|
|
|
|
|
43
|
$self->{'partials'}{$symbol}{'base'} = $template; |
89
|
|
|
|
|
|
|
|
90
|
16
|
50
|
|
|
|
55
|
if ($partial->{'subs'}) { |
91
|
|
|
|
|
|
|
# make sure we consider parent template now |
92
|
16
|
|
100
|
|
|
78
|
$partials->{'stack_text'} ||= {}; |
93
|
|
|
|
|
|
|
|
94
|
16
|
|
|
|
|
23
|
for my $key (sort keys %{ $partial->{'subs'} }) { |
|
16
|
|
|
|
|
67
|
|
95
|
0
|
0
|
|
|
|
0
|
if (!$partials->{'stack_text'}{$key}) { |
96
|
|
|
|
|
|
|
$partials->{'stack_text'}{$key} = |
97
|
|
|
|
|
|
|
$self->{'active_sub'} && $partials->{'stack_text'}{$self->{'active_sub'}} |
98
|
|
|
|
|
|
|
? $partials->{'stack_text'}{$self->{'active_sub'}} |
99
|
0
|
0
|
0
|
|
|
0
|
: $self->{'text'}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
16
|
|
|
|
|
81
|
$template = create_specialized_partial($template, $partial->{'subs'}, $partial->{'partials'}, $self->{'stack_subs'}, $self->{'stack_partials'}, $self->{'stack_text'}); |
103
|
|
|
|
|
|
|
} |
104
|
16
|
|
|
|
|
70
|
$self->{'partials'}{$symbol}{'instance'} = $template; |
105
|
|
|
|
|
|
|
|
106
|
16
|
|
|
|
|
49
|
return $template; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# tries to find a partial in the current scope and render it |
110
|
|
|
|
|
|
|
sub rp { |
111
|
16
|
|
|
16
|
0
|
44
|
my ($self, $symbol, $context, $partials, $indent) = @_; |
112
|
|
|
|
|
|
|
|
113
|
16
|
50
|
|
|
|
42
|
my $partial = $self->ep($symbol, $partials) or return ""; |
114
|
|
|
|
|
|
|
|
115
|
16
|
|
|
|
|
49
|
return $partial->ri($context, $partials, $indent); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# render a section |
119
|
|
|
|
|
|
|
sub rs { |
120
|
37
|
|
|
37
|
0
|
86
|
my ($self, $context, $partials, $section) = @_; |
121
|
37
|
|
|
|
|
67
|
my $tail = $context->[-1]; |
122
|
37
|
100
|
|
|
|
95
|
if (ref $tail ne 'ARRAY') { |
123
|
29
|
|
|
|
|
568
|
$section->($context, $partials, $self); |
124
|
29
|
|
|
|
|
534
|
return; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
8
|
|
|
|
|
19
|
for my $t (@$tail) { |
128
|
27
|
|
|
|
|
55
|
push @$context, $t; |
129
|
27
|
|
|
|
|
500
|
$section->($context, $partials, $self); |
130
|
27
|
|
|
|
|
196
|
pop @$context; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# maybe start a section |
135
|
|
|
|
|
|
|
sub s { |
136
|
77
|
|
|
77
|
0
|
191
|
my ($self, $val, $ctx, $partials, $inverted, $start, $end, $tags) = @_; |
137
|
77
|
|
|
|
|
124
|
my $pass; |
138
|
|
|
|
|
|
|
|
139
|
77
|
100
|
100
|
|
|
285
|
return 0 if (ref($val) eq 'ARRAY') && !@$val; |
140
|
|
|
|
|
|
|
|
141
|
74
|
100
|
|
|
|
154
|
if (ref($val) eq 'CODE') { |
142
|
6
|
|
|
|
|
16
|
$val = $self->ms($val, $ctx, $partials, $inverted, $start, $end, $tags); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
74
|
|
|
|
|
128
|
$pass = !!$val; |
146
|
|
|
|
|
|
|
|
147
|
74
|
100
|
100
|
|
|
289
|
if (!$inverted && $pass && $ctx) { |
|
|
|
66
|
|
|
|
|
148
|
37
|
100
|
100
|
|
|
163
|
push @$ctx, ((ref($val) eq 'ARRAY') || (ref($val) eq 'HASH')) ? $val : $ctx->[-1]; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
74
|
|
|
|
|
1684
|
return $pass; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# find values with dotted names |
155
|
|
|
|
|
|
|
sub d { |
156
|
37
|
|
|
37
|
0
|
86
|
my ($self, $key, $ctx, $partials, $return_found) = @_; |
157
|
37
|
|
|
|
|
56
|
my $found; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# JavaScript split is super weird!! |
160
|
|
|
|
|
|
|
# |
161
|
|
|
|
|
|
|
# GOOD: |
162
|
|
|
|
|
|
|
# > "a.b.c".split(".") |
163
|
|
|
|
|
|
|
# [ 'a', 'b', 'c' ] |
164
|
|
|
|
|
|
|
# |
165
|
|
|
|
|
|
|
# BAD: |
166
|
|
|
|
|
|
|
# > ".".split(".") |
167
|
|
|
|
|
|
|
# [ '', '' ] |
168
|
|
|
|
|
|
|
# |
169
|
37
|
100
|
|
|
|
132
|
my @names = $key eq '.' ? ( '' ) x 2 : split /\./, $key; |
170
|
|
|
|
|
|
|
|
171
|
37
|
|
|
|
|
84
|
my $val = $self->f($names[0], $ctx, $partials, $return_found); |
172
|
|
|
|
|
|
|
|
173
|
37
|
|
|
|
|
55
|
my $cx; |
174
|
|
|
|
|
|
|
|
175
|
37
|
100
|
66
|
|
|
136
|
if ($key eq '.' && (ref($ctx->[-2]) eq 'ARRAY')) { |
176
|
23
|
|
|
|
|
37
|
$val = $ctx->[-1]; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
else { |
179
|
14
|
|
|
|
|
42
|
for my $name (@names[1..$#names] ) { |
180
|
30
|
|
|
|
|
53
|
$found = find_in_scope($name, $val); |
181
|
30
|
100
|
|
|
|
58
|
if (defined $found) { |
182
|
21
|
|
|
|
|
32
|
$cx = $val; |
183
|
21
|
|
|
|
|
34
|
$val = $found; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
else { |
186
|
9
|
|
|
|
|
17
|
$val = ""; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
37
|
100
|
100
|
|
|
114
|
return 0 if $return_found && !$val; |
192
|
|
|
|
|
|
|
|
193
|
33
|
50
|
66
|
|
|
100
|
if (!$return_found && ref($val) eq 'CODE') { |
194
|
0
|
|
|
|
|
0
|
push @$ctx, $cx; |
195
|
0
|
|
|
|
|
0
|
$val = $self->mv($val, $ctx, $partials); |
196
|
0
|
|
|
|
|
0
|
pop @$ctx; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
33
|
|
|
|
|
66
|
return $self->_check_for_num($val); |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# handle numerical interpolation for decimal numbers "properly"... |
203
|
|
|
|
|
|
|
# |
204
|
|
|
|
|
|
|
# according to the mustache spec 1.210 should render as 1.21 |
205
|
|
|
|
|
|
|
# |
206
|
|
|
|
|
|
|
# unless the optional numeric_string_as_string was passed |
207
|
|
|
|
|
|
|
sub _check_for_num { |
208
|
219
|
|
|
219
|
|
325
|
my $self = shift; |
209
|
219
|
|
|
|
|
305
|
my $val = shift; |
210
|
219
|
100
|
|
|
|
449
|
return $val if ($self->{'numeric_string_as_string'} == 1); |
211
|
|
|
|
|
|
|
|
212
|
218
|
100
|
|
|
|
762
|
$val += 0 if looks_like_number($val); |
213
|
|
|
|
|
|
|
|
214
|
218
|
|
|
|
|
781
|
return $val; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# find values with normal names |
218
|
|
|
|
|
|
|
sub f { |
219
|
216
|
|
|
216
|
0
|
498
|
my ($self, $key, $ctx, $partials, $return_found) = @_; |
220
|
216
|
|
|
|
|
387
|
my ( $val, $found ) = ( 0 ); |
221
|
|
|
|
|
|
|
|
222
|
216
|
|
|
|
|
416
|
for my $v ( reverse @$ctx ) { |
223
|
344
|
|
|
|
|
604
|
$val = find_in_scope($key, $v); |
224
|
|
|
|
|
|
|
|
225
|
344
|
100
|
|
|
|
749
|
next unless defined $val; |
226
|
|
|
|
|
|
|
|
227
|
186
|
|
|
|
|
278
|
$found = 1; |
228
|
186
|
|
|
|
|
270
|
last; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
216
|
100
|
|
|
|
440
|
return $return_found ? 0 : "" unless $found; |
|
|
100
|
|
|
|
|
|
232
|
|
|
|
|
|
|
|
233
|
186
|
100
|
100
|
|
|
586
|
if (!$return_found && (ref($val) eq 'CODE')) { |
234
|
8
|
|
|
|
|
24
|
$val = $self->mv($val, $ctx, $partials); |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
186
|
|
|
|
|
384
|
return $self->_check_for_num($val); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
# higher order templates |
241
|
|
|
|
|
|
|
sub ls { |
242
|
5
|
|
|
5
|
0
|
13
|
my ($self, $func, $cx, $ctx, $partials, $text, $tags) = @_; |
243
|
5
|
|
|
|
|
9
|
my $old_tags = $self->{'options'}{'delimiters'}; |
244
|
|
|
|
|
|
|
|
245
|
5
|
|
|
|
|
10
|
$self->{'options'}{'delimiters'} = $tags; |
246
|
5
|
|
|
|
|
68
|
$self->b($self->ct($func->($text), $cx, $partials)); |
247
|
5
|
|
|
|
|
11
|
$self->{'options'}{'delimiters'} = $old_tags; |
248
|
|
|
|
|
|
|
|
249
|
5
|
|
|
|
|
10
|
return 0; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
# compile text |
253
|
|
|
|
|
|
|
sub ct { |
254
|
13
|
|
|
13
|
0
|
45
|
my ($self, $text, $cx, $partials) = @_; |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
die "Lambda features disabled" |
257
|
13
|
50
|
|
|
|
31
|
if $self->{'options'}{'disable_lambda'}; |
258
|
|
|
|
|
|
|
|
259
|
13
|
|
|
|
|
42
|
return $self->{'c'}->compile($text, $self->{'options'})->render($cx, $partials); |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
# template result buffering |
263
|
|
|
|
|
|
|
sub b { |
264
|
788
|
|
|
788
|
0
|
1526
|
my ($self, $s) = @_; |
265
|
788
|
|
|
|
|
13493
|
$self->{'buf'} .= $s; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
sub fl { |
269
|
163
|
|
|
163
|
0
|
316
|
my ($self) = @_; |
270
|
163
|
|
|
|
|
288
|
my $r = $self->{'buf'}; |
271
|
163
|
|
|
|
|
262
|
$self->{'buf'} = ""; |
272
|
163
|
|
|
|
|
830
|
return $r; |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
# method replace section |
276
|
|
|
|
|
|
|
sub ms { |
277
|
6
|
|
|
6
|
0
|
14
|
my ($self, $func, $ctx, $partials, $inverted, $start, $end, $tags) = @_; |
278
|
|
|
|
|
|
|
|
279
|
6
|
100
|
|
|
|
13
|
return 1 if $inverted; |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
my $text_source = ($self->{'active_sub'} && $self->{'subs_text'} && $self->{'subs_text'}{$self->{'active_sub'}}) |
282
|
|
|
|
|
|
|
? $self->{'subs_text'}{$self->{'active_sub'}} |
283
|
5
|
50
|
0
|
|
|
35
|
: $self->{'text'}; |
284
|
|
|
|
|
|
|
|
285
|
5
|
|
|
|
|
18
|
my $s = substr($text_source,$start,($end-$start)); |
286
|
|
|
|
|
|
|
|
287
|
5
|
|
|
|
|
17
|
$self->ls($func, $ctx->[-1], $ctx, $partials, $s, $tags); |
288
|
|
|
|
|
|
|
|
289
|
5
|
|
|
|
|
13
|
return 0; |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
# method replace variable |
293
|
|
|
|
|
|
|
sub mv { |
294
|
8
|
|
|
8
|
0
|
15
|
my ($self, $func, $ctx, $partials) = @_; |
295
|
8
|
|
|
|
|
13
|
my $cx = $ctx->[-1]; |
296
|
8
|
|
|
|
|
91
|
my $result = $func->($self,$cx); |
297
|
|
|
|
|
|
|
|
298
|
8
|
|
|
|
|
41
|
return $self->ct($result, $cx, $partials); |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
sub sub { |
302
|
0
|
|
|
0
|
0
|
0
|
my ($self, $name, $context, $partials, $indent) = @_; |
303
|
0
|
0
|
|
|
|
0
|
my $f = $self->{'subs'}{$name} or return; |
304
|
|
|
|
|
|
|
|
305
|
0
|
|
|
|
|
0
|
$self->{'active_sub'} = $name; |
306
|
0
|
|
|
|
|
0
|
$f->($context,$partials,$self,$indent); |
307
|
0
|
|
|
|
|
0
|
$self->{'active_sub'} = 0; |
308
|
|
|
|
|
|
|
} |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
################################################ |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
sub find_in_scope { |
313
|
374
|
|
|
374
|
0
|
648
|
my ($key, $scope) = @_; |
314
|
|
|
|
|
|
|
|
315
|
374
|
|
|
|
|
508
|
return eval { $scope->{$key} }; |
|
374
|
|
|
|
|
1078
|
|
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
sub create_specialized_partial { |
319
|
16
|
|
|
16
|
0
|
66
|
my ($instance, $subs, $partials, $stack_subs, $stack_partials, $stack_text) = @_; |
320
|
|
|
|
|
|
|
|
321
|
16
|
|
|
|
|
366
|
my $Partial = clone($instance); |
322
|
16
|
|
|
|
|
54
|
$Partial->{'buf'} = ""; |
323
|
|
|
|
|
|
|
|
324
|
16
|
|
100
|
|
|
74
|
$stack_subs ||= {}; |
325
|
16
|
|
|
|
|
31
|
$Partial->{'stack_subs'} = $stack_subs; |
326
|
16
|
|
|
|
|
28
|
$Partial->{'subs_text'} = $stack_text; |
327
|
|
|
|
|
|
|
|
328
|
16
|
|
|
|
|
38
|
for my $key (sort keys %$subs) { |
329
|
0
|
0
|
|
|
|
0
|
if (!$stack_subs->{$key}) { |
330
|
0
|
|
|
|
|
0
|
$stack_subs->{$key} = $subs->{$key}; |
331
|
|
|
|
|
|
|
} |
332
|
|
|
|
|
|
|
} |
333
|
16
|
|
|
|
|
33
|
for my $key (sort keys %$stack_subs) { |
334
|
0
|
|
|
|
|
0
|
$Partial->{'subs'}{$key} = $stack_subs->{$key}; |
335
|
|
|
|
|
|
|
} |
336
|
|
|
|
|
|
|
|
337
|
16
|
|
100
|
|
|
63
|
$stack_partials ||= {}; |
338
|
16
|
|
|
|
|
28
|
$Partial->{'stack_partials'} = $stack_partials; |
339
|
|
|
|
|
|
|
|
340
|
16
|
|
|
|
|
41
|
for my $key (sort keys %$partials) { |
341
|
0
|
0
|
|
|
|
0
|
if (!$stack_partials->{$key}) { |
342
|
0
|
|
|
|
|
0
|
$stack_partials->{$key} = $partials->{$key}; |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
} |
345
|
16
|
|
|
|
|
35
|
for my $key (sort keys %$stack_partials) { |
346
|
0
|
|
|
|
|
0
|
$Partial->{'partials'}{$key} = $stack_partials->{$key}; |
347
|
|
|
|
|
|
|
} |
348
|
|
|
|
|
|
|
|
349
|
16
|
|
|
|
|
36
|
return $Partial; |
350
|
|
|
|
|
|
|
} |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
sub coerce_to_string { |
354
|
0
|
|
|
0
|
0
|
|
my ($str) = @_; |
355
|
0
|
0
|
|
|
|
|
return defined($str) ? $str : ""; |
356
|
|
|
|
|
|
|
} |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
1; |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
__END__ |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
=head1 NAME |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
Text::Hogan::Template - represent and render compiled templates |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
=head1 VERSION |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
version 2.02 |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
=head1 SYNOPSIS |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
Use Text::Hogan::Compiler to create Template objects. |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
Then call render passing in a hashref for context. |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
use Text::Hogan::Compiler; |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
my $template = Text::Hogan::Compiler->new->compile("Hello, {{name}}!"); |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
say $template->render({ name => $_ }) for (qw(Fred Wilma Barney Betty)); |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
Optionally takes a hashref of partials. |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
use Text::Hogan::Compiler; |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
my $template = Text::Hogan::Compiler->new->compile("{{>hello}}"); |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
say $template->render({ name => "Dino" }, { hello => "Hello, {{name}}!" }); |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
=head1 AUTHORS |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
Started out statement-for-statement copied from hogan.js by Twitter! |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
Initial translation by Alex Balhatchet (alex@balhatchet.net) |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
Further improvements from: |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
Ed Freyfogle |
399
|
|
|
|
|
|
|
Mohammad S Anwar |
400
|
|
|
|
|
|
|
Ricky Morse |
401
|
|
|
|
|
|
|
Jerrad Pierce |
402
|
|
|
|
|
|
|
Tom Hukins |
403
|
|
|
|
|
|
|
Tony Finch |
404
|
|
|
|
|
|
|
Yanick Champoux |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
=cut |