| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#! perl |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package String::Interpolate::Named; |
|
4
|
|
|
|
|
|
|
|
|
5
|
8
|
|
|
8
|
|
74040
|
use warnings; |
|
|
8
|
|
|
|
|
20
|
|
|
|
8
|
|
|
|
|
317
|
|
|
6
|
8
|
|
|
8
|
|
48
|
use strict; |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
214
|
|
|
7
|
8
|
|
|
8
|
|
5018
|
use utf8; |
|
|
8
|
|
|
|
|
119
|
|
|
|
8
|
|
|
|
|
44
|
|
|
8
|
8
|
|
|
8
|
|
281
|
use Carp qw( carp croak ); |
|
|
8
|
|
|
|
|
17
|
|
|
|
8
|
|
|
|
|
468
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
8
|
|
|
8
|
|
3733
|
use parent 'Exporter'; |
|
|
8
|
|
|
|
|
2496
|
|
|
|
8
|
|
|
|
|
45
|
|
|
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.01'; |
|
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 no element is selected the values are concatenated. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 The Control Hash |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
The interpolation process requires two parameters: a hash with |
|
113
|
|
|
|
|
|
|
settings and values for the named arguments, and the string to be used |
|
114
|
|
|
|
|
|
|
as a template for interpolation. The hash will be further referred to |
|
115
|
|
|
|
|
|
|
as the I. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
The hash can have the following keys: |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=over |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item args |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This is either a hash that contains replacement texts for the named |
|
124
|
|
|
|
|
|
|
variables, or a subroutine that gets called with a variable as |
|
125
|
|
|
|
|
|
|
argument and returns a replacement value. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This element should be considered mandatory. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item separator |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
The separator used to concatenate list values, see L above. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
It defaults to Perl variable C<$"> that, on its turn, defaults to a |
|
134
|
|
|
|
|
|
|
single space. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item activator |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This is a single character that activates interpolation. By default |
|
139
|
|
|
|
|
|
|
this is the percent C<%> character. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item keypattern |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
The pattern to match key names. Default is C. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item maxiter |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
To enable nested substitutions and recursive replacement, the |
|
148
|
|
|
|
|
|
|
interpolation process is repeated until there are no more |
|
149
|
|
|
|
|
|
|
interpolations to be made. The maximun number of iterations is limited |
|
150
|
|
|
|
|
|
|
to the value of C. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
By default maxiter is 16. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=back |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
An example of a control hash: |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
my %ctl = |
|
159
|
|
|
|
|
|
|
( args => { |
|
160
|
|
|
|
|
|
|
customer => [ "Jones", "Smith" ], |
|
161
|
|
|
|
|
|
|
days => 2, |
|
162
|
|
|
|
|
|
|
title => "My Title", |
|
163
|
|
|
|
|
|
|
}, |
|
164
|
|
|
|
|
|
|
separator => ", ", |
|
165
|
|
|
|
|
|
|
); |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 Object Oriented API |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
my $ii = String::Interpolate::Named->new; |
|
170
|
|
|
|
|
|
|
$ii->ctl(\%ctl); |
|
171
|
|
|
|
|
|
|
$result = $ii->interpolate($template); |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
For convenience, the control hash may be passed to the constructor: |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
my $ii = String::Interpolate::Named->new(\%ctl); |
|
176
|
|
|
|
|
|
|
$result = $ii->interpolate($template); |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 Functional API |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
String::Interpolate::Named privides a single function, C, |
|
181
|
|
|
|
|
|
|
which is exported by default. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
The subroutine takes two arguments: a reference to a control hash and |
|
184
|
|
|
|
|
|
|
the template string. |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
$result = interpolate( \%ctl, $template ); |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 METHODS |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head2 new |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Constructs a new String::Interpolate::Named object. |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
my $ii = String::Interpolate::Named->new; |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
or |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
my $ii = String::Interpolate::Named->new(\%ctl); |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub new { |
|
205
|
2
|
|
|
2
|
1
|
1356
|
my ( $pkg, $ctl ) = @_; |
|
206
|
2
|
|
100
|
|
|
16
|
$ctl //= {}; |
|
207
|
2
|
|
|
|
|
8
|
bless $ctl => $pkg; |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head2 ctl |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Associates a control has with an existing object. |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
$ii->ctl(\%ctl); |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub ctl { |
|
219
|
1
|
|
|
1
|
1
|
38
|
my ( $self, $ctl ) = @_; |
|
220
|
1
|
|
|
|
|
45
|
$self->{$_} = $ctl->{$_} for keys(%$ctl); |
|
221
|
1
|
|
|
|
|
5
|
return $self; |
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head2 interpolate |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
This routine performs the actual interpolations. It can be used as a method: |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
$ii->interpolate($template); |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
and functional: |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
interpolate( \%ctl, $template ); |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=cut |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub interpolate { |
|
237
|
228
|
|
|
228
|
1
|
136310
|
my ( $ctl, $tpl ) = @_; |
|
238
|
|
|
|
|
|
|
|
|
239
|
228
|
|
50
|
|
|
1042
|
my $maxiter = $ctl->{maxiter} // 16; |
|
240
|
228
|
|
100
|
|
|
661
|
my $activator = $ctl->{activator} // '%'; |
|
241
|
228
|
|
66
|
|
|
1044
|
my $keypat = $ctl->{keypattern} // qr/\w+[-_\w.]*/; |
|
242
|
|
|
|
|
|
|
|
|
243
|
228
|
|
|
|
|
656
|
for ( my $cnt = 1; $cnt <= $maxiter; $cnt++ ) { |
|
244
|
|
|
|
|
|
|
|
|
245
|
447
|
|
|
|
|
748
|
my $prev = $tpl; |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
# Hide escaped specials by replacing them with Unicode noncharacters. |
|
248
|
447
|
|
|
|
|
833
|
$tpl =~ s/\\\\/\x{fdd0}/g; |
|
249
|
447
|
|
|
|
|
704
|
$tpl =~ s/\\\{/\x{fdd1}/g; |
|
250
|
447
|
|
|
|
|
691
|
$tpl =~ s/\\\}/\x{fdd2}/g; |
|
251
|
447
|
|
|
|
|
745
|
$tpl =~ s/\\\|/\x{fdd3}/g; |
|
252
|
447
|
|
|
|
|
1349
|
$tpl =~ s/\\\Q$activator\E/\x{fdd4}/g; |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
# Replace some seqs by a single char for easy matching. |
|
255
|
447
|
|
|
|
|
1136
|
$tpl =~ s/\Q$activator\E\{\}/\x{fdde}/g; |
|
256
|
447
|
|
|
|
|
1383
|
$tpl =~ s/\Q$activator\E\{/\x{fddf}/g; |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
# %{ key [ .index ] [ = value ] [ | then [ | else ] ] } |
|
259
|
|
|
|
|
|
|
|
|
260
|
447
|
|
|
|
|
3150
|
$tpl =~ s; ( \x{fddf} |
|
261
|
|
|
|
|
|
|
(? $keypat ) |
|
262
|
|
|
|
|
|
|
(?: (? \= ) |
|
263
|
|
|
|
|
|
|
(? [^|}\x{fddf}]*) )? |
|
264
|
|
|
|
|
|
|
(?: \| (? [^|}\x{fddf}]* ) |
|
265
|
|
|
|
|
|
|
(?: \| (? [^|}\x{fddf}]* ) )? |
|
266
|
|
|
|
|
|
|
)? |
|
267
|
|
|
|
|
|
|
\} |
|
268
|
|
|
|
|
|
|
) |
|
269
|
8
|
|
|
8
|
|
8050
|
; _interpolate($ctl, {%+} ) ;exo; |
|
|
8
|
|
|
|
|
3188
|
|
|
|
8
|
|
|
|
|
5778
|
|
|
|
219
|
|
|
|
|
3108
|
|
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
# Unescape escaped specials. |
|
272
|
447
|
|
|
|
|
1206
|
$tpl =~ s/\x{fdd0}/\\\\/g; |
|
273
|
447
|
|
|
|
|
715
|
$tpl =~ s/\x{fdd1}/\\\{/g; |
|
274
|
447
|
|
|
|
|
710
|
$tpl =~ s/\x{fdd2}/\\\}/g; |
|
275
|
447
|
|
|
|
|
740
|
$tpl =~ s/\x{fdd3}/\\\|/g; |
|
276
|
447
|
|
|
|
|
693
|
$tpl =~ s/\x{fdd4}/\\$activator/g; |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
# Restore (some) seqs. |
|
279
|
447
|
|
|
|
|
681
|
$tpl =~ s/\x{fdde}/$activator."{}"/ge; |
|
|
6
|
|
|
|
|
25
|
|
|
280
|
447
|
|
|
|
|
707
|
$tpl =~ s/\x{fddf}/$activator."{"/ge; |
|
|
33
|
|
|
|
|
102
|
|
|
281
|
|
|
|
|
|
|
|
|
282
|
447
|
100
|
|
|
|
983
|
if ( $prev eq $tpl ) { |
|
283
|
228
|
|
|
|
|
728
|
$tpl =~ s/\\(\Q$activator\E|[%{}|])/$1/g; |
|
284
|
228
|
|
|
|
|
1080
|
return $tpl; |
|
285
|
|
|
|
|
|
|
} |
|
286
|
219
|
50
|
|
|
|
730
|
warn("$cnt: $prev -> $tpl\n") if $ctl->{trace}; |
|
287
|
|
|
|
|
|
|
} |
|
288
|
0
|
|
|
|
|
0
|
Carp::croak("Maximum number of iterations exceeded"); |
|
289
|
|
|
|
|
|
|
} |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
sub _interpolate { |
|
292
|
219
|
|
|
219
|
|
499
|
my ( $ctl, $i ) = @_; |
|
293
|
219
|
|
50
|
|
|
639
|
my $key = $i->{key} // ''; |
|
294
|
219
|
|
|
|
|
361
|
my $m = $ctl->{args}; |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
# Establish the value for this key. |
|
297
|
219
|
|
|
|
|
343
|
my $val = ''; |
|
298
|
219
|
|
|
|
|
317
|
my $inx = 0; |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
# Split off possible index. |
|
301
|
219
|
100
|
|
|
|
579
|
if ( $key =~ /^(.*)\.(-?\d+)$/ ) { |
|
302
|
6
|
|
|
|
|
20
|
( $key, $inx ) = ( $1, $2 ); |
|
303
|
|
|
|
|
|
|
} |
|
304
|
|
|
|
|
|
|
|
|
305
|
219
|
100
|
|
|
|
1079
|
my $t = ref($m) eq 'CODE' ? $m->($key) : $m->{$key}; |
|
306
|
219
|
100
|
|
|
|
627
|
if ( defined $t ) { |
|
307
|
153
|
|
|
|
|
255
|
$val = $t; |
|
308
|
|
|
|
|
|
|
|
|
309
|
153
|
100
|
|
|
|
465
|
if ( UNIVERSAL::isa( $val, 'ARRAY' ) ) { |
|
|
|
50
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
# 1, 2, ... selects 1st, 2nd value; -1 counts from end. |
|
311
|
141
|
100
|
|
|
|
273
|
if ( $inx ) { |
|
312
|
5
|
100
|
66
|
|
|
23
|
if ( $inx > 0 && $inx <= @$val ) { |
|
313
|
3
|
|
|
|
|
7
|
$val = $val->[$inx-1]; |
|
314
|
|
|
|
|
|
|
} |
|
315
|
|
|
|
|
|
|
else { |
|
316
|
2
|
|
|
|
|
6
|
$val = $val->[$inx]; |
|
317
|
|
|
|
|
|
|
} |
|
318
|
|
|
|
|
|
|
} |
|
319
|
|
|
|
|
|
|
# Zero or none means concatenate all. |
|
320
|
|
|
|
|
|
|
else { |
|
321
|
136
|
|
66
|
|
|
632
|
$val = join( $ctl->{separator} // $", @$val ); |
|
322
|
|
|
|
|
|
|
} |
|
323
|
|
|
|
|
|
|
} |
|
324
|
|
|
|
|
|
|
elsif ( $inx ) { |
|
325
|
0
|
|
|
|
|
0
|
Carp::croak("Expecting an array for variable '$key'") |
|
326
|
|
|
|
|
|
|
} |
|
327
|
|
|
|
|
|
|
} |
|
328
|
|
|
|
|
|
|
|
|
329
|
219
|
|
|
|
|
361
|
my $subst = ''; |
|
330
|
219
|
100
|
|
|
|
510
|
if ( $i->{op} ) { |
|
|
|
100
|
|
|
|
|
|
|
331
|
66
|
|
50
|
|
|
200
|
my $test = $i->{test} // ''; |
|
332
|
66
|
100
|
66
|
|
|
268
|
if ( $i->{op} eq '=' && $val eq $test ) { |
|
333
|
30
|
|
100
|
|
|
96
|
$subst = $i->{then} // ''; |
|
334
|
|
|
|
|
|
|
} |
|
335
|
|
|
|
|
|
|
else { |
|
336
|
36
|
|
100
|
|
|
118
|
$subst = $i->{else} // ''; |
|
337
|
|
|
|
|
|
|
} |
|
338
|
|
|
|
|
|
|
} |
|
339
|
|
|
|
|
|
|
elsif ( $val ne '' ) { |
|
340
|
|
|
|
|
|
|
$subst = ($i->{then}//'') ne '' |
|
341
|
|
|
|
|
|
|
? $i->{then} |
|
342
|
104
|
50
|
100
|
|
|
467
|
: ($i->{else}//'') ne '' |
|
|
|
100
|
50
|
|
|
|
|
|
343
|
|
|
|
|
|
|
? '' : $val; |
|
344
|
|
|
|
|
|
|
} |
|
345
|
|
|
|
|
|
|
else { |
|
346
|
49
|
100
|
100
|
|
|
202
|
$subst = ($i->{else}//'') ne '' ? $i->{else} : ''; |
|
347
|
|
|
|
|
|
|
} |
|
348
|
|
|
|
|
|
|
|
|
349
|
219
|
|
|
|
|
505
|
$subst =~ s/\x{fdde}/$val/g; |
|
350
|
219
|
|
|
|
|
848
|
return $subst; |
|
351
|
|
|
|
|
|
|
} |
|
352
|
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
=head1 REQUIREMENTS |
|
354
|
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
Minimal Perl version 5.10.1. |
|
356
|
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
=head1 AUTHOR |
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
Johan Vromans, C<< >> |
|
360
|
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
=head1 SUPPORT |
|
362
|
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
Development of this module takes place on GitHub: |
|
364
|
|
|
|
|
|
|
L. |
|
365
|
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
367
|
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
perldoc String::Interpolate::Named |
|
369
|
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
Please report any bugs or feature requests using the issue tracker on |
|
371
|
|
|
|
|
|
|
GitHub. |
|
372
|
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
374
|
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
Many of the existing template / interpolate / substitute modules. |
|
376
|
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
378
|
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
Copyright 2018,2019 Johan Vromans, all rights reserved. |
|
380
|
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
382
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
383
|
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
=cut |
|
385
|
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
1; # End of String::Interpolate::Named |