> Having read this bit and also the PoD you posted I was wondering if it
> would be possible to take the op-tree you describe and compile to some
> other language similar to the way that Jemplate works.
Absolutely.
The "optree" is an arrayref of arrayrefs. The execute_tree method which runs
the tree looks like this:
sub execute_tree {
my ($self, $tree, $out_ref) = @_;
# node contains (0: DIRECTIVE,
# 1: start_index,
# 2: end_index,
# 3: parsed tag details,
# 4: sub tree for block types
# 5: continuation sub trees for sub continuation block
types (elsif, else, etc)
# 6: flag to capture next directive
for my $node (@$tree) {
### text nodes are just the bare text
if (! ref $node) {
warn "NODE: TEXT\n" if trace;
$$out_ref .= $node if defined $node;
next;
}
warn "NODE: $node->[0] (char $node->[1])\n" if trace;
$$out_ref .= $self->debug_node($node) if $self->{'_debug_dirs'} && !
$self->{'_debug_off'};
my $val = $DIRECTIVES->{$node->[0]}->[1]->($self, $node->[3], $node,
$out_ref);
$$out_ref .= $val if defined $val;
}
}
The $DIRECTIVES table looks like this:
$DIRECTIVES = {
#name #parse_sub #play_sub #block #postdir
#continue #move_to_front
BLOCK => [\&parse_BLOCK, \&play_BLOCK, 1, 0, 0,
1],
BREAK => [sub {}, \&play_control],
CALL => [\&parse_CALL, \&play_CALL],
CASE => [\&parse_CASE, undef, 0, 0,
{SWITCH => 1, CASE => 1}],
CATCH => [\&parse_CATCH, undef, 0, 0, {TRY
=> 1, CATCH => 1}],
CLEAR => [sub {}, \&play_CLEAR],
.... };
I will probably change those back to be pure overridable method lookups
instead of listing the callbacks in the table. That would allow you to
subclass CGI::Ex::Template and override each of the "play" blocks.
Or you can do arbitrary things with the optree.
Paul
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates