blib/lib/Text/Xslate/Bridge/TT2Like.pm

filter: Statementstmt 75.1% 224 / 298 Branchbran 38.4% 53 / 138 Conditioncond 29.4% 10 / 34 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 80.0% 68 / 85 Podpod n/a totaltotal 61.7% 355 / 575 CC 88 SCAR 19.0
CC
88
Cov
61%
_hash_list
30.0
_list_sort_make_key
30.0
_text_replace
24.3
CRAP 6.7
↑ Summary
1 package Text::Xslate::Bridge::TT2Like;
2 5 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use base qw(Text::Xslate::Bridge);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 our $VERSION = '0.00010';
8  
9 5 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Text::Xslate;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 our $TRUNCATE_LENGTH = 32;
13 5 our $TRUNCATE_ADDON = '...';
14  
15 __PACKAGE__->bridge(
16 scalar => {
17 item => \&_text_item,
18 list => \&_text_list,
19 hash => \&_text_hash,
20 length => \&_text_length,
21 size => \&_text_size,
22 defined => \&_text_defined,
23 match => \&_text_match,
24 search => \&_text_search,
25 repeat => \&_text_repeat,
26 replace => \&_text_replace,
27 remove => \&_text_remove,
28 split => \&_text_split,
29 chunk => \&_text_chunk,
30 substr => \&_text_substr,
31 },
32 hash => {
33 item => \&_hash_item,
34 hash => \&_hash_hash,
35 size => \&_hash_size,
36 each => \&_hash_each,
37 keys => \&_hash_keys,
38 values => \&_hash_values,
39 items => \&_hash_items,
40 pairs => \&_hash_pairs,
41 list => \&_hash_list,
42 exists => \&_hash_exists,
43 defined => \&_hash_defined,
44 delete => \&_hash_delete,
45 import => \&_hash_import,
46 sort => \&_hash_sort,
47 nsort => \&_hash_nsort,
48 },
49 array => {
50 item => \&_list_item,
51 list => \&_list_list,
52 hash => \&_list_hash,
53 push => \&_list_push,
54 pop => \&_list_pop,
55 unshift => \&_list_unshift,
56 shift => \&_list_shift,
57 max => \&_list_max,
58 size => \&_list_size,
59 defined => \&_list_defined,
60 first => \&_list_first,
61 last => \&_list_last,
62 reverse => \&_list_reverse,
63 grep => \&_list_grep,
64 join => \&_list_join,
65 sort => \&_list_sort,
66 nsort => \&_list_nsort,
67 unique => \&_list_unique,
68 import => \&_list_import,
69 merge => \&_list_merge,
70 slice => \&_list_slice,
71 splice => \&_list_splice,
72 },
73 function => {
74 # 'html' => \&_html_filter, # Xslate has builtin filter for html escape, and it is not overridable.
75 html_para => Text::Xslate::html_builder(\&_html_paragraph),
76 html_break => Text::Xslate::html_builder(\&_html_para_break),
77 html_para_break => Text::Xslate::html_builder(\&_html_para_break),
78 html_line_break => Text::Xslate::html_builder(\&_html_line_break),
79 xml => Text::Xslate::html_builder(\&_xml_filter),
80 # 'uri' => \&uri_escape, # builtin from version 0.1052
81 url => \&Text::Xslate::uri_escape,
82 1 ▶ upper => sub { uc $_[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
83 1 ▶ lower => sub { lc $_[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
84 1 ▶ ucfirst => sub { ucfirst $_[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
85 1 ▶ lcfirst => sub { lcfirst $_[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
86 # 'stderr' => sub { print STDERR @_; return '' }, # anyone want this??
87 1 ▶ trim => sub { for ($_[0]) { s/^\s+//; s/\s+$// }; $_[0] },
Subroutine __ANON__: called CC=2 SCAR=6.9
88 0 ▶ null => sub { return '' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
89 1 ▶ collapse => sub { for ($_[0]) { s/^\s+//; s/\s+$//; s/\s+/ /g };
Subroutine __ANON__: called CC=2 SCAR=6.9
90 1 $_[0] },
91 5 indent => \&_indent_filter_factory,
92 format => \&_format_filter_factory,
93 truncate => \&_truncate_filter_factory,
94 repeat => \&_repeat_filter_factory,
95 replace => \&_replace_filter_factory,
96 remove => \&_remove_filter_factory,
97 },
98 );
99  
100 0 ▶sub _text_item {
Subroutine _text_item: not called CC=1 SCAR=6.9
101 0 $_[0];
102 }
103  
104 0 ▶sub _text_list {
Subroutine _text_list: not called CC=1 SCAR=6.9
105 0 [ $_[0] ];
106 }
107  
108 0 ▶sub _text_hash {
Subroutine _text_hash: not called CC=1 SCAR=6.9
109 0 { value => $_[0] };
110 }
111  
112 1 ▶sub _text_length {
Subroutine _text_length: called CC=1 SCAR=0.0
113 1 length $_[0];
114 }
115  
116 1 ▶sub _text_size {
Subroutine _text_size: called CC=1 SCAR=0.0
117 1 return 1;
118 }
119  
120 0 ▶sub _text_defined {
Subroutine _text_defined: not called CC=1 SCAR=6.9
121 0 return 1;
122 }
123  
124 1 ▶sub _text_match {
Subroutine _text_match: called CC=5 SCAR=18.6
125 1 my ($str, $search, $global) = @_;
126 1 ▶ return $str unless defined $str and defined $search;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str and defined $search 0 1 1
Condition33%1/3
defined $str and defined $search
!ll&&!rl&&r
001
MC/DC0%0/2
defined $str and defined $search
defined $str defined $search
Truth table33%1/3
A and B
A= defined $strB= defined $search
ABresult
0X0
100
111
127 1 ▶ my @matches = $global ? ($str =~ /$search/g)
Branch: 1 branch
BranchTrueFalseTotal
$global ? : 1 0 1
128 : ($str =~ /$search/);
129 1 ▶ return @matches ? \@matches : '';
Branch: 1 branch
BranchTrueFalseTotal
@matches ? : 1 0 1
130 }
131  
132 2 ▶sub _text_search {
Subroutine _text_search: called CC=3 SCAR=12.5
133 2 my ($str, $pattern) = @_;
134 2 ▶ return $str unless defined $str and defined $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str and defined $pattern 0 2 2
Condition33%1/3
defined $str and defined $pattern
!ll&&!rl&&r
002
MC/DC0%0/2
defined $str and defined $pattern
defined $str defined $pattern
Truth table33%1/3
A and B
A= defined $strB= defined $pattern
ABresult
0X0
100
111
135 2 return $str =~ /$pattern/;
136 }
137  
138 0 ▶sub _text_repeat {
Subroutine _text_repeat: not called CC=4 SCAR=30.0
139 0 my ($str, $count) = @_;
140 0 ▶ $str = '' unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 0 0
141 0 ▶ return '' unless $count;
Branch: 1 branch
BranchTrueFalseTotal
unless $count 0 0 0
142 0 ▶ $count ||= 1;
Condition0%0/2
$count ||= 1
l!l
00
MC/DC0%0/1
$count ||= 1
$count
Truth table0%0/2
A
A= $count
Aresult
11
00
143 0 return $str x $count;
144 }
145  
146 1 ▶sub _text_replace {
Subroutine _text_replace: called CC=8 SCAR=31.9
147 1 my ($text, $pattern, $replace, $global) = @_;
148 1 ▶ $text = '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 1 1
149 1 ▶ $pattern = '' unless defined $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pattern 0 1 1
150 1 ▶ $replace = '' unless defined $replace;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $replace 0 1 1
151 1 ▶ $global = 1 unless defined $global;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $global 1 0 1
152  
153 1 ▶ if ($replace =~ /\$\d+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($replace =~ /\$\d+/) { } 0 1 1
154 # replacement string may contain backrefs
155 0 ▶ my $expand = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
156 0 my ($chunk, $start, $end) = @_;
157 0 $chunk =~ s{ \\(\\|\$) | \$ (\d+) }{
158 0 ▶ $1 ? $1
Branch: 2 branches
BranchTrueFalseTotal
$1 ? : 0 0 0
$2 > $start->$#* || $2 == 0 ? : 0 0 0
Condition0%0/3
$2 > $start->$#* or $2 == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$2 > $start->$#* or $2 == 0
$2 > $start->$#* $2 == 0
Truth table0%0/3
A or B
A= $2 > $start->$#*B= $2 == 0
ABresult
1X1
011
000
159 : ($2 > $#$start || $2 == 0) ? ''
160 : substr($text, $start->[$2], $end->[$2] - $start->[$2]);
161 }exg;
162 0 $chunk;
163 0 };
164 0 ▶ if ($global) {
Branch: 1 branch
BranchTrueFalseTotal
if ($global) { } 0 0 0
165 0 $text =~ s{$pattern}{ &$expand($replace, [@-], [@+]) }eg;
166 }
167 else {
168 0 $text =~ s{$pattern}{ &$expand($replace, [@-], [@+]) }e;
169 }
170 }
171 else {
172 1 ▶ if ($global) {
Branch: 1 branch
BranchTrueFalseTotal
if ($global) { } 1 0 1
173 1 $text =~ s/$pattern/$replace/g;
174 }
175 else {
176 0 $text =~ s/$pattern/$replace/;
177 }
178 }
179 1 return $text;
180 }
181  
182 1 ▶sub _text_remove {
Subroutine _text_remove: called CC=3 SCAR=12.0
183 1 my ($str, $search) = @_;
184 1 ▶ return $str unless defined $str and defined $search;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str and defined $search 0 1 1
Condition33%1/3
defined $str and defined $search
!ll&&!rl&&r
001
MC/DC0%0/2
defined $str and defined $search
defined $str defined $search
Truth table33%1/3
A and B
A= defined $strB= defined $search
ABresult
0X0
100
111
185 1 $str =~ s/$search//g;
186 1 return $str;
187 }
188
189 3 ▶sub _text_split {
Subroutine _text_split: called CC=5 SCAR=20.1
190 3 my ($str, $split, $limit) = @_;
191 3 ▶ $str = '' unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 3 3
192
193 # we have to be very careful about spelling out each possible
194 # combination of arguments because split() is very sensitive
195 # to them, for example C<split(' ', ...)> behaves differently
196 # to C<$space=' '; split($space, ...)>
197
198 3 ▶ if (defined $limit) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $limit) { } 0 3 3
199 0 ▶ return [ defined $split
Branch: 1 branch
BranchTrueFalseTotal
defined $split ? : 0 0 0
200 ? split($split, $str, $limit)
201 : split(' ', $str, $limit) ];
202 }
203 else {
204 3 ▶ return [ defined $split
Branch: 1 branch
BranchTrueFalseTotal
defined $split ? : 0 3 3
205 ? split($split, $str)
206 : split(' ', $str) ];
207 }
208 }
209  
210 2 ▶sub _text_chunk {
Subroutine _text_chunk: called CC=5 SCAR=19.1
211 2 my ($string, $size) = @_;
212 2 my @list;
213 2 ▶ $size ||= 1;
Condition50%1/2
$size ||= 1
l!l
20
MC/DC0%0/1
$size ||= 1
$size
Truth table50%1/2
A
A= $size
Aresult
11
00
214 2 ▶ if ($size < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size < 0) { } 0 2 2
215 # sexeger! It's faster to reverse the string, search
216 # it from the front and then reverse the output than to
217 # search it from the end, believe it nor not!
218 0 $string = reverse $string;
219 0 $size = -$size;
220 0 ▶ unshift(@list, scalar reverse $1)
Branch: 1 branch
BranchTrueFalseTotal
$string =~ /((.{$size})|(.+))/g and do { unshift @list, scalar reverse($1) } 0 0 0
221 while ($string =~ /((.{$size})|(.+))/g);
222 }
223 else {
224 2 ▶ push(@list, $1) while ($string =~ /((.{$size})|(.+))/g);
Branch: 1 branch
BranchTrueFalseTotal
$string =~ /((.{$size})|(.+))/g and do { push @list, $1 } 8 2 10
225 }
226 2 return \@list;
227 }
228  
229 2 ▶sub _text_substr {
Subroutine _text_substr: called CC=4 SCAR=14.2
230 2 my ($text, $offset, $length, $replacement) = @_;
231 2 ▶ $offset ||= 0;
Condition50%1/2
$offset ||= 0
l!l
02
MC/DC0%0/1
$offset ||= 0
$offset
Truth table50%1/2
A
A= $offset
Aresult
11
00
232
233 2 ▶ if(defined $length) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $length) { } 2 0 2
234 2 ▶ if (defined $replacement) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $replacement) { } 1 1 2
235 1 substr( $text, $offset, $length, $replacement );
236 1 return $text;
237 }
238 else {
239 1 return substr( $text, $offset, $length );
240 }
241 }
242 else {
243 0 return substr( $text, $offset );
244 }
245 }
246  
247 2 ▶sub _hash_item {
Subroutine _hash_item: called CC=2 SCAR=7.1
248 2 my ($hash, $item) = @_;
249 2 ▶ $item = '' unless defined $item;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 0 2 2
250 2 $hash->{ $item };
251 }
252  
253 0 ▶sub _hash_hash {
Subroutine _hash_hash: not called CC=1 SCAR=6.9
254 0 $_[0];
255 }
256  
257 1 ▶sub _hash_size {
Subroutine _hash_size: called CC=1 SCAR=0.0
258 1 scalar keys %{$_[0]};
259 }
260  
261 0 ▶sub _hash_each {
Subroutine _hash_each: not called CC=1 SCAR=6.9
262 # this will be changed in TT3 to do what hash_pairs() does
263 0 [ %{ $_[0] } ];
264 }
265  
266 1 ▶sub _hash_keys {
Subroutine _hash_keys: called CC=1 SCAR=0.0
267 1 [ keys %{ $_[0] } ];
268 }
269  
270 0 ▶sub _hash_values {
Subroutine _hash_values: not called CC=1 SCAR=6.9
271 0 [ values %{ $_[0] } ];
272 }
273  
274 0 ▶sub _hash_items {
Subroutine _hash_items: not called CC=1 SCAR=6.9
275 0 [ %{ $_[0] } ];
276 }
277  
278 2 ▶sub _hash_pairs {
Subroutine _hash_pairs: called CC=1 SCAR=0.0
279 [ map {
280 5 { key => $_ , value => $_[0]->{ $_ } }
281 }
282 2 sort keys %{ $_[0] }
283 ];
284 }
285  
286 0 ▶sub _hash_list {
Subroutine _hash_list: not called CC=5 SCAR=34.0
287 0 my ($hash, $what) = @_;
288 0 ▶ $what ||= '';
Condition0%0/2
$what ||= ""
l!l
00
MC/DC0%0/1
$what ||= ""
$what
Truth table0%0/2
A
A= $what
Aresult
11
00
289 return ($what eq 'keys') ? [ keys %$hash ]
290 : ($what eq 'values') ? [ values %$hash ]
291 : ($what eq 'each') ? [ %$hash ]
292 : # for now we do what pairs does but this will be changed
293 # in TT3 to return [ $hash ] by default
294 0 ▶ [ map { { key => $_ , value => $hash->{ $_ } } }
Branch: 3 branches
BranchTrueFalseTotal
$what eq 'keys' ? : 0 0 0
$what eq 'values' ? : 0 0 0
$what eq 'each' ? : 0 0 0
295 sort keys %$hash
296 ];
297 }
298  
299 2 ▶sub _hash_exists {
Subroutine _hash_exists: called CC=1 SCAR=0.0
300 2 exists $_[0]->{ $_[1] };
301 }
302  
303 1 ▶sub _hash_defined {
Subroutine _hash_defined: called CC=2 SCAR=7.2
304 # return the item requested, or 1 if no argument
305 # to indicate that the hash itself is defined
306 1 my $hash = shift;
307 1 ▶ return @_ ? defined $hash->{ $_[0] } : 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 1 1
308 }
309  
310 1 ▶sub _hash_delete {
Subroutine _hash_delete: called CC=2 SCAR=6.9
311 1 my $hash = shift;
312 1 delete $hash->{ $_ } for @_;
313 }
314  
315 0 ▶sub _hash_import {
Subroutine _hash_import: not called CC=2 SCAR=17.9
316 0 my ($hash, $imp) = @_;
317 0 ▶ $imp = {} unless ref $imp eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $imp eq "HASH" 0 0 0
318 0 @$hash{ keys %$imp } = values %$imp;
319 0 return '';
320 }
321  
322 1 ▶sub _hash_sort {
Subroutine _hash_sort: called CC=1 SCAR=0.0
323 1 my ($hash) = @_;
324 1 [ sort { lc $hash->{$a} cmp lc $hash->{$b} } (keys %$hash) ];
325 }
326  
327 0 ▶sub _hash_nsort {
Subroutine _hash_nsort: not called CC=1 SCAR=6.9
328 0 my ($hash) = @_;
329 0 [ sort { $hash->{$a} <=> $hash->{$b} } (keys %$hash) ];
330 }
331  
332 1 ▶sub _list_item {
Subroutine _list_item: called CC=2 SCAR=7.6
333 1 ▶ $_[0]->[ $_[1] || 0 ];
Condition50%1/2
$_[1] || 0
l!l
01
MC/DC0%0/1
$_[1] || 0
$_[1]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
334 }
335  
336 0 ▶sub _list_list {
Subroutine _list_list: not called CC=1 SCAR=6.9
337 0 $_[0];
338 }
339  
340 0 ▶sub _list_hash {
Subroutine _list_hash: not called CC=3 SCAR=19.6
341 0 my $list = shift;
342 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
343 0 ▶ my $n = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
344 0 return { map { ($n++, $_) } @$list };
345 }
346 5 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
347 0 return { @$list };
348 }
349  
350 1 ▶sub _list_push {
Subroutine _list_push: called CC=1 SCAR=0.0
351 1 my $list = shift;
352 1 push(@$list, @_);
353 1 return '';
354 }
355  
356 1 ▶sub _list_pop {
Subroutine _list_pop: called CC=1 SCAR=0.0
357 1 my $list = shift;
358 1 pop(@$list);
359 }
360  
361 4 ▶sub _list_unshift {
Subroutine _list_unshift: called CC=1 SCAR=0.0
362 4 my $list = shift;
363 4 unshift(@$list, @_);
364 4 return '';
365 }
366  
367 2 ▶sub _list_shift {
Subroutine _list_shift: called CC=1 SCAR=0.0
368 2 my $list = shift;
369 2 shift(@$list);
370 }
371  
372 1 ▶sub _list_max {
Subroutine _list_max: called CC=1 SCAR=0.0
373 5 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
374 1 my $list = shift;
375 1 $#$list;
376 }
377  
378 3 ▶sub _list_size {
Subroutine _list_size: called CC=1 SCAR=0.0
379 5 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
380 3 my $list = shift;
381 3 $#$list + 1;
382 }
383  
384 1 ▶sub _list_defined {
Subroutine _list_defined: called CC=2 SCAR=7.2
385 # return the item requested, or 1 if no argument to
386 # indicate that the hash itself is defined
387 1 my $list = shift;
388 1 ▶ return @_ ? defined $list->[$_[0]] : 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 1 1
389 }
390  
391 1 ▶sub _list_first {
Subroutine _list_first: called CC=2 SCAR=8.1
392 1 my $list = shift;
393 1 ▶ return $list->[0] unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 0 1
394 0 return [ @$list[0..$_[0]-1] ];
395 }
396  
397 1 ▶sub _list_last {
Subroutine _list_last: called CC=2 SCAR=8.1
398 1 my $list = shift;
399 1 ▶ return $list->[-1] unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 0 1
400 0 return [ @$list[-$_[0]..-1] ];
401 }
402  
403 1 ▶sub _list_reverse {
Subroutine _list_reverse: called CC=1 SCAR=0.0
404 1 my $list = shift;
405 1 [ reverse @$list ];
406 }
407  
408 1 ▶sub _list_grep {
Subroutine _list_grep: called CC=2 SCAR=7.1
409 1 my ($list, $pattern) = @_;
410 1 ▶ $pattern ||= '';
Condition50%1/2
$pattern ||= ""
l!l
10
MC/DC0%0/1
$pattern ||= ""
$pattern
Truth table50%1/2
A
A= $pattern
Aresult
11
00
411 1 return [ grep /$pattern/, @$list ];
412 }
413  
414 11 ▶sub _list_join {
Subroutine _list_join: called CC=3 SCAR=11.7
415 11 my ($list, $joint) = @_;
416 join(defined $joint ? $joint : ' ',
417 11 ▶ map { defined $_ ? $_ : '' } @$list);
Branch: 2 branches
BranchTrueFalseTotal
defined $joint ? : 11 0 11
defined $_ ? : 53 0 53
418 }
419  
420 0 ▶sub _list_sort_make_key {
Subroutine _list_sort_make_key: not called CC=5 SCAR=34.0
421 0 my ($item, $fields) = @_;
422 0 my @keys;
423  
424 0 ▶ if (ref($item) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $item eq 'HASH') { } 0 0 0
elsif (builtin::blessed($item)) { } 0 0 0
425 0 @keys = map { $item->{ $_ } } @$fields;
426 }
427 elsif (blessed $item) {
428 0 ▶ @keys = map { $item->can($_) ? $item->$_() : $item } @$fields;
Branch: 1 branch
BranchTrueFalseTotal
$item->can($_) ? : 0 0 0
429 }
430 else {
431 0 @keys = $item;
432 }
433
434 # ugly hack to generate a single string using a delimiter that is
435 # unlikely (but not impossible) to be found in the wild.
436 0 ▶ return lc join('/*^UNLIKELY^*/', map { defined $_ ? $_ : '' } @keys);
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
437 }
438  
439 2 ▶sub _list_sort {
Subroutine _list_sort: called CC=3 SCAR=12.6
440 2 my ($list, @fields) = @_;
441 2 ▶ return $list unless @$list > 1; # no need to sort 1 item lists
Branch: 1 branch
BranchTrueFalseTotal
unless @$list > 1 0 2 2
442 return [
443 @fields # Schwartzian Transform
444 0 ? map { $_->[0] } # for case insensitivity
445 0 sort { $a->[1] cmp $b->[1] }
446 0 map { [ $_, _list_sort_make_key($_, \@fields) ] }
447 @$list
448 8 : map { $_->[0] }
449 12 sort { $a->[1] cmp $b->[1] }
450 2 ▶ map { [ $_, lc $_ ] }
Branch: 1 branch
BranchTrueFalseTotal
@fields ? : 0 2 2
451 @$list,
452 ];
453 }
454  
455 1 ▶sub _list_nsort {
Subroutine _list_nsort: called CC=3 SCAR=12.6
456 1 my ($list, @fields) = @_;
457 1 ▶ return $list unless @$list > 1; # no need to sort 1 item lists
Branch: 1 branch
BranchTrueFalseTotal
unless @$list > 1 0 1 1
458 return [
459 @fields # Schwartzian Transform
460 0 ? map { $_->[0] } # for case insensitivity
461 0 sort { $a->[1] <=> $b->[1] }
462 0 map { [ $_, _list_sort_make_key($_, \@fields) ] }
463 @$list
464 6 : map { $_->[0] }
465 11 sort { $a->[1] <=> $b->[1] }
466 1 ▶ map { [ $_, lc $_ ] }
Branch: 1 branch
BranchTrueFalseTotal
@fields ? : 0 1 1
467 @$list,
468 ];
469 }
470  
471 1 ▶sub _list_unique {
Subroutine _list_unique: called CC=1 SCAR=0.0
472 1 my %u;
473 1 [ grep { ++$u{$_} == 1 } @{$_[0]} ];
474 }
475  
476 1 ▶sub _list_import {
Subroutine _list_import: called CC=2 SCAR=7.1
477 1 my $list = shift;
478 1 ▶ push(@$list, grep defined, map ref eq 'ARRAY' ? @$_ : undef, @_);
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 1 0 1
479 1 return $list;
480 }
481  
482 2 ▶sub _list_merge {
Subroutine _list_merge: called CC=2 SCAR=7.2
483 2 my $list = shift;
484 2 ▶ return [ @$list, grep defined, map ref eq 'ARRAY' ? @$_ : undef, @_ ];
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 2 0 2
485 }
486  
487 1 ▶sub _list_slice {
Subroutine _list_slice: called CC=5 SCAR=17.2
488 1 my ($list, $from, $to) = @_;
489 1 ▶ $from ||= 0;
Condition50%1/2
$from ||= 0
l!l
10
MC/DC0%0/1
$from ||= 0
$from
Truth table50%1/2
A
A= $from
Aresult
11
00
490 1 ▶ $to = $#$list unless defined $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to 0 1 1
491 1 ▶ $from += @$list if $from < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $from < 0 0 1 1
492 1 ▶ $to += @$list if $to < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $to < 0 0 1 1
493 1 return [ @$list[$from..$to] ];
494 }
495  
496 1 ▶sub _list_splice {
Subroutine _list_splice: called CC=6 SCAR=25.6
497 1 my ($list, $offset, $length, @replace) = @_;
498 1 ▶ if (@replace) {
Branch: 3 branches
BranchTrueFalseTotal
if (@replace) { } 1 0 1
elsif (defined $length) { } 0 0 0
elsif (defined $offset) { } 0 0 0
499 # @replace can contain a list of multiple replace items, or
500 # be a single reference to a list
501 1 ▶ @replace = @{ $replace[0] }
Branch: 1 branch
BranchTrueFalseTotal
if @replace == 1 and ref $replace[0] eq "ARRAY" 1 0 1
Condition33%1/3
@replace == 1 and ref $replace[0] eq "ARRAY"
!ll&&!rl&&r
001
MC/DC0%0/2
@replace == 1 and ref $replace[0] eq "ARRAY"
@replace == 1 ref $replace[0] eq "ARRAY"
Truth table33%1/3
A and B
A= @replace == 1B= ref $replace[0] eq "ARRAY"
ABresult
0X0
100
111
502 if @replace == 1 && ref $replace[0] eq 'ARRAY';
503 1 return [ splice @$list, $offset, $length, @replace ];
504 }
505 elsif (defined $length) {
506 0 return [ splice @$list, $offset, $length ];
507 }
508 elsif (defined $offset) {
509 0 return [ splice @$list, $offset ];
510 }
511 else {
512 0 return [ splice(@$list) ];
513 }
514 }
515  
516 1 ▶sub _xml_filter {
Subroutine _xml_filter: called CC=2 SCAR=6.9
517 1 my $text = shift;
518 1 for ($text) {
519 1 s/&/&amp;/g;
520 1 s/</&lt;/g;
521 1 s/>/&gt;/g;
522 1 s/"/&quot;/g;
523 1 s/'/&apos;/g;
524 }
525 1 return $text;
526 }
527  
528 3 ▶sub _html_paragraph {
Subroutine _html_paragraph: called CC=1 SCAR=0.0
529 3 my $text = shift;
530 3 return "<p>\n"
531 . join("\n</p>\n\n<p>\n", split(/(?:\r?\n){2,}/, Text::Xslate::Util::html_escape($text)))
532 . "</p>\n";
533 }
534  
535 4 ▶sub _html_para_break {
Subroutine _html_para_break: called CC=1 SCAR=0.0
536 4 my $text = shift;
537 4 $text = Text::Xslate::Util::html_escape($text);
538 4 $text =~ s|(\r?\n){2,}|$1<br />$1<br />$1|g;
539 4 return $text;
540 }
541  
542 2 ▶sub _html_line_break {
Subroutine _html_line_break: called CC=1 SCAR=0.0
543 2 my $text = shift;
544 2 $text = Text::Xslate::Util::html_escape($text);
545 2 $text =~ s|(\r?\n)|<br />$1|g;
546 2 return $text;
547 }
548  
549 1 ▶sub _indent_filter_factory {
Subroutine _indent_filter_factory: called CC=3 SCAR=11.3
550 1 my ($pad) = @_;
551 1 ▶ $pad = 4 unless defined $pad;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pad 0 1 1
552 1 ▶ $pad = ' ' x $pad if $pad =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $pad =~ /^\d+$/ 0 1 1
553  
554 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
555 1 my $text = shift;
556 1 ▶ $text = '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 1 1
557 1 $text =~ s/^/$pad/mg;
558 1 return $text;
559 }
560 1 }
561  
562 1 ▶sub _format_filter_factory {
Subroutine _format_filter_factory: called CC=2 SCAR=7.1
563 1 my ($format) = @_;
564 1 ▶ $format = '%s' unless defined $format;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $format 0 1 1
565  
566 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
567 1 my $text = shift;
568 1 ▶ $text = '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 1 1
569 1 return join("\n", map{ sprintf($format, $_) } split(/\n/, $text));
570 }
571 1 }
572  
573 1 ▶sub _truncate_filter_factory {
Subroutine _truncate_filter_factory: called CC=4 SCAR=15.0
574 1 my ($len, $char) = @_;
575 1 ▶ $len = $TRUNCATE_LENGTH unless defined $len;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 1 1
576 1 ▶ $char = $TRUNCATE_ADDON unless defined $char;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $char 1 0 1
577  
578 # Length of char is the minimum length
579 1 my $lchar = length $char;
580 1 ▶ if ($len < $lchar) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len < $lchar) 0 1 1
581 0 $char = substr($char, 0, $len);
582 0 $lchar = $len;
583 }
584  
585 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
586 1 my $text = shift;
587 1 ▶ return $text if length $text <= $len;
Branch: 1 branch
BranchTrueFalseTotal
if length $text <= $len 0 1 1
588 1 return substr($text, 0, $len - $lchar) . $char;
589 }
590 1 }
591  
592 1 ▶sub _repeat_filter_factory {
Subroutine _repeat_filter_factory: called CC=3 SCAR=11.8
593 1 my ($iter) = @_;
594 1 ▶ $iter = 1 unless defined $iter and length $iter;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $iter and length $iter 0 1 1
Condition33%1/3
defined $iter and length $iter
!ll&&!rl&&r
001
MC/DC0%0/2
defined $iter and length $iter
defined $iter length $iter
Truth table33%1/3
A and B
A= defined $iterB= length $iter
ABresult
0X0
100
111
595  
596 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
597 1 my $text = shift;
598 1 ▶ $text = '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 1 1
599 1 return join('\n', $text) x $iter;
600 }
601 1 }
602  
603 1 ▶sub _replace_filter_factory {
Subroutine _replace_filter_factory: called CC=3 SCAR=11.3
604 1 my ($search, $replace) = @_;
605 1 ▶ $search = '' unless defined $search;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $search 0 1 1
606 1 ▶ $replace = '' unless defined $replace;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $replace 0 1 1
607  
608 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
609 1 my $text = shift;
610 1 ▶ $text = '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 1 1
611 1 $text =~ s/$search/$replace/g;
612 1 return $text;
613 }
614 1 }
615  
616 1 ▶sub _remove_filter_factory {
Subroutine _remove_filter_factory: called CC=1 SCAR=0.0
617 1 my ($search) = @_;
618  
619 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
620 1 my $text = shift;
621 1 ▶ $text = '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 1 1
622 1 $text =~ s/$search//g;
623 1 return $text;
624 }
625 1 }
626  
627 5 1;
↑ Summary