Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / Template::Provider.3pm
CommitLineData
3fea05b9 1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "Template::Provider 3"
132.TH Template::Provider 3 "2008-11-13" "perl v5.8.7" "User Contributed Perl Documentation"
133.SH "NAME"
134Template::Provider \- Provider module for loading/compiling templates
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 1
138\& $provider = Template::Provider\->new(\e%options);
139.Ve
140.PP
141.Vb 1
142\& ($template, $error) = $provider\->fetch($name);
143.Ve
144.SH "DESCRIPTION"
145.IX Header "DESCRIPTION"
146The Template::Provider is used to load, parse, compile and cache template
147documents. This object may be sub-classed to provide more specific facilities
148for loading, or otherwise providing access to templates.
149.PP
150The Template::Context objects maintain a list of Template::Provider
151objects which are polled in turn (via \fIfetch()\fR) to
152return a requested template. Each may return a compiled template, raise an
153error, or decline to serve the request, giving subsequent providers a chance
154to do so.
155.PP
156The Template::Provider can also be subclassed to provide templates from
157a different source, e.g. a database. See \s-1SUBCLASSING\s0 below.
158.PP
159This documentation needs work.
160.SH "PUBLIC METHODS"
161.IX Header "PUBLIC METHODS"
162.Sh "new(\e%options)"
163.IX Subsection "new(%options)"
164Constructor method which instantiates and returns a new \f(CW\*(C`Template::Provider\*(C'\fR
165object. A reference to a hash array of configuration options may be passed.
166.PP
167See \*(L"\s-1CONFIGURATION\s0 \s-1OPTIONS\s0\*(R" below for a summary of configuration options
168and Template::Manual::Config for full details.
169.Sh "fetch($name)"
170.IX Subsection "fetch($name)"
171Returns a compiled template for the name specified. If the template cannot be
172found then \f(CW\*(C`(undef, STATUS_DECLINED)\*(C'\fR is returned. If an error occurs (e.g.
173read error, parse error) then \f(CW\*(C`($error, STATUS_ERROR)\*(C'\fR is returned, where
174\&\f(CW$error\fR is the error message generated. If the \s-1TOLERANT\s0 option is set the
175the method returns \f(CW\*(C`(undef, STATUS_DECLINED)\*(C'\fR instead of returning an error.
176.ie n .Sh "store($name, $template)"
177.el .Sh "store($name, \f(CW$template\fP)"
178.IX Subsection "store($name, $template)"
179Stores the compiled template, \f(CW$template\fR, in the cache under the name,
180\&\f(CW$name\fR. Susbequent calls to \f(CW\*(C`fetch($name)\*(C'\fR will return this template in
181preference to any disk-based file.
182.Sh "include_path(\e@newpath)"
183.IX Subsection "include_path(@newpath)"
184Accessor method for the \f(CW\*(C`INCLUDE_PATH\*(C'\fR setting. If called with an
185argument, this method will replace the existing \f(CW\*(C`INCLUDE_PATH\*(C'\fR with
186the new value.
187.Sh "\fIpaths()\fP"
188.IX Subsection "paths()"
189This method generates a copy of the \f(CW\*(C`INCLUDE_PATH\*(C'\fR list. Any elements in the
190list which are dynamic generators (e.g. references to subroutines or objects
191implementing a \f(CW\*(C`paths()\*(C'\fR method) will be called and the list of directories
192returned merged into the output list.
193.PP
194It is possible to provide a generator which returns itself, thus sending
195this method into an infinite loop. To detect and prevent this from happening,
196the \f(CW$MAX_DIRS\fR package variable, set to \f(CW64\fR by default, limits the maximum
197number of paths that can be added to, or generated for the output list. If
198this number is exceeded then the method will immediately return an error
199reporting as much.
200.SH "CONFIGURATION OPTIONS"
201.IX Header "CONFIGURATION OPTIONS"
202The following list summarises the configuration options that can be provided
203to the \f(CW\*(C`Template::Provider\*(C'\fR \fInew()\fR constructor. Please consult
204Template::Manual::Config for further details and examples of each
205configuration option in use.
206.Sh "\s-1INCLUDE_PATH\s0"
207.IX Subsection "INCLUDE_PATH"
208The \s-1INCLUDE_PATH\s0 option is used to
209specify one or more directories in which template files are located.
210.PP
211.Vb 4
212\& # single path
213\& my $provider = Template::Provider\->new({
214\& INCLUDE_PATH => '/usr/local/templates',
215\& });
216.Ve
217.PP
218.Vb 5
219\& # multiple paths
220\& my $provider = Template::Provider\->new({
221\& INCLUDE_PATH => [ '/usr/local/templates',
222\& '/tmp/my/templates' ],
223\& });
224.Ve
225.Sh "\s-1ABSOLUTE\s0"
226.IX Subsection "ABSOLUTE"
227The \s-1ABSOLUTE\s0 flag is used to indicate if
228templates specified with absolute filenames (e.g. '\f(CW\*(C`/foo/bar\*(C'\fR') should be
229processed. It is disabled by default and any attempt to load a template by
230such a name will cause a '\f(CW\*(C`file\*(C'\fR' exception to be raised.
231.PP
232.Vb 3
233\& my $provider = Template::Provider\->new({
234\& ABSOLUTE => 1,
235\& });
236.Ve
237.Sh "\s-1RELATIVE\s0"
238.IX Subsection "RELATIVE"
239The \s-1RELATIVE\s0 flag is used to indicate if
240templates specified with filenames relative to the current directory (e.g.
241\&\f(CW\*(C`./foo/bar\*(C'\fR or \f(CW\*(C`../../some/where/else\*(C'\fR) should be loaded. It is also disabled
242by default, and will raise a \f(CW\*(C`file\*(C'\fR error if such template names are
243encountered.
244.PP
245.Vb 3
246\& my $provider = Template::Provider\->new({
247\& RELATIVE => 1,
248\& });
249.Ve
250.Sh "\s-1DEFAULT\s0"
251.IX Subsection "DEFAULT"
252The \s-1DEFAULT\s0 option can be used to specify
253a default template which should be used whenever a specified template can't be
254found in the \s-1INCLUDE_PATH\s0.
255.PP
256.Vb 3
257\& my $provider = Template::Provider\->new({
258\& DEFAULT => 'notfound.html',
259\& });
260.Ve
261.PP
262If a non-existant template is requested through the Template
263\&\fIprocess()\fR method, or by an \f(CW\*(C`INCLUDE\*(C'\fR, \f(CW\*(C`PROCESS\*(C'\fR or
264\&\f(CW\*(C`WRAPPER\*(C'\fR directive, then the \f(CW\*(C`DEFAULT\*(C'\fR template will instead be processed, if
265defined. Note that the \f(CW\*(C`DEFAULT\*(C'\fR template is not used when templates are
266specified with absolute or relative filenames, or as a reference to a input
267file handle or text string.
268.Sh "\s-1ENCODING\s0"
269.IX Subsection "ENCODING"
270The Template Toolkit will automatically decode Unicode templates that
271have a Byte Order Marker (\s-1BOM\s0) at the start of the file. This option
272can be used to set the default encoding for templates that don't define
273a \s-1BOM\s0.
274.PP
275.Vb 3
276\& my $provider = Template::Provider\->new({
277\& ENCODING => 'utf8',
278\& });
279.Ve
280.PP
281See Encode for further information.
282.Sh "\s-1CACHE_SIZE\s0"
283.IX Subsection "CACHE_SIZE"
284The \s-1CACHE_SIZE\s0 option can be used to
285limit the number of compiled templates that the module should cache. By
286default, the \s-1CACHE_SIZE\s0 is undefined
287and all compiled templates are cached.
288.PP
289.Vb 3
290\& my $provider = Template::Provider\->new({
291\& CACHE_SIZE => 64, # only cache 64 compiled templates
292\& });
293.Ve
294.Sh "\s-1STAT_TTL\s0"
295.IX Subsection "STAT_TTL"
296The \s-1STAT_TTL\s0 value can be set to control
297how long the \f(CW\*(C`Template::Provider\*(C'\fR will keep a template cached in memory
298before checking to see if the source template has changed.
299.PP
300.Vb 3
301\& my $provider = Template::Provider\->new({
302\& STAT_TTL => 60, # one minute
303\& });
304.Ve
305.Sh "\s-1COMPILE_EXT\s0"
306.IX Subsection "COMPILE_EXT"
307The \s-1COMPILE_EXT\s0 option can be
308provided to specify a filename extension for compiled template files.
309It is undefined by default and no attempt will be made to read or write
310any compiled template files.
311.PP
312.Vb 3
313\& my $provider = Template::Provider\->new({
314\& COMPILE_EXT => '.ttc',
315\& });
316.Ve
317.Sh "\s-1COMPILE_DIR\s0"
318.IX Subsection "COMPILE_DIR"
319The \s-1COMPILE_DIR\s0 option is used to
320specify an alternate directory root under which compiled template files should
321be saved.
322.PP
323.Vb 3
324\& my $provider = Template::Provider\->new({
325\& COMPILE_DIR => '/tmp/ttc',
326\& });
327.Ve
328.Sh "\s-1TOLERANT\s0"
329.IX Subsection "TOLERANT"
330The \s-1TOLERANT\s0 flag can be set to indicate
331that the \f(CW\*(C`Template::Provider\*(C'\fR module should ignore any errors encountered while
332loading a template and instead return \f(CW\*(C`STATUS_DECLINED\*(C'\fR.
333.Sh "\s-1PARSER\s0"
334.IX Subsection "PARSER"
335The \s-1PARSER\s0 option can be used to define
336a parser module other than the default of Template::Parser.
337.PP
338.Vb 3
339\& my $provider = Template::Provider\->new({
340\& PARSER => MyOrg::Template::Parser\->new({ ... }),
341\& });
342.Ve
343.Sh "\s-1DEBUG\s0"
344.IX Subsection "DEBUG"
345The \s-1DEBUG\s0 option can be used to enable
346debugging messages from the Template::Provider module by setting it to include
347the \f(CW\*(C`DEBUG_PROVIDER\*(C'\fR value.
348.PP
349.Vb 1
350\& use Template::Constants qw( :debug );
351.Ve
352.PP
353.Vb 3
354\& my $template = Template\->new({
355\& DEBUG => DEBUG_PROVIDER,
356\& });
357.Ve
358.SH "SUBCLASSING"
359.IX Header "SUBCLASSING"
360The \f(CW\*(C`Template::Provider\*(C'\fR module can be subclassed to provide templates from a
361different source (e.g. a database). In most cases you'll just need to provide
362custom implementations of the \f(CW\*(C`_template_modified()\*(C'\fR and \f(CW\*(C`_template_content()\*(C'\fR
363methods. If your provider requires and custom initialisation then you'll also
364need to implement a new \f(CW\*(C`_init()\*(C'\fR method.
365.PP
366Caching in memory and on disk will still be applied (if enabled)
367when overriding these methods.
368.Sh "_template_modified($path)"
369.IX Subsection "_template_modified($path)"
370Returns a timestamp of the \f(CW$path\fR passed in by calling \f(CW\*(C`stat()\*(C'\fR.
371This can be overridden, for example, to return a last modified value from
372a database. The value returned should be a timestamp value (as returned by \f(CW\*(C`time()\*(C'\fR,
373although a sequence number should work as well.
374.Sh "_template_content($path)"
375.IX Subsection "_template_content($path)"
376This method returns the content of the template for all \f(CW\*(C`INCLUDE\*(C'\fR, \f(CW\*(C`PROCESS\*(C'\fR,
377and \f(CW\*(C`INSERT\*(C'\fR directives.
378.PP
379When called in scalar context, the method returns the content of the template
380located at \f(CW$path\fR, or \f(CW\*(C`undef\*(C'\fR if \f(CW$path\fR is not found.
381.PP
382When called in list context it returns \f(CW\*(C`($content, $error, $mtime)\*(C'\fR,
383where \f(CW$content\fR is the template content, \f(CW$error\fR is an error string
384(e.g. "\f(CW\*(C`$path: File not found\*(C'\fR"), and \f(CW$mtime\fR is the template modification
385time.
386.SH "AUTHOR"
387.IX Header "AUTHOR"
388Andy Wardley <abw@wardley.org> <http://wardley.org/>
389.SH "COPYRIGHT"
390.IX Header "COPYRIGHT"
391Copyright (C) 1996\-2007 Andy Wardley. All Rights Reserved.
392.PP
393This module is free software; you can redistribute it and/or
394modify it under the same terms as Perl itself.
395.SH "SEE ALSO"
396.IX Header "SEE ALSO"
397Template, Template::Parser, Template::Context