File Coverage

blib/lib/Template/TAL/Language.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 6 66.6
pod 3 3 100.0
total 17 21 80.9


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Template::TAL::Language - base class for Template::TAL languages
4              
5             =head1 SYNOPSIS
6              
7             my $tal = Template::TAL->new();
8             $tal->add_language(MyLanguage->new);
9             $tal->process( $template, $data );
10              
11             =head1 DESCRIPTION
12              
13             To be as flexible as possible, the tag handling in Template::TAL is
14             implemented as Language modules, which declare the namespace and the
15             tags that they wish to handle, and are called from the 'process_tag_node'
16             method of Template::TAL::Template. So far, there is only one
17             implemented language, L, and there is no
18             easy way of changing which languages are loaded by Template::TAL in
19             it's normal use, though I expect this to change in the near future.
20             Specifically, when L is ready, support
21             for adding Language modules will get a lot better.
22              
23             =head1 SUBCLASSING
24              
25             Assuming you want to create a new Language, subclass this module, and
26             override the L and L methods, and provide process_tag_XXX
27             methods for every tag your language contains. For instance:
28              
29             package MyLanguage;
30             use base qw( Template::TAL::Language );
31            
32             sub namespace { 'http://foo.bar' }
33             sub tags {qw( bar )}
34             sub process_tag_bar {
35             my ($self, $parent, $element, $value, $local_context, $global_context);
36             return (); # just remove the node
37             }
38            
39             When loaded, this will apply to the template
40              
41            
42             this element will be removed
43            
44              
45             =cut
46              
47             package Template::TAL::Language;
48 1     1   9 use warnings;
  1         2  
  1         34  
49 1     1   5 use strict;
  1         2  
  1         35  
50 1     1   5 use Carp qw( croak );
  1         2  
  1         150  
51              
52             =head1 METHODS
53              
54             Override these methods in a subclass
55              
56             =over
57              
58             =item new()
59              
60             creates a new instance
61              
62             =cut
63              
64             sub new {
65 1     1 1 671 return bless {}, shift;
66             }
67              
68             =item namespace
69              
70             return the namespace of the tags this module implements
71              
72             =cut
73              
74 0     0 1   sub namespace { return }
75              
76             =item tags
77              
78             return a list of tags in that namespace, in processing order, that this module
79             handles.
80              
81             =cut
82              
83 0     0 1   sub tags { () }
84              
85             =item process_tag_( caller, element, value, local_context, global_context )
86              
87             called to process tags with the given tagname. The params are
88              
89             =over
90              
91             =item element - the XML::LibXML::Element being processed
92              
93             =item value - the string value of the attribute
94              
95             =item local_context - the local context hash, use this for preference
96              
97             =item global_context - the global context hash
98              
99             =back
100              
101             Certian tag names, eg 'omit-tag', contain '-' characters, which will be converted
102             to '_' characters for the method call, so define process_tag_omit_tag { .. }.
103              
104             =cut
105              
106             # sub process_tag_foo { ..
107              
108             =back
109              
110             =head1 COPYRIGHT
111              
112             Written by Tom Insam, Copyright 2005 Fotango Ltd. All Rights Reserved
113              
114             This program is free software; you can redistribute
115             it and/or modify it under the same terms as Perl itself.
116              
117             =cut
118              
119             1;