line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#! perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package String::Interpolate::Named; |
4
|
|
|
|
|
|
|
|
5
|
8
|
|
|
8
|
|
102995
|
use warnings; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
330
|
|
6
|
8
|
|
|
8
|
|
48
|
use strict; |
|
8
|
|
|
|
|
27
|
|
|
8
|
|
|
|
|
203
|
|
7
|
8
|
|
|
8
|
|
5276
|
use utf8; |
|
8
|
|
|
|
|
123
|
|
|
8
|
|
|
|
|
43
|
|
8
|
8
|
|
|
8
|
|
339
|
use Carp qw( carp croak ); |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
535
|
|
9
|
|
|
|
|
|
|
|
10
|
8
|
|
|
8
|
|
3416
|
use parent 'Exporter'; |
|
8
|
|
|
|
|
2615
|
|
|
8
|
|
|
|
|
51
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw( interpolate ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
String::Interpolate::Named - Interpolated named arguments in string |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '1.03'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use String::Interpolate::Named; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $ctl = { args => { fn => "Johan", ln => "Bach" } }; |
26
|
|
|
|
|
|
|
say interpolate( $ctl, "The famous %{fn} %{ln}." ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# If you like object orientation. |
29
|
|
|
|
|
|
|
my $int = String::Interpolate::Named->new( { args => { ... } } ); |
30
|
|
|
|
|
|
|
say $int->interpolate("The famous %{fn} %{ln}."); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
String::Interpolate::Named provides a function to interpolate named |
35
|
|
|
|
|
|
|
I by I in a template string. The target texts |
36
|
|
|
|
|
|
|
are provided to the function via a hash, where the keys correspond to |
37
|
|
|
|
|
|
|
the named argument to be replaced, or a subroutine that performs the |
38
|
|
|
|
|
|
|
lookup. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 Named Arguments |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
The arguments to be replaced are marked in the template by enclosing |
43
|
|
|
|
|
|
|
them between C<%{> and C<}>. For example, the string C<"The famous |
44
|
|
|
|
|
|
|
%{fn} %{ln}."> contains two named arguments, C and C. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Note that the activator may be changed from C<%> into something else, |
47
|
|
|
|
|
|
|
see below. Throughout this document we use the default value. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 Basic Interpolation |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
When interpolated, the keys C and C are looked up in the hash, |
52
|
|
|
|
|
|
|
and the corresponding values are substituted. If no value was found |
53
|
|
|
|
|
|
|
for a named argument, nothing is substituted and the C<%{...}> is |
54
|
|
|
|
|
|
|
removed. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
You can precede C<%>, C<{>, C<}> (and C<|>, see below) with a |
57
|
|
|
|
|
|
|
backslash C<\> to hide their special meanings. For example, C<\}> will |
58
|
|
|
|
|
|
|
I be considered closing an argument but yield a plain C<}> in the |
59
|
|
|
|
|
|
|
text. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 Conditional Interpolation |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
It is possible to select replacement values depending on whether |
64
|
|
|
|
|
|
|
the named argument has a value or not: |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
"This book has %{title|title %{title}}" |
67
|
|
|
|
|
|
|
"This book has %{title|title %{title}|no title}" |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
These are considered C<%{if|then}> and C<%{if|then|else}> cases. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Assuming argument C has the value C<"My Book">, in the first |
72
|
|
|
|
|
|
|
example the text C<"title My Book">, the 'then' text, will be |
73
|
|
|
|
|
|
|
substituted, resulting in |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
"This book has title My Title" |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
If C does not have a value, the empty string is substituted. In |
78
|
|
|
|
|
|
|
the second example, the string C<"no title">, the 'else' text, will be |
79
|
|
|
|
|
|
|
substituted. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
As can be seen, the replacement texts may contain interpolations as |
82
|
|
|
|
|
|
|
well. For convenience, you can use C<%{}> to refer to the value of the |
83
|
|
|
|
|
|
|
named argument currently being examinated. The last example above can |
84
|
|
|
|
|
|
|
be written more shortly and elegantly as: |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
"This book has %{title|title %{}|no title}" |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 Testing Values |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Instead of testing for named variables to have a value, you can also |
91
|
|
|
|
|
|
|
test for specific values: |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
"This takes %{days=1|%{} day|%{} days}" |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 List Values |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
The replacement values hash may be scalar (in general: strings and |
98
|
|
|
|
|
|
|
numbers) or lists of scalars. If a value is a list of scalars, it is |
99
|
|
|
|
|
|
|
possible to select a particular value from the list by appending an |
100
|
|
|
|
|
|
|
index (period and a number) to the named argument. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Assume C has value C<[ "Jones", "Smith" ]>, then: |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
"%{customer.1} will be Smith" |
105
|
|
|
|
|
|
|
"%{customer.2} will be Jones" |
106
|
|
|
|
|
|
|
"%{customer} will be Jones Smith" |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
When the value exceeds the number of elements in the list, an empty |
109
|
|
|
|
|
|
|
value is returned. |
110
|
|
|
|
|
|
|
When no element is selected the values are concatenated. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 The Control Hash |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
The interpolation process requires two parameters: a hash with |
115
|
|
|
|
|
|
|
settings and values for the named arguments, and the string to be used |
116
|
|
|
|
|
|
|
as a template for interpolation. The hash will be further referred to |
117
|
|
|
|
|
|
|
as the I. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
The hash can have the following keys: |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=over |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item args |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This is either a hash that contains replacement texts for the named |
126
|
|
|
|
|
|
|
variables, or a subroutine that gets called with a variable as |
127
|
|
|
|
|
|
|
argument and returns a replacement value. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This element should be considered mandatory. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item separator |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
The separator used to concatenate list values, see L above. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
It defaults to Perl variable C<$"> that, on its turn, defaults to a |
136
|
|
|
|
|
|
|
single space. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item activator |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This is a single character that activates interpolation. By default |
141
|
|
|
|
|
|
|
this is the percent C<%> character. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item keypattern |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
The pattern to match key names. Default is C. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item maxiter |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
To enable nested substitutions and recursive replacement, the |
150
|
|
|
|
|
|
|
interpolation process is repeated until there are no more |
151
|
|
|
|
|
|
|
interpolations to be made. The maximun number of iterations is limited |
152
|
|
|
|
|
|
|
to the value of C. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
By default maxiter is 16. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
An example of a control hash: |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
my %ctl = |
161
|
|
|
|
|
|
|
( args => { |
162
|
|
|
|
|
|
|
customer => [ "Jones", "Smith" ], |
163
|
|
|
|
|
|
|
days => 2, |
164
|
|
|
|
|
|
|
title => "My Title", |
165
|
|
|
|
|
|
|
}, |
166
|
|
|
|
|
|
|
separator => ", ", |
167
|
|
|
|
|
|
|
); |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 Object Oriented API |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
my $ii = String::Interpolate::Named->new; |
172
|
|
|
|
|
|
|
$ii->ctl(\%ctl); |
173
|
|
|
|
|
|
|
$result = $ii->interpolate($template); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
For convenience, the control hash may be passed to the constructor: |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
my $ii = String::Interpolate::Named->new(\%ctl); |
178
|
|
|
|
|
|
|
$result = $ii->interpolate($template); |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 Functional API |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
String::Interpolate::Named privides a single function, C, |
183
|
|
|
|
|
|
|
which is exported by default. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
The subroutine takes two arguments: a reference to a control hash and |
186
|
|
|
|
|
|
|
the template string. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
$result = interpolate( \%ctl, $template ); |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 METHODS |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 new |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Constructs a new String::Interpolate::Named object. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
my $ii = String::Interpolate::Named->new; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
or |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
my $ii = String::Interpolate::Named->new(\%ctl); |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub new { |
207
|
2
|
|
|
2
|
1
|
1220
|
my ( $pkg, $ctl ) = @_; |
208
|
2
|
|
100
|
|
|
13
|
$ctl //= {}; |
209
|
2
|
|
|
|
|
6
|
bless $ctl => $pkg; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 ctl |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Associates a control has with an existing object. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
$ii->ctl(\%ctl); |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=cut |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub ctl { |
221
|
1
|
|
|
1
|
1
|
14
|
my ( $self, $ctl ) = @_; |
222
|
1
|
|
|
|
|
9
|
$self->{$_} = $ctl->{$_} for keys(%$ctl); |
223
|
1
|
|
|
|
|
3
|
return $self; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head2 interpolate |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
This routine performs the actual interpolations. It can be used as a method: |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
$ii->interpolate($template); |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
and functional: |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
interpolate( \%ctl, $template ); |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=cut |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub interpolate { |
239
|
289
|
|
|
289
|
1
|
167230
|
my ( $ctl, $tpl ) = @_; |
240
|
|
|
|
|
|
|
|
241
|
289
|
|
50
|
|
|
1306
|
my $maxiter = $ctl->{maxiter} // 16; |
242
|
289
|
|
100
|
|
|
1021
|
my $activator = $ctl->{activator} // '%'; |
243
|
289
|
|
66
|
|
|
1415
|
my $keypat = $ctl->{keypattern} // qr/\w+[-_\w.]*/; |
244
|
|
|
|
|
|
|
|
245
|
289
|
|
|
|
|
878
|
for ( my $cnt = 1; $cnt <= $maxiter; $cnt++ ) { |
246
|
|
|
|
|
|
|
|
247
|
534
|
|
|
|
|
959
|
my $prev = $tpl; |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
# Hide escaped specials by replacing them with Unicode noncharacters. |
250
|
534
|
|
|
|
|
1031
|
$tpl =~ s/\\\\/\x{fdd0}/g; |
251
|
534
|
|
|
|
|
880
|
$tpl =~ s/\\\{/\x{fdd1}/g; |
252
|
534
|
|
|
|
|
813
|
$tpl =~ s/\\\}/\x{fdd2}/g; |
253
|
534
|
|
|
|
|
898
|
$tpl =~ s/\\\|/\x{fdd3}/g; |
254
|
534
|
|
|
|
|
1547
|
$tpl =~ s/\\\Q$activator\E/\x{fdd4}/g; |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
# Replace some seqs by a single char for easy matching. |
257
|
534
|
|
|
|
|
1325
|
$tpl =~ s/\Q$activator\E\{\}/\x{fdde}/g; |
258
|
534
|
|
|
|
|
1531
|
$tpl =~ s/\Q$activator\E\{/\x{fddf}/g; |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
# %{ key [ .index ] [ = value ] [ | then [ | else ] ] } |
261
|
|
|
|
|
|
|
|
262
|
534
|
|
|
|
|
926
|
my $pre = ''; |
263
|
534
|
|
|
|
|
790
|
my $post = ''; |
264
|
534
|
100
|
|
|
|
3755
|
if ( $tpl =~ s; ( ^ |
265
|
|
|
|
|
|
|
(? .*? ) |
266
|
|
|
|
|
|
|
\x{fddf} |
267
|
|
|
|
|
|
|
(? $keypat ) |
268
|
|
|
|
|
|
|
(?: (? \= ) |
269
|
|
|
|
|
|
|
(? [^|}\x{fddf}]*) )? |
270
|
|
|
|
|
|
|
(?: \| (? [^|}\x{fddf}]* ) |
271
|
|
|
|
|
|
|
(?: \| (? [^|}\x{fddf}]* ) )? |
272
|
|
|
|
|
|
|
)? |
273
|
|
|
|
|
|
|
\} |
274
|
|
|
|
|
|
|
(? .* ) |
275
|
|
|
|
|
|
|
$ |
276
|
|
|
|
|
|
|
) |
277
|
8
|
|
|
8
|
|
8812
|
; _interpolate($ctl, {%+} ) ;exso ) { |
|
8
|
|
|
|
|
4237
|
|
|
8
|
|
|
|
|
6289
|
|
|
245
|
|
|
|
|
4340
|
|
278
|
245
|
|
|
|
|
1041
|
$pre = $+{pre}; |
279
|
245
|
|
|
|
|
952
|
$post = $+{post}; |
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
else { |
282
|
289
|
|
|
|
|
522
|
$pre = $tpl; |
283
|
289
|
|
|
|
|
471
|
$tpl = ''; |
284
|
|
|
|
|
|
|
} |
285
|
534
|
|
|
|
|
1689
|
for ( $pre, $tpl, $post ) { |
286
|
|
|
|
|
|
|
# Unescape escaped specials. |
287
|
1602
|
|
|
|
|
2507
|
s/\x{fdd0}/\\\\/g; |
288
|
1602
|
|
|
|
|
2239
|
s/\x{fdd1}/\\\{/g; |
289
|
1602
|
|
|
|
|
2268
|
s/\x{fdd2}/\\\}/g; |
290
|
1602
|
|
|
|
|
2307
|
s/\x{fdd3}/\\\|/g; |
291
|
1602
|
|
|
|
|
2257
|
s/\x{fdd4}/\\$activator/g; |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
# Restore (some) seqs. |
294
|
1602
|
|
|
|
|
2262
|
s/\x{fdde}/$activator."{}"/ge; |
|
6
|
|
|
|
|
21
|
|
295
|
1602
|
|
|
|
|
2562
|
s/\x{fddf}/$activator."{"/ge; |
|
43
|
|
|
|
|
161
|
|
296
|
|
|
|
|
|
|
} |
297
|
534
|
|
|
|
|
1631
|
$tpl =~ s/\\(\Q$activator\E|[{}|\\])/$1/g; |
298
|
534
|
50
|
|
|
|
1249
|
warn ("'$prev' => '$pre' '$tpl' '$post'\n" ) if $ctl->{trace}; |
299
|
|
|
|
|
|
|
|
300
|
534
|
|
|
|
|
1152
|
my $t = $pre . $tpl . $post; |
301
|
534
|
100
|
|
|
|
1203
|
if ( $prev eq $t ) { |
302
|
|
|
|
|
|
|
# De-escape in subst part only (issue #6); |
303
|
289
|
|
|
|
|
713
|
$tpl =~ s/\\(\Q$activator\E|[{}|])/$1/g; |
304
|
289
|
|
|
|
|
1632
|
return $pre . $tpl . $post; |
305
|
|
|
|
|
|
|
} |
306
|
245
|
|
|
|
|
414
|
$tpl = $t; |
307
|
245
|
50
|
|
|
|
906
|
warn("$cnt: $prev -> $tpl\n") if $ctl->{trace}; |
308
|
|
|
|
|
|
|
} |
309
|
0
|
|
|
|
|
0
|
Carp::croak("Maximum number of iterations exceeded"); |
310
|
|
|
|
|
|
|
} |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
sub _interpolate { |
313
|
245
|
|
|
245
|
|
618
|
my ( $ctl, $i ) = @_; |
314
|
245
|
|
50
|
|
|
701
|
my $key = $i->{key} // ''; |
315
|
245
|
|
|
|
|
423
|
my $m = $ctl->{args}; |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
# Establish the value for this key. |
318
|
245
|
|
|
|
|
375
|
my $val = ''; |
319
|
245
|
|
|
|
|
347
|
my $inx = 0; |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
# Split off possible index. |
322
|
245
|
100
|
|
|
|
648
|
if ( $key =~ /^(.*)\.(-?\d+)$/ ) { |
323
|
7
|
|
|
|
|
23
|
( $key, $inx ) = ( $1, $2 ); |
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
|
326
|
245
|
100
|
|
|
|
829
|
my $t = ref($m) eq 'CODE' ? $m->($key) : $m->{$key}; |
327
|
245
|
100
|
|
|
|
790
|
if ( defined $t ) { |
328
|
174
|
|
|
|
|
270
|
$val = $t; |
329
|
|
|
|
|
|
|
|
330
|
174
|
100
|
|
|
|
536
|
if ( UNIVERSAL::isa( $val, 'ARRAY' ) ) { |
|
|
50
|
|
|
|
|
|
331
|
|
|
|
|
|
|
# 1, 2, ... selects 1st, 2nd value; -1 counts from end. |
332
|
161
|
100
|
|
|
|
305
|
if ( $inx ) { |
333
|
6
|
100
|
|
|
|
22
|
if ( $inx > 0 ) { |
334
|
4
|
100
|
|
|
|
10
|
if ( $inx <= @$val ) { |
335
|
3
|
|
|
|
|
7
|
$val = $val->[$inx-1]; |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
else { |
338
|
1
|
|
|
|
|
3
|
$val = ""; |
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
|
else { |
342
|
2
|
|
|
|
|
6
|
$val = $val->[$inx]; |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
# Zero or none means concatenate all. |
346
|
|
|
|
|
|
|
else { |
347
|
155
|
|
66
|
|
|
695
|
$val = join( $ctl->{separator} // $", @$val ); |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
} |
350
|
|
|
|
|
|
|
elsif ( $inx ) { |
351
|
0
|
|
|
|
|
0
|
Carp::croak("Expecting an array for variable '$key'") |
352
|
|
|
|
|
|
|
} |
353
|
|
|
|
|
|
|
} |
354
|
|
|
|
|
|
|
|
355
|
245
|
|
|
|
|
414
|
my $subst = ''; |
356
|
245
|
100
|
|
|
|
574
|
if ( $i->{op} ) { |
|
|
100
|
|
|
|
|
|
357
|
66
|
|
50
|
|
|
195
|
my $test = $i->{test} // ''; |
358
|
66
|
100
|
66
|
|
|
268
|
if ( $i->{op} eq '=' && $val eq $test ) { |
359
|
30
|
|
100
|
|
|
112
|
$subst = $i->{then} // ''; |
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
else { |
362
|
36
|
|
100
|
|
|
117
|
$subst = $i->{else} // ''; |
363
|
|
|
|
|
|
|
} |
364
|
|
|
|
|
|
|
} |
365
|
|
|
|
|
|
|
elsif ( $val ne '' ) { |
366
|
124
|
|
100
|
|
|
411
|
$subst = $i->{then} // $val; |
367
|
|
|
|
|
|
|
} |
368
|
|
|
|
|
|
|
else { |
369
|
55
|
|
100
|
|
|
187
|
$subst = $i->{else} // ''; |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
|
372
|
245
|
|
|
|
|
564
|
$subst =~ s/\x{fdde}/$val/g; |
373
|
245
|
|
|
|
|
1073
|
return $subst; |
374
|
|
|
|
|
|
|
} |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
=head1 REQUIREMENTS |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
Minimal Perl version 5.10.1. |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
=head1 AUTHOR |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
Johan Vromans, C<< >> |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
=head1 SUPPORT |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
Development of this module takes place on GitHub: |
387
|
|
|
|
|
|
|
L. |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
perldoc String::Interpolate::Named |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
Please report any bugs or feature requests using the issue tracker on |
394
|
|
|
|
|
|
|
GitHub. |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
Many of the existing template / interpolate / substitute modules. |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
Copyright 2018,2019 Johan Vromans, all rights reserved. |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
405
|
|
|
|
|
|
|
under the same terms as Perl itself. |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
=cut |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
1; # End of String::Interpolate::Named |