Template/Filters.pm

filter: Statementstmt 29.0% 64 / 220 Branchbran 0.0% 0 / 120 Conditioncond 0.0% 0 / 42 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 42.5% 20 / 47 Podpod 0.0% 0 / 14 totaltotal 18.1% 84 / 464 CC 76 SCAR 59.4
CC
76
Cov
17%
__ANON__
870.0
__ANON__
650.0
__ANON__
272.0
CRAP 381.0
↑ Summary Template.pm »
1 package HTML::Template::Filters;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use vars qw(@ISA @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 our $VERSION = '0.05';
9  
10 1 @ISA = qw(Exporter);
11 1 @EXPORT = qw(
12 HT_FILTER_STRIP_TMPL_NEWLINE_WHITESPACE
13 HT_FILTER_VANGUARD_COMPATIBILITY
14 HT_FILTER_ALLOW_TRAILING_SLASH
15 HT_FILTER_SSI_INCLUDE_VIRTUAL
16 HT_FILTER_STRIP_TMPL_NEWLINE
17 HT_FILTER_GZIPPED_TEMPLATES
18 HT_FILTER_PERCENT_VARIABLES
19 HT_FILTER_STRIP_REDUNDANT
20 HT_FILTER_STRIP_NEWLINE
21 HT_FILTER_TMPL_CONSTANT
22 HT_FILTER_TMPL_COMMENT
23 HT_FILTER_TMPL_FIXME
24 HT_FILTER_TMPL_JOIN
25 HT_FILTER_MAC_OS
26 );
27  
28 1 ▶use constant HT_FILTER_STRIP_TMPL_NEWLINE_WHITESPACE => 'strip_tmpl_newline_whitespace';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use constant HT_FILTER_VANGUARD_COMPATIBILITY => 'percent_variables';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use constant HT_FILTER_ALLOW_TRAILING_SLASH => 'allow_trailing_slash';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use constant HT_FILTER_SSI_INCLUDE_VIRTUAL => 'ssi_include_virtual';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use constant HT_FILTER_STRIP_TMPL_NEWLINE => 'strip_tmpl_newline';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use constant HT_FILTER_GZIPPED_TEMPLATES => 'gzipped_templates';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use constant HT_FILTER_PERCENT_VARIABLES => 'percent_variables';
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use constant HT_FILTER_STRIP_REDUNDANT => 'strip_redundant';
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use constant HT_FILTER_STRIP_NEWLINE => 'strip_newline';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use constant HT_FILTER_TMPL_CONSTANT => 'tmpl_constant';
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use constant HT_FILTER_TMPL_COMMENT => 'tmpl_comment';
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use constant HT_FILTER_TMPL_FIXME => 'tmpl_fixme';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use constant HT_FILTER_TMPL_JOIN => 'tmpl_join';
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use constant HT_FILTER_MAC_OS => 'mac_os';
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 #
44 # Example: get_filters(HT_FILTER_ALLOW_TRAILING_SLASH,HT_FILTER_TMPL_COMMENT);
45 #
46 0 ▶sub get_filters {
Subroutine get_filters: not called CC=8 SCAR=42.8
Pod undocumented
47 0 ▶ croak "Invalid arguments to HTML::Template::Filters->get_filters()" unless (@_ > 1);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 1 0 0 0
48 0 my $pkg = shift;
49 0 my @wanted_filters = @_;
50  
51 # get the requested filters
52 0 my @filter_subs;
53 0 foreach my $wanted_filter (@wanted_filters) {
54 0 ▶ next unless (defined $wanted_filter and length $wanted_filter);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $wanted_filter and length $wanted_filter 0 0 0
Condition0%0/3
defined $wanted_filter and length $wanted_filter
!ll&&!rl&&r
000
MC/DC0%0/2
defined $wanted_filter and length $wanted_filter
defined $wanted_filter length $wanted_filter
Truth table0%0/3
A and B
A= defined $wanted_filterB= length $wanted_filter
ABresult
0X0
100
111
55 0 ▶ croak "Unknown filter: $wanted_filter" unless ($pkg->can($wanted_filter));
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg->can($wanted_filter) 0 0 0
56 0 my ($filter,$format) = $pkg->$wanted_filter();
57 0 ▶ $format = 'scalar' if (not defined $format or $format ne 'array');
Branch: 1 branch
BranchTrueFalseTotal
if not defined $format or $format ne "array" 0 0 0
Condition0%0/3
not defined $format or $format ne "array"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $format or $format ne "array"
not defined $format $format ne "array"
Truth table0%0/3
not(A) or B
A= not defined $formatB= $format ne "array"
ABresult
1X1
011
000
58 0 push @filter_subs, {
59 'sub' => $filter,
60 'format' => $format,
61 };
62 }
63  
64 0 return \@filter_subs;
65 }
66  
67 #
68 # allow trailing slash in <TMPL_xxx /> tags
69 #
70 0 ▶sub allow_trailing_slash {
Subroutine allow_trailing_slash: not called CC=1 SCAR=6.9
Pod undocumented
71 0 ▶ my $filter = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 0 my $text_ref = shift;
73 0 my $match = qr/(<[Tt][Mm][Pp][Ll]_[^>]+)\/>/;
74 0 $$text_ref =~ s/$match/$1>/g;
75 0 };
76 0 return $filter;
77 }
78  
79 #
80 # Translate the SSI "include virtual" into a template include:
81 #
82 0 ▶sub ssi_include_virtual {
Subroutine ssi_include_virtual: not called CC=1 SCAR=6.9
Pod undocumented
83 0 ▶ my $filter = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 0 my $text_ref = shift;
85 0 my $match = qr/<!--\s*#include virtual="[\/]?(.+?)"\s*-->/i;
86 0 $$text_ref =~ s/$match/<TMPL_INCLUDE NAME="$1">/g;
87 0 };
88 0 return $filter;
89 }
90  
91 #
92 # Decompress gzip-comressed templates
93 #
94 0 ▶sub gzipped_templates {
Subroutine gzipped_templates: not called CC=2 SCAR=17.9
Pod undocumented
95 0 eval { require Compress::Zlib; };
96 0 ▶ croak "To use gzip-compressed templates, you need into install Compress::Zlib" if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
97 0 ▶ my $filter = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
98 0 my $text_ref = shift;
99 0 require Compress::Zlib;
100 0 $text_ref = Compress::Zlib::uncompress($text_ref);
101 0 };
102 0 return $filter;
103 }
104  
105 #
106 # Allow template variables to use %var% syntax
107 #
108 0 ▶sub percent_variables {
Subroutine percent_variables: not called CC=1 SCAR=6.9
Pod undocumented
109 0 ▶ my $filter = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
110 0 my $text_ref = shift;
111 0 my $match = qr/%([-\w\/\.+]+)%/;
112 0 $$text_ref =~ s/$match/<TMPL_VAR NAME="$1">/g;
113 0 };
114 0 return $filter;
115 }
116  
117 #
118 # Strip newline's following TMPL_XXX statements
119 #
120 0 ▶sub strip_tmpl_newline {
Subroutine strip_tmpl_newline: not called CC=1 SCAR=6.9
Pod undocumented
121 0 ▶ my $filter = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
122 0 my $text_ref = shift;
123 0 $$text_ref =~ s/(<TMPL_[^>]>)[\r\n]+/$1/g;
124 0 };
125 0 return $filter;
126 }
127  
128  
129 # remove any space at the start of a line if it is immediately before a tmpl tag
130 0 ▶sub strip_tmpl_newline_whitespace {
Subroutine strip_tmpl_newline_whitespace: not called CC=1 SCAR=6.9
Pod undocumented
131 0 ▶ my $filter = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
132 0 my $text_ref = shift;
133 0 $$text_ref =~ s!^\s+(</?TMPL_[^>]+>)!$1!sg;
134 0 $$text_ref =~ s!(</?TMPL_[^>]>)[\r\n]+!$1!sg;
135 0 };
136 0 return $filter;
137 }
138  
139 ##
140 ## Concept taken from Compress::LeadingBlankSpaces to remove redundant data from the output stream
141 ##
142 ## -> Takes a string ref and returns string ref, so as to minimise data copying
143 ## -> skip over headers...
144 ## -> respects <pre>...</pre> tags
145 ## -> strips leading spaces
146 ## -> strips javascript comments
147 ## -> strips style comments
148 ## -> strips html comments
149 ## -> strips empty lines
150 ## -> Doesn't support multi-line stripping, as this complicates the issue somewhat
151 ##
152 0 ▶sub strip_redundant {
Subroutine strip_redundant: not called CC=1 SCAR=6.9
Pod undocumented
153 0 ▶ my $filter = sub {
Subroutine __ANON__: not called CC=29 SCAR=67.7
154 0 my $text_ref = shift;
155 0 my @buf = split('\n',$$text_ref);
156 0 my $output = '';
157 0 my $pre = 0;
158 0 my $script = 0;
159 0 my $style = 0;
160 0 my $headers = 1;
161
162 0 LOOP: foreach (@buf) {
163
164 ## skip over headers
165 0 ▶ if ($headers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headers) 0 0 0
166 0 ▶ /<[Hh][Tt][Mm][Ll]/o and $headers=0;
Branch: 1 branch
BranchTrueFalseTotal
/<[Hh][Tt][Mm][Ll]/o and $headers = 0 0 0 0
167 0 ▶ if ($headers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headers) 0 0 0
168 0 $output .= $_ ."\n";
169 0 next;
170 };
171 }
172
173 ## find any </pre>
174 0 ▶ if (/<\/[Pr][Rr][Ee]>/o) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[</[Pr][Rr][Ee]>]o) 0 0 0
175 0 $output .= $_ ."\n";
176 0 $pre=0;
177 0 next;
178 }
179 0 ▶ if ($pre) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre) 0 0 0
180 0 $output .= $_ ."\n";
181 0 next;
182 }
183
184 0 chomp;
185 0 ▶ next unless length;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 0 0
186
187 ## javascript comments
188 0 ▶ /<[Ss][Cc][Rr][Ii][Pp][Tt]/o and $script=1;
Branch: 1 branch
BranchTrueFalseTotal
/<[Ss][Cc][Rr][Ii][Pp][Tt]/o and $script = 1 0 0 0
189 0 ▶ /<\/[Ss][Cc][Rr][Ii][Pp][Tt]>/o and $script=0;
Branch: 1 branch
BranchTrueFalseTotal
m[</[Ss][Cc][Rr][Ii][Pp][Tt]>]o and $script = 0 0 0 0
190 0 ▶ if ($script) {
Branch: 1 branch
BranchTrueFalseTotal
if ($script) 0 0 0
191 0 ▶ /^\/\//o and not /-->/o and next;
Branch: 1 branch
BranchTrueFalseTotal
m[^//]o and not /-->/o and next 0 0 0
Condition0%0/3
m[^//]o and not /-->/o
!ll&&!rl&&r
000
MC/DC0%0/2
m[^//]o and not /-->/o
m[^//]o not /-->/o
Truth table0%0/3
A and not(B)
A= m[^//]oB= not /-->/o
ABresult
0X0
100
111
192 0 ▶ /(.*)\/\/(.*)$/o and not ($1 =~ /http/o or $2 =~ /-->/o) and s/\s*\/\/.*$//o and next unless length;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 0 0
Condition0%0/14
length $_ || m[(.*)//(.*)$]o && !($1 =~ /http/o || $2 =~ /-->/o) && s[\s*//.*$][]o && (next)
l!l&&r!l&&!r
000
m[(.*)//(.*)$]o and not $1 =~ /http/o || $2 =~ /-->/o and s[\s*//.*$][]o and next
!ll
00
m[(.*)//(.*)$]o and not $1 =~ /http/o || $2 =~ /-->/o and s[\s*//.*$][]o
!ll&&!rl&&r
000
m[(.*)//(.*)$]o and not $1 =~ /http/o || $2 =~ /-->/o
!ll&&!rl&&r
000
$1 =~ /http/o || $2 =~ /-->/o
l!l&&r!l&&!r
000
MC/DC0%0/5
length $_ || m[(.*)//(.*)$]o && !($1 =~ /http/o || $2 =~ /-->/o) && s[\s*//.*$][]o && (next)
length $_ m[(.*)//(.*)$]o $1 =~ /http/o $2 =~ /-->/o s[\s*//.*$][]o
Truth table0%0/6
A || B and not(C || D) and E
A= length $_B= m[(.*)//(.*)$]oC= $1 =~ /http/oD= $2 =~ /-->/oE= s[\s*//.*$][]o
ABCDEresult
1XXXX1
010011
00XXX0
011XX0
0101X0
010000
193 0 ▶ s/\s*\/\*.*\*\/\s*//o and next unless length;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 0 0
Condition0%0/5
length $_ || s[\s*/\*.*\*/\s*][]o && (next)
l!l&&r!l&&!r
000
s[\s*/\*.*\*/\s*][]o and next
!ll
00
MC/DC0%0/2
length $_ || s[\s*/\*.*\*/\s*][]o && (next)
length $_ s[\s*/\*.*\*/\s*][]o
Truth table0%0/3
A || B
A= length $_B= s[\s*/\*.*\*/\s*][]o
ABresult
1X1
011
000
194 }
195
196 ## support in-document styles
197 0 ▶ /<[Ss][Tt][Yy][Ll][Ee]/o and $style=1;
Branch: 1 branch
BranchTrueFalseTotal
/<[Ss][Tt][Yy][Ll][Ee]/o and $style = 1 0 0 0
198 0 ▶ /<\/[Ss][Tt][Yy][Ll][Ee]>/o and $style=0;
Branch: 1 branch
BranchTrueFalseTotal
m[</[Ss][Tt][Yy][Ll][Ee]>]o and $style = 0 0 0 0
199 0 ▶ if ($style) {
Branch: 1 branch
BranchTrueFalseTotal
if ($style) 0 0 0
200 0 ▶ s/\s*\/\*.*\*\/\s*//o and next unless length;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 0 0
Condition0%0/5
length $_ || s[\s*/\*.*\*/\s*][]o && (next)
l!l&&r!l&&!r
000
s[\s*/\*.*\*/\s*][]o and next
!ll
00
MC/DC0%0/2
length $_ || s[\s*/\*.*\*/\s*][]o && (next)
length $_ s[\s*/\*.*\*/\s*][]o
Truth table0%0/3
A || B
A= length $_B= s[\s*/\*.*\*/\s*][]o
ABresult
1X1
011
000
201 }
202
203 ## html comments
204 0 ▶ s/<!--.*-->//o unless ($style or $script);
Branch: 1 branch
BranchTrueFalseTotal
unless $style or $script 0 0 0
Condition0%0/3
$style or $script
l!l&&r!l&&!r
000
MC/DC0%0/2
$style or $script
$style $script
Truth table0%0/3
A or B
A= $styleB= $script
ABresult
1X1
011
000
205
206 ## trailing white space
207 0 s/\s+$//o;
208
209 ## leading white space
210 0 s/^\s+//o;
211
212 ## all white space
213 0 s/^\s*$//o;
214
215 ## if we got here and the line contains no content, dont do anything
216 0 ▶ next unless length;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 0 0
217
218 ## find any <pre>
219 0 ▶ /<[Pr][Rr][Ee]>/o and $pre++;
Branch: 1 branch
BranchTrueFalseTotal
/<[Pr][Rr][Ee]>/o and ++$pre 0 0 0
220
221 0 $output .= $_ ."\n";
222 }
223
224 0 $text_ref = \$output;
225 0 };
226 0 return $filter;
227 }
228  
229 #
230 # Simple newline strip
231 #
232 0 ▶sub strip_newline {
Subroutine strip_newline: not called CC=1 SCAR=6.9
Pod undocumented
233 0 ▶ my $filter = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
234 0 my $text_ref = shift;
235 0 $$text_ref =~ s/\n\| *//g;
236 0 };
237 0 return $filter;
238 }
239  
240 #
241 # strip out <TMPL_COMMENT>...</TMPL_COMMENT> entries
242 #
243 0 ▶sub tmpl_comment {
Subroutine tmpl_comment: not called CC=1 SCAR=6.9
Pod undocumented
244 0 ▶ my $filter = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
245 0 my $text_ref = shift;
246 0 my $match = qr/<(?:\!--\s*)?[Tt][Mm][Pp][Ll]_[Cc][Oo][Mm][Mm][Ee][Nn][Tt]\s*(?:--)?>.*?<(?:\!--\s*)?\/[Tt][Mm][Pp][Ll]_[Cc][Oo][Mm][Mm][Ee][Nn][Tt]\s*(?:--)?>/s;
247 0 $$text_ref =~ s/$match//g;
248 0 };
249 0 return $filter;
250 }
251  
252 #
253 # strip out <TMPL_FIXME>...</TMPL_FIXME> entries
254 #
255 0 ▶sub tmpl_fixme {
Subroutine tmpl_fixme: not called CC=1 SCAR=6.9
Pod undocumented
256 0 ▶ my $filter = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
257 0 my $text_ref = shift;
258 0 my $match = qr/<(?:\!--\s*)?[Tt][Mm][Pp][Ll]_[Ff][Ii][Xx][Mm][Ee]\s*(?:--)?>.*?<(?:\!--\s*)?\/[Tt][Mm][Pp][Ll]_[Ff][Ii][Xx][Mm][Ee]\s*(?:--)?>/s;
259 0 $$text_ref =~ s/$match//g;
260 0 };
261 0 return $filter;
262 }
263  
264 #
265 # strip out <TMPL_JOIN ...> entries
266 #
267 0 ▶sub tmpl_join {
Subroutine tmpl_join: not called CC=1 SCAR=6.9
Pod undocumented
268 0 ▶ my $filter = sub {
Subroutine __ANON__: not called CC=25 SCAR=64.8
269 0 my $text_ref = shift;
270 0 my $ht = shift;
271 0 my $options = $ht->{options};
272 0 ▶ die "TMPL_JOIN requires 'loop_context_vars' to be set" unless $options->{loop_context_vars};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"loop_context_vars"} 0 0 0
273 0 my @chunks = split(m!(?=<(?:\!--\s*)?[Tt][Mm][Pp][Ll]_[Jj][Oo][Ii][Nn]\s)!, $$text_ref);
274 0 ▶ for (my $count = 0; $count < @chunks; $count++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count < @chunks) 0 0 0
275 0 my $chunk = $chunks[$count];
276 0 ▶ if ($chunk =~ /^<
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk =~ m[^< (?:!--\s*)? (?: [Tt][Mm][Pp][Ll]_[Jj][Oo][Ii][Nn] ) \s+ # ESCAPE attribute (?: [Ee][Ss][Cc][Aa][Pp][Ee] \s*=\s* ( (?:"[^"]*") | (?:'[^']*') | (?:[^\s]*) ) # $1 => ESCAPE )? \s* # FIELD attribute (?: [Ff][Ii][Ee][Ll][Dd] \s*=\s* ( (?:"[^"]*") | (?:'[^']*') | (?:[^\s]*) ) # $2 => FIELD )? \s* # SEP attribute (?: [Ss][Ee][Pp](?:[Aa][Rr][Aa][Tt][Oo][Rr])? \s*=\s* ( (?:"[^"]*") | (?:'[^']*') | (?:[^\s]*) ) # $3 => SEP )? \s* # ESCAPE attribute (?: [Ee][Ss][Cc][Aa][Pp][Ee] \s*=\s* ( (?:"[^"]*") | (?:'[^']*') | (?:[^\s]*) ) # $4 => ESCAPE )? \s* # FIELD attribute (?: [Ff][Ii][Ee][Ll][Dd] \s*=\s* ( (?:"[^"]*") | (?:'[^']*') | (?:[^\s]*) ) # $5 => FIELD )? \s* # SEP attribute (?: [Ss][Ee][Pp](?:[Aa][Rr][Aa][Tt][Oo][Rr])? \s*=\s* ( (?:"[^"]*") | (?:'[^']*') | (?:[^\s]*) ) # $6 => SEP )? \s* # ESCAPE attribute (?: [Ee][Ss][Cc][Aa][Pp][Ee] \s*=\s* ( (?:"[^"]*") | (?:'[^']*') | (?:[^\s]*) ) # $7 => ESCAPE )? \s* # NAME attribute (?: (?: [Nn][Aa][Mm][Ee] \s*=\s* )? ( (?:"[^"]*") | (?:'[^']*') | (?:[^\s]*) ) # $8 => NAME )? \s* # ESCAPE attribute (?: [Ee][Ss][Cc][Aa][Pp][Ee] \s*=\s* ( (?:"[^"]*") | (?:'[^']*') | (?:[^\s]*) ) # $9 => ESCAPE )? \s* # FIELD attribute (?: [Ff][Ii][Ee][Ll][Dd] \s*=\s* ( (?:"[^"]*") | (?:'[^']*') | (?:[^\s]*) ) # $10 => FIELD )? \s* # SEP attribute (?: [Ss][Ee][Pp](?:[Aa][Rr][Aa][Tt][Oo][Rr])? \s*=\s* ( (?:"[^"]*") | (?:'[^']*') | (?:[^\s]*) ) # $11 => SEP )? \s* # ESCAPE attribute (?: [Ee][Ss][Cc][Aa][Pp][Ee] \s*=\s* ( (?:"[^"]*") | (?:'[^']*') | (?:[^\s]*) ) # $12 => ESCAPE )? \s* # FIELD attribute (?: [Ff][Ii][Ee][Ll][Dd] \s*=\s* ( (?:"[^"]*") | (?:'[^']*') | (?:[^\s]*) ) # $13 => FIELD )? \s* # SEP attribute (?: [Ss][Ee][Pp](?:[Aa][Rr][Aa][Tt][Oo][Rr])? \s*=\s* ( (?:"[^"]*") | (?:'[^']*') | (?:[^\s]*) ) # $14 => SEP )? \s* # ESCAPE attribute (?: [Ee][Ss][Cc][Aa][Pp][Ee] \s*=\s* ( (?:"[^"]*") | (?:'[^']*') | (?:[^\s]*) ) # $15 => ESCAPE )? \s* (?: (?:--) | (?:/) )?> (.*) # $16 => $post - text that comes after the tag $]osx) 0 0 0
277 (?:!--\s*)?
278 (?:
279 [Tt][Mm][Pp][Ll]_[Jj][Oo][Ii][Nn]
280 )
281  
282 \s+
283  
284 # ESCAPE attribute
285 (?:
286 [Ee][Ss][Cc][Aa][Pp][Ee]
287 \s*=\s*
288 (
289 (?:"[^"]*")
290 |
291 (?:'[^']*')
292 |
293 (?:[^\s]*)
294 ) # $1 => ESCAPE
295 )?
296
297 \s*
298
299 # FIELD attribute
300 (?:
301 [Ff][Ii][Ee][Ll][Dd]
302 \s*=\s*
303 (
304 (?:"[^"]*")
305 |
306 (?:'[^']*')
307 |
308 (?:[^\s]*)
309 ) # $2 => FIELD
310 )?
311
312 \s*
313
314 # SEP attribute
315 (?:
316 [Ss][Ee][Pp](?:[Aa][Rr][Aa][Tt][Oo][Rr])?
317 \s*=\s*
318 (
319 (?:"[^"]*")
320 |
321 (?:'[^']*')
322 |
323 (?:[^\s]*)
324 ) # $3 => SEP
325 )?
326
327 \s*
328
329 # ESCAPE attribute
330 (?:
331 [Ee][Ss][Cc][Aa][Pp][Ee]
332 \s*=\s*
333 (
334 (?:"[^"]*")
335 |
336 (?:'[^']*')
337 |
338 (?:[^\s]*)
339 ) # $4 => ESCAPE
340 )?
341
342 \s*
343
344 # FIELD attribute
345 (?:
346 [Ff][Ii][Ee][Ll][Dd]
347 \s*=\s*
348 (
349 (?:"[^"]*")
350 |
351 (?:'[^']*')
352 |
353 (?:[^\s]*)
354 ) # $5 => FIELD
355 )?
356
357 \s*
358
359 # SEP attribute
360 (?:
361 [Ss][Ee][Pp](?:[Aa][Rr][Aa][Tt][Oo][Rr])?
362 \s*=\s*
363 (
364 (?:"[^"]*")
365 |
366 (?:'[^']*')
367 |
368 (?:[^\s]*)
369 ) # $6 => SEP
370 )?
371
372 \s*
373
374 # ESCAPE attribute
375 (?:
376 [Ee][Ss][Cc][Aa][Pp][Ee]
377 \s*=\s*
378 (
379 (?:"[^"]*")
380 |
381 (?:'[^']*')
382 |
383 (?:[^\s]*)
384 ) # $7 => ESCAPE
385 )?
386
387 \s*
388
389 # NAME attribute
390 (?:
391 (?:
392 [Nn][Aa][Mm][Ee]
393 \s*=\s*
394 )?
395 (
396 (?:"[^"]*")
397 |
398 (?:'[^']*')
399 |
400 (?:[^\s]*)
401 ) # $8 => NAME
402 )?
403
404 \s*
405
406 # ESCAPE attribute
407 (?:
408 [Ee][Ss][Cc][Aa][Pp][Ee]
409 \s*=\s*
410 (
411 (?:"[^"]*")
412 |
413 (?:'[^']*')
414 |
415 (?:[^\s]*)
416 ) # $9 => ESCAPE
417 )?
418
419 \s*
420
421 # FIELD attribute
422 (?:
423 [Ff][Ii][Ee][Ll][Dd]
424 \s*=\s*
425 (
426 (?:"[^"]*")
427 |
428 (?:'[^']*')
429 |
430 (?:[^\s]*)
431 ) # $10 => FIELD
432 )?
433
434 \s*
435
436 # SEP attribute
437 (?:
438 [Ss][Ee][Pp](?:[Aa][Rr][Aa][Tt][Oo][Rr])?
439 \s*=\s*
440 (
441 (?:"[^"]*")
442 |
443 (?:'[^']*')
444 |
445 (?:[^\s]*)
446 ) # $11 => SEP
447 )?
448
449 \s*
450
451 # ESCAPE attribute
452 (?:
453 [Ee][Ss][Cc][Aa][Pp][Ee]
454 \s*=\s*
455 (
456 (?:"[^"]*")
457 |
458 (?:'[^']*')
459 |
460 (?:[^\s]*)
461 ) # $12 => ESCAPE
462 )?
463
464 \s*
465
466 # FIELD attribute
467 (?:
468 [Ff][Ii][Ee][Ll][Dd]
469 \s*=\s*
470 (
471 (?:"[^"]*")
472 |
473 (?:'[^']*')
474 |
475 (?:[^\s]*)
476 ) # $13 => FIELD
477 )?
478
479 \s*
480
481 # SEP attribute
482 (?:
483 [Ss][Ee][Pp](?:[Aa][Rr][Aa][Tt][Oo][Rr])?
484 \s*=\s*
485 (
486 (?:"[^"]*")
487 |
488 (?:'[^']*')
489 |
490 (?:[^\s]*)
491 ) # $14 => SEP
492 )?
493
494 \s*
495
496 # ESCAPE attribute
497 (?:
498 [Ee][Ss][Cc][Aa][Pp][Ee]
499 \s*=\s*
500 (
501 (?:"[^"]*")
502 |
503 (?:'[^']*')
504 |
505 (?:[^\s]*)
506 ) # $15 => ESCAPE
507 )?
508
509 \s*
510  
511 (?:
512 (?:--)
513 |
514 (?:\/)
515 )?>
516 (.*) # $16 => $post - text that comes after the tag
517  
518 $/sxo) {
519 0 my $name = $8;
520 0 ▶ if (defined $name and length $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and length $name) 0 0 0
Condition0%0/3
defined $name and length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
521 0 ▶ my $escape = defined $1 ? $1 : defined $4 ? $4 : defined $7 ? $7 : defined $9 ? $9 : defined $12 ? $12 : defined $15 ? $15 : '';
Branch: 6 branches
BranchTrueFalseTotal
defined $1 ? : 0 0 0
defined $4 ? : 0 0 0
defined $7 ? : 0 0 0
defined $9 ? : 0 0 0
defined $12 ? : 0 0 0
defined $15 ? : 0 0 0
522 0 ▶ my $sep = defined $3 ? $3 : defined $6 ? $6 : defined $11 ? $11 : defined $14 ? $14 : '';
Branch: 4 branches
BranchTrueFalseTotal
defined $3 ? : 0 0 0
defined $6 ? : 0 0 0
defined $11 ? : 0 0 0
defined $14 ? : 0 0 0
523 0 ▶ my $field = defined $2 ? $2 : defined $5 ? $5 : defined $10 ? $10 : defined $13 ? $13 : '';
Branch: 4 branches
BranchTrueFalseTotal
defined $2 ? : 0 0 0
defined $5 ? : 0 0 0
defined $10 ? : 0 0 0
defined $13 ? : 0 0 0
524 0 ▶ my $post = defined $16 ? $16 : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $16 ? : 0 0 0
525 0 ▶ $field = '__value__' unless length($field);
Branch: 1 branch
BranchTrueFalseTotal
unless length $field 0 0 0
526 0 ▶ $sep = substr($sep,1,length($sep)-2) if ($sep =~ /^['"]/);
Branch: 1 branch
BranchTrueFalseTotal
if $sep =~ /^['"]/ 0 0 0
527 0 ▶ $escape = "ESCAPE=$escape" if $escape;
Branch: 1 branch
BranchTrueFalseTotal
if $escape 0 0 0
528 0 ▶ my $join = length $sep ? "<TMPL_UNLESS __last__>$sep</TMPL_UNLESS>" : "";
Branch: 1 branch
BranchTrueFalseTotal
length $sep ? : 0 0 0
529 0 $chunk = "<TMPL_LOOP $name><TMPL_VAR NAME=$field $escape>$join</TMPL_LOOP>";
530 0 $chunks[$count] = $chunk.$post;
531 }
532 }
533 }
534 0 $$text_ref = join('',@chunks);
535 0 };
536 0 return $filter;
537 }
538  
539 #
540 # allow <TMPL_CONSTANT NAME="variable" VALUE="value">
541 # note this only works for TMPL_VAR's
542 #
543 0 ▶sub tmpl_constant {
Subroutine tmpl_constant: not called CC=1 SCAR=6.9
Pod undocumented
544 0 ▶ my $filter = sub {
Subroutine __ANON__: not called CC=16 SCAR=56.1
545 0 my $text_ref = shift;
546 0 my $match = qr/<(?:\!--\s*)?[Tt][Mm][Pp][Ll]_[Cc][Oo][Nn][Ss][Tt][Aa][Nn][Tt]\s*[Nn][Aa][Mm][Ee]\s*=(.*?)\s*[Vv][Aa][Ll][Uu][Ee]\s*=(.*?)\s*(?:--)?>/;
547 0 my @taglist = $$text_ref =~ m/$match/g;
548 0 ▶ return unless (@taglist > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless @taglist > 0 0 0 0
549 0 my $strip = qr/^(?:'(.*)')|(?:"(.*)")$/;
550 0 my %set_params;
551 0 ▶ while (@taglist) {
Branch: 1 branch
BranchTrueFalseTotal
if (@taglist) 0 0 0
552 0 my ($t,$v) = (shift @taglist,shift @taglist);
553 0 $t =~ m/$strip/;
554 0 ▶ $t = defined $1 ? $1 : defined $2 ? $2 : $t;
Branch: 2 branches
BranchTrueFalseTotal
defined $1 ? : 0 0 0
defined $2 ? : 0 0 0
555 0 $v =~ m/$strip/;
556 0 ▶ $v = defined $1 ? $1 : defined $2 ? $2 : $v;
Branch: 2 branches
BranchTrueFalseTotal
defined $1 ? : 0 0 0
defined $2 ? : 0 0 0
557 0 $set_params{$t} = $v;
558 }
559 0 $$text_ref =~ s/$match//g;
560 0 my $split = qr/(?=<(?:\!--\s*)?[Tt][Mm][Pp][Ll]_[Vv][Aa][Rr]\s+)/;
561 0 my @chunks = split ($split, $$text_ref);
562 0 ▶ return unless (@chunks > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless @chunks > 0 0 0 0
563 0 my @output;
564 0 my $chunker = qr/^(?=
565 <(?:!--\s*)?
566 [Tt][Mm][Pp][Ll]_[Vv][Aa][Rr]\s+(?:[Nn][Aa][Mm][Ee]\s*=\s*)?
567 (?:
568 "([^">]*)"
569 |
570 '([^'>]*)'
571 |
572 ([^\s=>]*)
573 )
574 \s*(?:[^>])?(?:--)?>
575 (.*)
576 )/sx;
577 0 foreach my $chunk (@chunks) {
578 0 ▶ if ($chunk =~ $chunker) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk =~ /$chunker/) 0 0 0
579 0 ▶ my $name = defined $1 ? $1 : defined $2 ? $2 : defined $3 ? $3 : undef;
Branch: 3 branches
BranchTrueFalseTotal
defined $1 ? : 0 0 0
defined $2 ? : 0 0 0
defined $3 ? : 0 0 0
580 0 ▶ if (defined $name and exists $set_params{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and exists $set_params{$name}) 0 0 0
Condition0%0/3
defined $name and exists $set_params{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and exists $set_params{$name}
defined $name exists $set_params{$name}
Truth table0%0/3
A and B
A= defined $nameB= exists $set_params{$name}
ABresult
0X0
100
111
581 0 $chunk = $set_params{$name};
582 0 ▶ $chunk .= $4 if $4;
Branch: 1 branch
BranchTrueFalseTotal
if $4 0 0 0
583 }
584 }
585 0 push @output, $chunk;
586 }
587 0 $$text_ref = join '',@output;
588 0 };
589 0 return $filter;
590 }
591  
592 #
593 # turns the '\r' line feed to a '\n', for the Mac OS
594 #
595 0 ▶sub mac_os {
Subroutine mac_os: not called CC=1 SCAR=6.9
Pod undocumented
596 0 ▶ my $filter = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
597 0 my $text_ref = shift;
598 0 my $match = qr/\r/s;
599 0 $$text_ref =~ s/$match/\n/g;
600 0 };
601 0 return $filter;
602 }
603  
604 1 1;
605 __END__
↑ Summary Template.pm »