1MakeMethods::Template::UTseexrtBCuoinltdreirb(u3t)ed PerMlakDeoMceutmheondtsa:t:iToenmplate::TextBuilder(3)
2
3
4

NAME

6       Class::MakeMethods::Template::TextBuilder - Basic text substitutions
7

SYNOPSIS

9        print text_builder( $base_text, @exprs )
10

DESCRIPTION

12       This module provides a single function, which implements a simple "text
13       macro" mechanism for assembling templated text strings.
14
15         $expanded_text = text_builder( $base_text, @exprs )
16
17       Returns a modified copy of $base_text using rules from the @exprs list.
18
19       The @exprs list may contain any of the following:
20
21       •   A string, in which any '*' characters will be replaced by the base
22           text. The interpolated string then replaces the base text.
23
24       •   A code-ref, which will be called with the base text as its only
25           argument. The result of that call then replaces the base text.
26
27       •   A hash-ref, which will be added to the substitution hash used in
28           the second pass, below.
29
30       •   An array-ref, containing additional expressions to be treated as
31           above.
32
33       After any initial string and code-ref rules have been applied, the hash
34       of substitution rules are applied.
35
36       The text will be searched for occurances of the keys of the
37       substitution hash, which will be modified based on the corresponding
38       value in the hash. If the substitution key ends with '{}', the search
39       will also match a balanced block of braces, and that value will also be
40       used in the substitution.
41
42       The hash-ref may contain the following types of rules:
43
44       •   'string' => 'string'
45
46           Occurances of the first string are to be replaced by the second.
47
48       •   'string' => code_ref
49
50           Occurances of the string are to be replaced by the results of
51           calling the subroutine with no arguments.
52
53       •   'string{}' => 'string'
54
55           Occurances of the first string and subsequent block of braces are
56           replaced by a copy of the second string in which any '*' characters
57           have first been replaced by the contents of the brace block.
58
59       •   'string{}' => code_ref
60
61           Occurances of the string and subsequent block of braces are
62           replaced by the results of calling the subroutine with the contents
63           of the brace block as its only argument.
64
65       •   'string{}' => hash_ref
66
67           Occurances of the string and subsequent block of braces are
68           replaced by using the contents of the brace block as a key into the
69           provided hash-ref.
70

EXAMPLE

72       The following text and modification rules provides a skeleton for a
73       collection letter:
74
75         my $letter = "You owe us AMOUNT. Please pay up!\n\n" .
76                         "THREAT{SEVERITY}";
77
78         my @exprs = (
79           "Dear NAMEm\n\n*",
80           "*\n\n-- The Management",
81
82           { 'THREAT{}' => { 'good'=>'Please?', 'bad'=>'Or else!' } },
83
84           "\t\t\t\tDATE\n*",
85           { 'DATE' => 'Tuesday, April 1, 2001' },
86         );
87
88       One might invoke this template by providing additional data for a given
89       instance and calling the text_builder function:
90
91         my $item = { 'NAME'=>'John', 'AMOUNT'=>'200 camels', 'SEVERITY'=>'bad' };
92
93         print text_builder( $letter, @exprs, $item );
94
95       The resulting output is shown below:
96
97                                         Tuesday, April 1, 2001
98         Dear John,
99
100         You owe us 200 camels. Please pay up!
101
102         Or else!
103
104         -- The Management
105

SEE ALSO

107       See Class::MakeMethods for general information about this distribution.
108
109
110
111perl v5.34.0                      2021-07-M2a2keMethods::Template::TextBuilder(3)
Impressum