Author image Yichun Zhang (章亦春)
and 1 contributors


astt - tpage-like tool that combines Perl AST with template file


    astt -h
    astt -t foo.ast > foo.htm
    astt -o test.htm -t test.ast

    # Apply multiple ASTs to one template file:
    astt -o foo -t ast1 ast2 ast3


  astt [-h] [-o <output-file>] -t <template-file> <ast-file1> <ast-file2> ...



Print this help to stdout.

-o output-file

Specify the output file name. I will print to stdout if this option is omitted.

-t template-file

Specify the Perl Template Toolkit template file.


This tool is similar to Perl Template Toolkit's script in some way, but is much more powerful. With tpage, one can only assign values to template variables using the --define option. Whereas, one has the ability to apply an extremely complicated Perl data structures (we will call it AST here) to the template file. Such data structure is defined in a separated file in the form of Perl codes. An example is as follows:

    $vars = [ { name => 'John', age => 17 }, { name => 'Marry', age => 12 } ];

The data structure must be assigned to a variable named $vars. Please don't use "my" or "our" to qualify the variable.

It is strongly recommended to utilize the Perl core module Data::Dumper to generate the AST automatically if the AST is huge. I'd like to give an instance here:

    use Data::Dumper;

    my $vars = ... # build the AST in a tricky way
    my $code = Data::Dumper->Dump([$vars], [qw(vars)]);
    open my $fh, '>foo.ast' or die $!;
    print $fh $code;
    close $fh;

After you run your, you will get a perfect AST file named foo.ast which can be used with my astt tool.

If multiple AST files are passed to astt, it will use the Template::Ast->merge method to merge the input files from left to right. The AST applied to the template file will the data structure after merging.


Template::Manual, Template::Ast, Data::Dumper


Agent Zhang (ÕÂÒà´º), <>


Copyright (C) 2005 by Agent Zhang.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 137:

Non-ASCII character seen before =encoding in '(ÕÂÒà´º),'. Assuming ISO8859-1