The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

SYNOPSIS

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

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

USAGE

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

OPTIONS

-h

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.

DESCRIPTION

This tool is similar to Perl Template Toolkit's tpage.pl 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:

    # astgen.pl
    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 astgen.pl, 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.

SEE ALSO

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

AUTHOR

Agent Zhang (ÕÂÒà´º), <agent2002@126.com>

COPYRIGHT

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 CP1252