Template::TAL::Language - base class for Template::TAL languages
my $tal = Template::TAL->new(); $tal->add_language(MyLanguage->new); $tal->process( $template, $data );
To be as flexible as possible, the tag handling in Template::TAL is implemented as Language modules, which declare the namespace and the tags that they wish to handle, and are called from the 'process_tag_node' method of Template::TAL::Template. So far, there is only one implemented language, Template::TAL::Language::TAL, and there is no easy way of changing which languages are loaded by Template::TAL in it's normal use, though I expect this to change in the near future. Specifically, when Template::TAL::Language::METAL is ready, support for adding Language modules will get a lot better.
Assuming you want to create a new Language, subclass this module, and override the namespace and tags methods, and provide process_tag_XXX methods for every tag your language contains. For instance:
package MyLanguage; use base qw( Template::TAL::Language ); sub namespace { 'http://foo.bar' } sub tags {qw( bar )} sub process_tag_bar { my ($self, $parent, $element, $value, $local_context, $global_context); return (); # just remove the node }
When loaded, this will apply to the template
<html xmlns:test="http://foo.bar"> <fred test:bar="1">this element will be removed</fred> </html>
Override these methods in a subclass
creates a new instance
return the namespace of the tags this module implements
return a list of tags in that namespace, in processing order, that this module handles.
called to process tags with the given tagname. The params are
Certian tag names, eg 'omit-tag', contain '-' characters, which will be converted to '_' characters for the method call, so define process_tag_omit_tag { .. }.
Written by Tom Insam, Copyright 2005 Fotango Ltd. All Rights Reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Template::TAL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Template::TAL
CPAN shell
perl -MCPAN -e shell install Template::TAL
For more information on module installation, please visit the detailed CPAN module installation guide.