This class models template strings.
Template strings may contain any ASCII text and any number of placeholders.
Placeholders are identified by %%ident%% where ident is [\w_]+, i.e. %%t_001%% .
Placeholders are defined in an array of HASH whereby an individual placeholder
is identified with an HASH {ident => <value>}.
<Value> may be a scalar or a CODE ref to a callback which is called
&<value>($self,<template string processed so far>).
The callback must return a scalar which is used to replace the placeholder itself.
The return value UNDEF is automatically turned to an empty string.
my $t = ctkTemplateString->new(<options>);
whereby <options> is
[fileName => <filepath of the file containing the template>]
[,template => <templates def string]
[,debug => debug mode 0|1]
[,placeHolderList => <array of placeholder definitions>]
$t->fileName(<file name of the template file>);
$t->getTemplateStringfromFile([<file name of the template file>]);
$t->placeHolderList(<array of the placeholder definition>);
$t->template(<template string>);
$t->placeHolderValues(<array of the placeholder definition>);
$t->replacePlaceholder([template string]);
$t->destroy
my $t = ctkTemplateString->new(
fileName => 'test_templateString.txt',
placeHolderList => [
{t000 => 'Marco'},
{t001 => 'Marazzi'},
{t003 => ' --- %%t004%% ---'},
{t004 => 'Zürich'},
{t005 => sub {return shift->getDateAndTime()}},
{t006 => \&subString}
],
debug => $debug);
my $s = $t->getTemplateStringfromFile();
$s = $t->replacePlaceHolder($s);
- Properties
-
template
placeHolderList
- Methods
-
new {
_init
getTemplateStringfromFile
placeHolderValues
replacePlaceHolder
verifyTemplate
- s Globals
-
debug (debug mode on/off)
- specialized classes : create a package for objects
which work with a specific template, whereby the template
is encapsulated in the class (or just its file name), and
a specific placeHolder list.
- specify the placeHolder list at construct time and update
it just before the message 'replacePlaceHolder'.
- callbacks: use callbacks to
- force the use of actual values,
- construct compound replacements,
- iteration and recursion.
Author: MARCO
date: 10.01.2007
History
11.01.2008 refactoring