blob: aa239a05f212f2d42916d0f16217b1a4a8cea187 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package Text::Handlebars;
use strict;
use warnings;
use base 'Text::Xslate';
sub default_functions {
my $class = shift;
return {
%{ $class->SUPER::default_functions(@_) },
'(is_array)' => sub {
my ($val) = @_;
return ref($val) && ref($val) eq 'ARRAY';
},
'(is_empty_array)' => sub {
my ($val) = @_;
return @$val == 0;
},
'(make_array)' => sub {
my ($length) = @_;
return [(undef) x $length];
},
'(new_vars_for)' => sub {
my ($vars, $value, $i) = @_;
$i = 0 unless defined $i; # XXX
if (my $ref = ref($value)) {
if (defined $ref && $ref eq 'ARRAY') {
die "no iterator cycle provided?"
unless defined $i;
$value = $value->[$i];
$ref = ref($value);
}
die "invalid value: $value"
if !defined($ref) || $ref ne 'HASH';
return $value;
}
else {
return $vars;
}
},
};
}
sub options {
my $class = shift;
my $options = $class->SUPER::options(@_);
$options->{compiler} = 'Text::Handlebars::Compiler';
return $options;
}
1;
|