lib/App/WebPerimeterScan/I18N.pm

filter: Statementstmt 100% 108 / 108 Branchbran 93.7% 30 / 32 Conditioncond 74.3% 29 / 39 MC/DCmcdc 45.8% 11 / 24 Subroutinesub 100% 27 / 27 Podpod 100% 4 / 4 totaltotal 89.3% 209 / 234 CC 33 SCAR 16.6
CC
33
Cov
93%
_select_form
12.6
_wanted_languages
8.1
i18n
7.0
CRAP 5.3
« lib/App/WebPerimeterScan/HTTP.pm ↑ Summary lib/App/WebPerimeterScan/Findings.pm »
1 package App::WebPerimeterScan::I18N;
2  
3 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 34 ▶use autodie qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 34 ▶use Carp qw(carp confess croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 34 ▶use Params::Get qw(get_params);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 34 ▶use Params::Validate::Strict qw(validate_strict);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 34 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 34 ▶use Sub::Private { mode => 'enforce' };
Subroutine BEGIN: called CC=1 SCAR=0.0
12 34 ▶use Sub::Protected;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 34 ▶use App::WebPerimeterScan::Messages ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 34 our $VERSION = '0.001.0';
17  
18 # Run-time settings. A plain hash rather than Readonly so that a caller, or
19 # Object::Configure, can pin a language for a whole run.
20 34 our %config = (
21 # undef: take the language from the environment on every call.
22 language => undef,
23 # The catalogue every other language falls back to, key by key.
24 fallback => 'en',
25 );
26  
27 # Where the language comes from, most specific first. LANGUAGE is GNU
28 # gettext's colon-separated preference list; the rest are POSIX.
29 34 Readonly::Array my @LOCALE_VARIABLES => qw(LANGUAGE LC_ALL LC_MESSAGES LANG);
30  
31 # Locale names that mean "no preference", so they must not select a catalogue.
32 34 Readonly::Hash my %NEUTRAL_LOCALE => (C => 1, POSIX => 1);
33  
34 # {name} or {name:%.1f} - the optional part is handed to sprintf.
35 34 Readonly::Scalar my $PLACEHOLDER => qr/\{(\w+)(?::(%[^{}]+))?\}/;
36  
37 # The form every selector falls back to, as in ICU MessageFormat.
38 34 Readonly::Scalar my $OTHER_FORM => 'other';
39  
40 # Carp's location suffix: " at FILE line N." with an optional trailing period
41 # and newline, and optionally ", <FH> line N." when a handle was being read.
42 34 Readonly::Scalar my $CARP_SUFFIX => qr/\s+at\s+\S.*?\s+line\s+\d+(?:,\s+<[^>]*>\s+(?:line|chunk)\s+\d+)?\.?\s*\z/s;
43  
44 # Plural rules by language: count in, CLDR category out. Only the languages
45 # with a catalogue need one; any other language uses the fallback's rule,
46 # because the words come from the fallback catalogue too.
47 our %PLURAL_RULE = (
48 16 ▶ en => sub { return $_[0] == 1 ? 'one' : $OTHER_FORM },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] == 1 ? : 7 9 16
49 34 );
50  
51 =encoding utf8
52  
53 =head1 NAME
54  
55 App::WebPerimeterScan::I18N - message catalogue lookup and the shared error handler
56  
57 =head1 VERSION
58  
59 Version 0.001.0
60  
61 =head1 SYNOPSIS
62  
63 Render a message with values:
64  
65 use App::WebPerimeterScan::I18N;
66  
67 my $i18n = 'App::WebPerimeterScan::I18N';
68 print $i18n->i18n('scope.not_listed', {
69 host => 'evil.example',
70 source => 'scope.txt',
71 }), "\n";
72  
73 Let the count choose between singular and plural:
74  
75 # "1 endpoint defined in source was not scanned"
76 # "3 endpoints defined in source were not scanned"
77 print $i18n->i18n('source-routes-unvisited.title', { count => 3 }), "\n";
78  
79 Choose the language, whatever the environment says:
80  
81 $App::WebPerimeterScan::I18N::config{language} = 'de';
82 print $i18n->language, "\n"; # 'de' if a German catalogue exists, else 'en'
83  
84 Remove the "at FILE line N." that C<croak> adds, before you show an error
85 to a person:
86  
87 eval { $scope->load_file('missing.txt'); 1 }
88 or print App::WebPerimeterScan::I18N::clean_error($@), "\n";
89  
90 Write a module that throws catalogued errors:
91  
92 package App::WebPerimeterScan::Example;
93  
94 use parent 'App::WebPerimeterScan::I18N';
95  
96 sub load
97 {
98 my ($self, $file) = @_;
99  
100 # croak()s with the catalogue text for the user's language
101 $self->_throw('scope.empty', { file => $file }) unless -s $file;
102  
103 return $self;
104 }
105  
106 # Any class or object in the distribution can render a message
107 print App::WebPerimeterScan::I18N->i18n('report.summary', { summary => '0 high' }), "\n";
108  
109 =head1 DESCRIPTION
110  
111 Every user-facing string in the distribution - finding titles, error
112 messages, report labels and the command-line usage text - lives in
113 L<App::WebPerimeterScan::Messages> under a stable key. This class looks the
114 key up for the user's language, fills in the placeholders and chooses the
115 plural or gender form, so no other module holds English text.
116  
117 It is also the base class of every module in the distribution, which is what
118 gives each of them C<i18n> and the protected C<_throw> and C<_warn> helpers.
119 Those helpers are the only places that call C<croak> and C<carp>.
120  
121 =head2 Message format
122  
123 A message is either a string or a selector.
124  
125 A string may contain C<{name}>, replaced by the argument of that name, or
126 C<{name:%.1f}>, where the part after the colon is a C<sprintf> format applied
127 to the argument. A placeholder whose argument was not given is left in the
128 text as it is, so a missing value is visible rather than silently empty.
129  
130 A selector is a hash:
131  
132 { plural => 'count', forms => { one => '{count} file', other => '{count} files' } }
133 { select => 'gender', forms => { female => 'her', male => 'his', other => 'their' } }
134  
135 C<plural> applies the language's plural rule to the named argument to choose
136 the form; C<select> uses the argument's value as the form name. Either falls
137 back to C<other>, and the chosen form may itself be a selector.
138  
139 =cut
140  
141 =head1 SUBROUTINES/METHODS
142  
143 =head2 language
144  
145 Purpose: report which catalogue C<i18n> will read.
146  
147 Args: none (callable as a class or an object method).
148  
149 Returns: a language code such as C<en>; always one that has a catalogue.
150  
151 Side Effects: none. The environment is read on each call so a test can
152 change C<LC_ALL> between calls.
153  
154 Usage: C<< my $lang = App::WebPerimeterScan::I18N->language; >>
155  
156 =head3 EXAMPLE
157  
158 local $ENV{LC_ALL} = 'de_DE.UTF-8';
159 # 'en' until a German catalogue is installed
160 print App::WebPerimeterScan::I18N->language, "\n";
161  
162 =head3 API SPECIFICATION
163  
164 =head4 INPUT
165  
166 {}
167  
168 =head4 OUTPUT
169  
170 { type => 'string', matches => qr/\A[a-z]{2,3}\z/ }
171  
172 =head3 MESSAGES
173  
174 None.
175  
176 =cut
177  
178 sub language
179 2076 ▶{
Subroutine language: called CC=2 SCAR=7.0
Pod documented
180 2076 my ($self) = @_;
181  
182 2076 my $catalogue = \%App::WebPerimeterScan::Messages::CATALOGUE;
183  
184 # The first preference with a catalogue wins; the fallback always exists.
185 2076 my ($chosen) = grep { exists $catalogue->{$_} } @{ _wanted_languages() };
186  
187 2076 ▶ return $chosen // $config{fallback};
Condition66%2/3
$chosen // $App::WebPerimeterScan::I18N::config{"fallback"}
l!l&&r!l&&!r
1320630
MC/DC0%0/2
$chosen // $App::WebPerimeterScan::I18N::config{"fallback"}
$chosen $App::WebPerimeterScan::I18N::config{"fallback"}
Truth table66%2/3
A // B
A= $chosenB= $App::WebPerimeterScan::I18N::config{"fallback"}
ABresult
1X1
011
000
188 }
189  
190 =head2 i18n
191  
192 Purpose: return the text of a message key in the user's language, with its
193 placeholders filled in.
194  
195 Args: C<$key> (string) and an optional hash reference of named arguments.
196  
197 Returns: the rendered string.
198  
199 Side Effects: C<confess>es when no catalogue - not even the fallback - holds
200 the key, because that is a programming error and the stack trace is what
201 finds it.
202  
203 Usage: C<< $self->i18n('scope.empty', { file => $file }) >>
204  
205 =head3 EXAMPLE
206  
207 my $text = App::WebPerimeterScan::I18N->i18n(
208 'source-routes-unvisited.title', { count => 3 },
209 );
210 # "3 endpoints defined in source were not scanned"
211  
212 =head3 API SPECIFICATION
213  
214 =head4 INPUT
215  
216 {
217 key => { type => 'string', min => 1, position => 0 },
218 args => { type => 'hashref', optional => 1, position => 1 },
219 }
220  
221 =head4 OUTPUT
222  
223 { type => 'string' }
224  
225 =head3 MESSAGES
226  
227 Message Meaning / resolution
228 ----------------------------------- ---------------------------------------
229 No message is defined for "KEY" The key is in no catalogue. Add it to
230 App::WebPerimeterScan::Messages (en).
231  
232 =head3 PSEUDOCODE
233  
234 look the key up in the user's catalogue, then in the fallback
235 confess if neither has it
236 while the message is a selector
237 choose the form named by the plural rule or the argument value
238 use 'other' if that form does not exist
239 replace each {name} or {name:format} that has an argument
240  
241 =cut
242  
243 sub i18n
244 1500 ▶{
Subroutine i18n: called CC=7 SCAR=19.5
Pod documented
245 1500 my ($self, $key, $args) = @_;
246  
247 # Validated by hand rather than with validate_strict: this runs for
248 # every string in every report, and the two checks are all it needs.
249 1500 my $language = $self->language;
250 1500 ▶ $args = {} unless ref $args eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args eq "HASH" 144 1356 1500
251  
252 # A missing key is a programming error, so the full stack trace is
253 # worth more than a short message. The text itself is catalogued too.
254 1500 ▶ my $message = (defined $key && length $key) ? _lookup($language, $key) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $key && length $key ? : 1499 1 1500
Condition66%2/3
defined $key and length $key
!ll&&!rl&&r
101499
MC/DC50%1/2
defined $key and length $key
defined $key length $key
Truth table66%2/3
A and B
A= defined $keyB= length $key
ABresult
0X0
100
111
255 1500 ▶ confess(_render(_lookup($config{fallback}, 'i18n.missing_key'), { key => $key // '' }))
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 2 1498 1500
Condition100%2/2
$key // ""
l!l
11
MC/DC100%1/1
$key // ""
$key
Truth table100%2/2
A
A= $key
Aresult
11
00
256 unless defined $message;
257  
258 # A selector may nest another selector (plural inside gender, say).
259 1498 ▶ $message = _select_form($language, $message, $args) while ref $message eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
ref $message eq "HASH" and do { $message = _select_form($language, $message, $args) } 76 1498 1574
260  
261 1498 return _render($message, $args);
262 }
263  
264 =head2 has_message
265  
266 Purpose: say whether a key exists, for optional parts of a message family
267 such as a finding's C<.fix> text.
268  
269 Args: C<$key> (string).
270  
271 Returns: 1 if the user's catalogue or the fallback has the key, else 0.
272  
273 Side Effects: none.
274  
275 Usage: C<< $self->i18n("$id.fix") if $self->has_message("$id.fix") >>
276  
277 =head3 EXAMPLE
278  
279 print "has a fix\n" if App::WebPerimeterScan::I18N->has_message('csp-missing.fix');
280  
281 =head3 API SPECIFICATION
282  
283 =head4 INPUT
284  
285 { key => { type => 'string', min => 1, position => 0 } }
286  
287 =head4 OUTPUT
288  
289 { type => 'boolean' }
290  
291 =head3 MESSAGES
292  
293 None.
294  
295 =cut
296  
297 sub has_message
298 565 ▶{
Subroutine has_message: called CC=3 SCAR=11.0
Pod documented
299 565 my ($self, $key) = @_;
300  
301 # An undefined key cannot name a message; say no rather than warn.
302 565 ▶ return (defined $key && defined _lookup($self->language, $key)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $key && defined _lookup($self->language, $key) ? : 550 15 565
Condition100%3/3
defined $key and defined _lookup($self->language, $key)
!ll&&!rl&&r
114550
MC/DC100%2/2
defined $key and defined _lookup($self->language, $key)
defined $key defined _lookup($self->language, $key)
Truth table100%3/3
A and B
A= defined $keyB= defined _lookup($self->language, $key)
ABresult
0X0
100
111
303 }
304  
305 =head2 clean_error
306  
307 Purpose: turn an exception into a one-line message for a person, by removing
308 the C<at FILE line N.> suffix that C<croak> and C<die> append.
309  
310 Args: the exception: a string, or an object that stringifies, such as an
311 L<autodie::exception>.
312  
313 Returns: the message without the location or trailing newline; an empty
314 string for C<undef>.
315  
316 Side Effects: none.
317  
318 Usage: C<< print STDERR clean_error($@), "\n" if $@; >>
319  
320 =head3 EXAMPLE
321  
322 eval { $scope->load_file('missing.txt') };
323 print App::WebPerimeterScan::I18N::clean_error($@), "\n";
324 # Cannot read scope file 'missing.txt': No such file or directory
325  
326 =head3 API SPECIFICATION
327  
328 =head4 INPUT
329  
330 { error => { type => 'scalar|object', optional => 1, position => 0 } }
331  
332 =head4 OUTPUT
333  
334 { type => 'string' }
335  
336 =head3 MESSAGES
337  
338 None.
339  
340 =cut
341  
342 sub clean_error
343 11 ▶{
Subroutine clean_error: called CC=2 SCAR=6.9
Pod documented
344 11 my ($error) = @_;
345  
346 # Stringify first so an exception object is handled like a plain string.
347 11 ▶ my $text = defined $error ? "$error" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $error ? : 10 1 11
348 11 $text =~ s/$CARP_SUFFIX//;
349 11 chomp $text;
350  
351 11 return $text;
352 }
353  
354 # _throw
355 # Purpose: croak with the rendered text of a message key, so every error
356 # in the distribution is translatable and reported from the
357 # caller's point of view.
358 # Entry: $self is a class name or object inheriting from this class;
359 # $key exists in the catalogue; $args is an optional hashref.
360 # Exit: never returns.
361 # Side effects: throws.
362 13 ▶sub _throw :Protected
Subroutine _throw: called CC=1 SCAR=0.0
363 {
364 13 my ($self, $key, $args) = @_;
365  
366 13 croak($self->i18n($key, $args));
367 34 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
368  
369 # _warn
370 # Purpose: carp the rendered text of a message key.
371 # Entry: as _throw.
372 # Exit: $self, so a caller can chain on.
373 # Side effects: emits a warning through Carp (and so through $SIG{__WARN__}).
374 5 ▶sub _warn :Protected
Subroutine _warn: called CC=1 SCAR=0.0
375 {
376 5 my ($self, $key, $args) = @_;
377  
378 5 carp($self->i18n($key, $args));
379  
380 5 return $self;
381 34 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
382  
383 # _wanted_languages
384 # Purpose: the user's language preferences, most preferred first.
385 # Entry: none; reads %config and %ENV.
386 # Exit: arrayref of lowercase language codes, possibly empty.
387 # Side effects: none.
388 2076 ▶sub _wanted_languages :Private
Subroutine _wanted_languages: called CC=8 SCAR=20.9
389 {
390 2076 my @wanted;
391 2076 ▶ push @wanted, $config{language} if defined $config{language};
Branch: 1 branch
BranchTrueFalseTotal
if defined $App::WebPerimeterScan::I18N::config{"language"} 1 2075 2076
392  
393 2076 for my $variable (@LOCALE_VARIABLES) {
394 8304 my $value = $ENV{$variable};
395 8304 ▶ next unless defined $value && length $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 8255 49 8304
Condition66%2/3
defined $value and length $value
!ll&&!rl&&r
8255049
MC/DC50%1/2
defined $value and length $value
defined $value length $value
Truth table66%2/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
396  
397 # LANGUAGE may be "de:fr:en"; the others hold a single locale.
398 49 for my $locale (split /:/, $value) {
399 50 ▶ next if $NEUTRAL_LOCALE{$locale};
Branch: 1 branch
BranchTrueFalseTotal
if $NEUTRAL_LOCALE{$locale} 20 30 50
400  
401 # de_DE.UTF-8@euro -> de
402 30 ▶ push @wanted, lc $1 if $locale =~ /\A([A-Za-z]{2,3})(?:[_.@-]|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
if $locale =~ /\A([A-Za-z]{2,3})(?:[_.\@-]|\z)/ 30 0 30
403 }
404 }
405  
406 2076 return \@wanted;
407 34 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
408  
409 # _lookup
410 # Purpose: find a key in one language, then in the fallback.
411 # Entry: $language has a catalogue; $key is a non-empty string.
412 # Exit: the message (string or selector hash), or undef if absent.
413 # Side effects: none.
414 2065 ▶sub _lookup :Private
Subroutine _lookup: called CC=2 SCAR=6.9
415 {
416 2065 my ($language, $key) = @_;
417  
418 2065 my $catalogue = \%App::WebPerimeterScan::Messages::CATALOGUE;
419  
420 # Per-key fallback, so a partial translation still renders every message.
421 2065 ▶ return $catalogue->{$language}{$key} // $catalogue->{ $config{fallback} }{$key};
Condition100%3/3
$catalogue->{$language}{$key} // $$catalogue{$App::WebPerimeterScan::I18N::config{"fallback"}}{$key}
l!l&&r!l&&!r
2049115
MC/DC100%2/2
$catalogue->{$language}{$key} // $$catalogue{$App::WebPerimeterScan::I18N::config{"fallback"}}{$key}
$catalogue->{$language}{$key} $$catalogue{$App::WebPerimeterScan::I18N::config{"fallback"}}{$key}
Truth table100%3/3
A // B
A= $catalogue->{$language}{$key}B= $$catalogue{$App::WebPerimeterScan::I18N::config{"fallback"}}{$key}
ABresult
1X1
011
000
422 34 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
423  
424 # _select_form
425 # Purpose: resolve one level of a plural or select message.
426 # Entry: $message is a hashref with 'forms' and one of 'plural'/'select'.
427 # Exit: the chosen form (a string or a nested selector).
428 # Side effects: none.
429 76 ▶sub _select_form :Private
Subroutine _select_form: called CC=11 SCAR=25.3
430 {
431 76 my ($language, $message, $args) = @_;
432  
433 76 ▶ my $forms = $message->{forms} || {};
Condition50%1/2
$message->{'forms'} || {}
l!l
760
MC/DC0%0/1
$message->{'forms'} || {}
$message->{'forms'}
Truth table50%1/2
A
A= $message->{'forms'}
Aresult
11
00
434 76 my $form;
435  
436 76 ▶ if(defined(my $name = $message->{plural})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $name = $message->{'plural'})) { } 18 58 76
elsif (defined(my $selector = $message->{'select'})) { } 58 0 58
437 # A count that is missing or not a number is treated as plural:
438 # "0 files" reads better than a crash in the middle of a report.
439 18 my $count = $args->{$name};
440 18 ▶ my $rule = $PLURAL_RULE{$language} || $PLURAL_RULE{ $config{fallback} };
Condition66%2/3
$App::WebPerimeterScan::I18N::PLURAL_RULE{$language} || $App::WebPerimeterScan::I18N::PLURAL_RULE{$App::WebPerimeterScan::I18N::config{'fallback'}}
l!l&&r!l&&!r
1710
MC/DC0%0/2
$App::WebPerimeterScan::I18N::PLURAL_RULE{$language} || $App::WebPerimeterScan::I18N::PLURAL_RULE{$App::WebPerimeterScan::I18N::config{'fallback'}}
$App::WebPerimeterScan::I18N::PLURAL_RULE{$language} $App::WebPerimeterScan::I18N::PLURAL_RULE{$App::WebPerimeterScan::I18N::config{'fallback'}}
Truth table66%2/3
A || B
A= $App::WebPerimeterScan::I18N::PLURAL_RULE{$language}B= $App::WebPerimeterScan::I18N::PLURAL_RULE{$App::WebPerimeterScan::I18N::config{'fallback'}}
ABresult
1X1
011
000
441 18 ▶ $form = (defined $count && $count =~ /\A-?\d+(?:\.\d+)?\z/) ? $rule->($count) : $OTHER_FORM;
Branch: 1 branch
BranchTrueFalseTotal
defined $count && $count =~ /\A-?\d+(?:\.\d+)?\z/ ? : 16 2 18
Condition100%3/3
defined $count and $count =~ /\A-?\d+(?:\.\d+)?\z/
!ll&&!rl&&r
1116
MC/DC100%2/2
defined $count and $count =~ /\A-?\d+(?:\.\d+)?\z/
defined $count $count =~ /\A-?\d+(?:\.\d+)?\z/
Truth table100%3/3
A and B
A= defined $countB= $count =~ /\A-?\d+(?:\.\d+)?\z/
ABresult
0X0
100
111
442 } elsif(defined(my $selector = $message->{select})) {
443 58 ▶ $form = $args->{$selector} // $OTHER_FORM;
Condition66%2/3
$args->{$selector} // $OTHER_FORM
l!l&&r!l&&!r
5710
MC/DC0%0/2
$args->{$selector} // $OTHER_FORM
$args->{$selector} $OTHER_FORM
Truth table66%2/3
A // B
A= $args->{$selector}B= $OTHER_FORM
ABresult
1X1
011
000
444 }
445  
446 76 ▶ return $forms->{ $form // $OTHER_FORM } // $forms->{$OTHER_FORM} // '';
Condition50%4/8
($$forms{$form // $OTHER_FORM} // $forms->{$OTHER_FORM}) // ""
l!l
760
$$forms{$form // $OTHER_FORM} // $forms->{$OTHER_FORM}
l!l&&r!l&&!r
31450
$form // $OTHER_FORM
l!l&&r!l&&!r
7600
MC/DC0%0/2
($$forms{$form // $OTHER_FORM} // $forms->{$OTHER_FORM}) // ""
$$forms{$form // $OTHER_FORM} $forms->{$OTHER_FORM}
MC/DC0%0/2
$form // $OTHER_FORM
$form $OTHER_FORM
Truth table66%2/3
A // B
A= $$forms{$form // $OTHER_FORM}B= $forms->{$OTHER_FORM}
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $formB= $OTHER_FORM
ABresult
1X1
011
000
447 34 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
448  
449 # _render
450 # Purpose: substitute {name} and {name:%fmt} placeholders.
451 # Entry: $text is a string; $args is a hashref.
452 # Exit: the rendered string. Unknown placeholders are left as is.
453 # Side effects: none.
454 1500 ▶sub _render :Private
Subroutine _render: called CC=4 SCAR=13.9
455 {
456 1500 my ($text, $args) = @_;
457  
458 # One pass, so a value that itself contains "{x}" is never expanded.
459 1500 $text =~ s{$PLACEHOLDER}{
460 !exists $args->{$1} || !defined $args->{$1} ? $&
461 : defined $2 ? sprintf($2, $args->{$1})
462 486 ▶ : $args->{$1}
Branch: 2 branches
BranchTrueFalseTotal
!(exists $args->{$1} && defined $args->{$1}) ? : 8 478 486
defined $2 ? : 1 477 478
Condition100%3/3
exists $args->{$1} && defined $args->{$1}
!ll&&!rl&&r
71478
MC/DC100%2/2
exists $args->{$1} && defined $args->{$1}
exists $args->{$1} defined $args->{$1}
Truth table100%3/3
A && B
A= exists $args->{$1}B= defined $args->{$1}
ABresult
0X0
100
111
463 }ge;
464  
465 1500 return $text;
466 34 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
467  
468 34 1;
469  
470 __END__
« lib/App/WebPerimeterScan/HTTP.pm ↑ Summary lib/App/WebPerimeterScan/Findings.pm »