File Coverage

blib/lib/TemplateM.pm
Criterion Covered Total %
statement 78 193 40.4
branch 14 106 13.2
condition 15 84 17.8
subroutine 19 27 70.3
pod 0 5 0.0
total 126 415 30.3


line stmt bran cond sub pod time code
1             package TemplateM; # $Id: TemplateM.pm 10 2013-07-08 14:37:29Z abalama $
2 6     6   148750 use strict;
  6         19  
  6         939  
3            
4             =head1 NAME
5            
6             TemplateM - *ML templates processing module
7            
8             =head1 VERSION
9            
10             Version 3.03
11            
12             =head1 SYNOPSIS
13            
14             use TemplateM;
15             use TemplateM 'simple';
16            
17             my $template = new TemplateM(
18             -url => 'http://localhost/foo.shtml',
19             -utf8 => 1,
20             );
21            
22             my $template = new TemplateM( -file => 'ftp://login:password@192.168.1.1/foo.shtml' );
23             my $template = new TemplateM( -file => 'foo.shtml' );
24             my $template = new TemplateM( -file => \*DATA );
25            
26             # GALORE (DEFAULT):
27            
28             my $block = $template->start( 'block_label' );
29             $block->loop( foo => 'value1', bar => 'value2', ... );
30            
31             $template->stash( foo => 'value1', bar => 'value2', ... );
32             $block->stash( baz => 'value1', ... );
33            
34             $template->ifelse( "ifblock_label", $predicate )
35             $block->ifelse( "ifblock_label", $predicate )
36            
37             print $block->output;
38            
39             $block->finish;
40            
41             print $template->output;
42             print $template->html( "Content-type: text/html\n\n" );
43            
44             # OBSOLETE:
45            
46             $template->cast( {foo => 'value1', bar => 'value2', ... } );
47             my %h = ( ... );
48             $template->cast( \%h );
49            
50             $template->cast_loop ( "block_label", {foo => 'value1', bar => 'value2', ... } );
51             $template->finalize ( "block_label" );
52            
53             $template->cast_if( "block_label", $predicate );
54            
55             =head1 ABSTRACT
56            
57             The TemplateM module means for text templates processing in XML, HTML, TEXT and so on formats.
58             TemplateM is the alternative to most of standard modules, and it can accomplish remote access
59             to template files, has simple syntax, small size and flexibility. Then you use TemplateM,
60             functionality and data are completely separated, this is quality of up-to-date web-projects.
61            
62             =head1 TERMS
63            
64             =head2 Scheme
65            
66             Set of methods prodiving process template's structures.
67            
68             =head2 Template
69            
70             File or array of data which represents the set of instructions, directives and tags of markup
71             languages and statistics.
72            
73             =head2 Directive
74            
75             Name of structure in a template for substitution. There are a number of directives:
76            
77             cgi, val, do, loop, if, endif, else, endelse
78            
79             =head2 Structure
80            
81             Structure is the tag or the group of tags in a template which defining a scope of substitution.
82             The structure consist of tag and formatted content:
83            
84             DIRECTIVE: LABEL
85            
86             The structure can be simple or complex. Simple one is like this:
87            
88            
89             or
90            
91            
92             Complex structure is the group of simple structures which constitutive a "section"
93            
94            
95             ...
96            
97             ...
98            
99            
100             even so:
101            
102            
103             ...
104            
105            
106             ...
107            
108            
109             =head2 Label
110            
111             This is identifier of structure. E.g. foo, bar, baz
112            
113            
114            
115             =head1 DESCRIPTION
116            
117             =head2 SCHEMES
118            
119             While defining use it can specify 2 accessible schemes - galore (default) or simple.
120             It is not obligatory to point at default scheme.
121            
122             Simple scheme is basic and defines using of basic methods:
123            
124             C
125            
126             Simple scheme methods is expedient for small-datasize projects.
127            
128             Galore (default) scheme is the alternative for base scheme and it defines own set of methods:
129            
130             C
131            
132             In order to get knowing which of schemes is activated you need to invoke methods either module()
133             or scheme()
134            
135             my $module = $template->module;
136             my $module = $template->scheme;
137            
138             In order to get know real module name of the used scheme it's enough to read property 'module'
139             of $template object
140            
141             my $module = $template->{module};
142            
143             =head2 CONSTRUCTOR
144            
145             Constructor new() is the principal method independent of selected scheme. Almost simple way to use
146             the constructor is:
147            
148             my $template = new TemplateM( -template => "blah-blah-blah" );
149            
150             This invoking takes directive to use simple text as template.
151            
152             Below is the attribute list of constructor:
153            
154             =over 8
155            
156             =item B
157            
158             B designates either path or filehandle to file is passed for reading from disk, bypassing
159             the method of remote obtaining of a template.
160            
161             =item B
162            
163             B is the absolute or relative path to directory for cache files storage. This directory needs
164             to have a permission to read and write files.
165             When B is missed caching is disabled. Caching on is recommended for faster module operations.
166            
167             =item B
168            
169             B