summaryrefslogtreecommitdiffstats
path: root/lib/Text/Handlebars/Compiler.pm
blob: 2fc742246e72180c05940c97c0e68174c75dacf3 (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
package Text::Handlebars::Compiler;
use Any::Moose;

extends 'Text::Xslate::Compiler';

use Try::Tiny;

has '+syntax' => (
    default => 'Handlebars',
);

sub _generate_block {
    my $self = shift;
    my ($node) = @_;

    my @compiled = map { $self->compile_ast($_) } @{ $node->second };

    unshift @compiled, $self->_localize_vars($node->first)
        if $node->first;

    return @compiled;
}

sub _generate_include {
    my $self = shift;
    my ($node) = @_;

    my $file = $node->first;
    $file->id($file->id . $self->engine->{suffix})
        unless try { $self->engine->find_file($file->id); 1 };
    return $self->SUPER::_generate_include($node);
}

if (0) {
    our $_recursing;
    around compile_ast => sub {
        my $orig = shift;
        my $self = shift;

        my @ast = do {
            local $_recursing = 1;
            $self->$orig(@_);
        };
        use Data::Dump; ddx(\@ast) unless $_recursing;
        return @ast;
    };
}

__PACKAGE__->meta->make_immutable;
no Any::Moose;

1;