Obj2HTML.pm

filter: Statementstmt 21.8% 94 / 430 Branchbran 18.4% 49 / 266 Conditioncond 13.7% 11 / 80 MC/DCmcdc 0.0% 0 / 51 Subroutinesub 36.5% 15 / 41 Podpod 0.0% 0 / 29 totaltotal 18.8% 169 / 897 SCAR 96.3
CC
171
Cov
20%
gen
7595.4
find
110.0
append
72.0
CRAP 15229.4
↑ Summary Obj2HTML/Plugin/SemanticUIForms.pm »
1 package HTML::Obj2HTML;
2  
3 1 $HTML::Obj2HTML::VERSION = '0.11';
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Text::Markdown;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Text::Pluralize;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Locale::Currency::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use List::MoreUtils qw(uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Module::Pluggable require => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 use constant {
17 1 END_TAG_OPTIONAL => 0x0,
18 END_TAG_REQUIRED => 0x1,
19 END_TAG_FORBIDDEN => 0x2,
20 OBSOLETE => 0x4
21 1 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 # storage is a sort of top-level stash for an object. It doesn't have to be used
24 # you can get away with building your own object variable and passing it to "gen"
25 1 my $storage = [];
26 # Opts are simple storage that could be referred to in extensions (not typically
27 # in the base class). A good example is "readonly" (true/false)
28 1 my %opt;
29 # extensions are stored here
30 1 my %extensions = ();
31 # snippets are stored here
32 1 my $snippets = {};
33 # A dictionary of substitutions are stored here and can be referenced in _content_
34 1 my %dictionary;
35  
36 my %dofiles;
37  
38 # Whether or not to close empty tags with /
39 1 my $mode = "XHTML";
40 # Whether or not to output a warning when something that doesn't look like a valid
41 # html 5 tag is used
42 1 my $warn_on_unknown_tag = 1;
43 # Whether or not to use HTML::FromArrayref format ("elementname {attributes} content" triplets)
44 1 my $html_fromarrayref_format = 0;
45 # Default currency to use
46 1 my $default_currency = "GBP";
47  
48 1 our $db;
49  
50 # Load up the extensions
51 1 plugins();
52  
53 sub import {
54 1 ▶ my @extra = ();
Subroutine import: called CC=8 SCAR=33.3
55 1 ▶ while (my $opt = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $opt = shift()) 1 1 2
56 1 ▶ if ($opt eq "components") {
Branch: 5 branches
BranchTrueFalseTotal
if ($opt eq 'components') { } 0 1 1
elsif ($opt eq 'default_currency') { } 0 1 1
elsif ($opt eq 'mode') { } 0 1 1
elsif ($opt eq 'warn_on_unknown_tag') { } 0 1 1
elsif ($opt eq 'html_fromarrayref_format') { } 0 1 1
57 0 my $arg = shift;
58 0 foreach my $file (split("\n", `find $arg -name "*.po"`)) {
59 0 chomp($file);
60 0 my $l = $file;
61 0 $l =~ s/$arg\///;
62 0 $l =~ s/\.po$//;
63 0 $l =~ s/\//::/g;
64 #print STDERR "HTML::Obj2HTML registering component $l\n";
65 HTML::Obj2HTML::register_extension($l, {
66 tag => "",
67 before => sub {
68 0 ▶ my $o = shift;
Subroutine __ANON__: not called CC=2 SCAR=17.9
69 0 ▶ if (ref $o eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $o eq 'HASH') { } 0 0 0
70 0 return HTML::Obj2HTML::fetch($file, $o);
71 } else {
72 0 return HTML::Obj2HTML::fetch($file, { _ => $o });
73 }
74 }
75 0 });
76 }
77 }
78 elsif ($opt eq "default_currency") {
79 0 $default_currency = shift;
80 }
81 elsif ($opt eq "mode") {
82 0 $mode = shift;
83 }
84 elsif ($opt eq "warn_on_unknown_tag") {
85 0 $warn_on_unknown_tag = shift;
86 }
87 elsif ($opt eq "html_fromarrayref_format") {
88 0 $html_fromarrayref_format = shift;
89 }
90 else {
91 1 push(@extra, $opt);
92 }
93 }
94 }
95  
96 1 my %tags = (
97 a => END_TAG_REQUIRED,
98 abbr => END_TAG_REQUIRED,
99 acronym => END_TAG_REQUIRED | OBSOLETE,
100 address => END_TAG_REQUIRED,
101 applet => END_TAG_REQUIRED | OBSOLETE,
102 area => END_TAG_FORBIDDEN,
103 article => END_TAG_REQUIRED,
104 aside => END_TAG_REQUIRED,
105 audio => END_TAG_REQUIRED,
106 b => END_TAG_REQUIRED,
107 base => END_TAG_FORBIDDEN,
108 basefont => END_TAG_FORBIDDEN | OBSOLETE,
109 bdi => END_TAG_REQUIRED,
110 bdo => END_TAG_REQUIRED,
111 big => END_TAG_REQUIRED | OBSOLETE,
112 blockquote => END_TAG_REQUIRED,
113 body => END_TAG_OPTIONAL,
114 br => END_TAG_FORBIDDEN,
115 button => END_TAG_REQUIRED,
116 canvas => END_TAG_REQUIRED,
117 caption => END_TAG_REQUIRED,
118 center => END_TAG_REQUIRED,
119 cite => END_TAG_REQUIRED,
120 code => END_TAG_REQUIRED,
121 col => END_TAG_FORBIDDEN,
122 colgroup => END_TAG_REQUIRED,
123 data => END_TAG_REQUIRED,
124 datalist => END_TAG_REQUIRED,
125 dd => END_TAG_OPTIONAL,
126 del => END_TAG_REQUIRED,
127 details => END_TAG_REQUIRED,
128 dfn => END_TAG_REQUIRED,
129 dialog => END_TAG_REQUIRED,
130 dir => END_TAG_REQUIRED | OBSOLETE,
131 div => END_TAG_REQUIRED,
132 dl => END_TAG_REQUIRED,
133 dt => END_TAG_OPTIONAL,
134 em => END_TAG_REQUIRED,
135 embed => END_TAG_FORBIDDEN,
136 fielset => END_TAG_REQUIRED,
137 figcaption => END_TAG_REQUIRED,
138 figure => END_TAG_REQUIRED,
139 font => END_TAG_REQUIRED | OBSOLETE,
140 footer => END_TAG_REQUIRED,
141 form => END_TAG_REQUIRED,
142 frame => END_TAG_FORBIDDEN | OBSOLETE,
143 frameset => END_TAG_REQUIRED | OBSOLETE,
144 head => END_TAG_OPTIONAL,
145 header => END_TAG_REQUIRED,
146 hgroup => END_TAG_REQUIRED,
147 h1 => END_TAG_REQUIRED,
148 h2 => END_TAG_REQUIRED,
149 h3 => END_TAG_REQUIRED,
150 h4 => END_TAG_REQUIRED,
151 h5 => END_TAG_REQUIRED,
152 h6 => END_TAG_REQUIRED,
153 hr => END_TAG_FORBIDDEN,
154 html => END_TAG_OPTIONAL,
155 i => END_TAG_REQUIRED,
156 iframe => END_TAG_REQUIRED,
157 img => END_TAG_FORBIDDEN,
158 input => END_TAG_FORBIDDEN,
159 ins => END_TAG_REQUIRED,
160 kbd => END_TAG_REQUIRED,
161 keygen => END_TAG_FORBIDDEN,
162 label => END_TAG_REQUIRED,
163 legend => END_TAG_REQUIRED,
164 li => END_TAG_REQUIRED,
165 link => END_TAG_FORBIDDEN,
166 main => END_TAG_REQUIRED,
167 map => END_TAG_REQUIRED,
168 mark => END_TAG_REQUIRED,
169 menu => END_TAG_REQUIRED,
170 menuitem => END_TAG_FORBIDDEN,
171 meta => END_TAG_FORBIDDEN,
172 meter => END_TAG_REQUIRED,
173 nav => END_TAG_REQUIRED,
174 noframes => END_TAG_REQUIRED | OBSOLETE,
175 noscript => END_TAG_REQUIRED,
176 object => END_TAG_REQUIRED,
177 ol => END_TAG_REQUIRED,
178 optgroup => END_TAG_REQUIRED,
179 option => END_TAG_OPTIONAL,
180 output => END_TAG_REQUIRED,
181 p => END_TAG_OPTIONAL,
182 param => END_TAG_FORBIDDEN,
183 picture => END_TAG_REQUIRED,
184 pre => END_TAG_REQUIRED,
185 progress => END_TAG_REQUIRED,
186 q => END_TAG_REQUIRED,
187 rp => END_TAG_REQUIRED,
188 rt => END_TAG_REQUIRED,
189 ruby => END_TAG_REQUIRED,
190 s => END_TAG_REQUIRED,
191 samp => END_TAG_REQUIRED,
192 script => END_TAG_REQUIRED,
193 section => END_TAG_REQUIRED,
194 select => END_TAG_REQUIRED,
195 small => END_TAG_REQUIRED,
196 source => END_TAG_FORBIDDEN,
197 span => END_TAG_REQUIRED,
198 strike => END_TAG_REQUIRED | OBSOLETE,
199 strong => END_TAG_REQUIRED,
200 style => END_TAG_REQUIRED,
201 sub => END_TAG_REQUIRED,
202 summary => END_TAG_REQUIRED,
203 sup => END_TAG_REQUIRED,
204 svp => END_TAG_REQUIRED,
205 table => END_TAG_REQUIRED,
206 tbody => END_TAG_REQUIRED,
207 td => END_TAG_REQUIRED,
208 template => END_TAG_REQUIRED,
209 textarea => END_TAG_REQUIRED,
210 tfoot => END_TAG_REQUIRED,
211 th => END_TAG_OPTIONAL,
212 thead => END_TAG_REQUIRED,
213 time => END_TAG_REQUIRED,
214 title => END_TAG_REQUIRED,
215 tr => END_TAG_OPTIONAL,
216 track => END_TAG_FORBIDDEN,
217 tt => END_TAG_REQUIRED | OBSOLETE,
218 u => END_TAG_REQUIRED,
219 ul => END_TAG_REQUIRED,
220 var => END_TAG_REQUIRED,
221 video => END_TAG_REQUIRED,
222 wbr => END_TAG_FORBIDDEN
223 );
224  
225 sub flush {
226 0 ▶ %opt = ();
Subroutine flush: not called CC=1 SCAR=6.9
Pod undocumented
227 0 %dictionary = ();
228 0 $snippets = {};
229 }
230 sub set_opt {
231 0 ▶ my $key = shift;
Subroutine set_opt: not called CC=1 SCAR=6.9
Pod undocumented
232 0 my $val = shift;
233 0 $opt{$key} = $val;
234 }
235 sub get_opt {
236 0 ▶ my $key = shift;
Subroutine get_opt: not called CC=1 SCAR=6.9
Pod undocumented
237 0 return $opt{$key};
238 }
239  
240 sub set_dbh {
241 0 ▶ $db = shift;
Subroutine set_dbh: not called CC=1 SCAR=6.9
Pod undocumented
242 }
243  
244 sub set_dictionary {
245 0 ▶ my $hashref = shift;
Subroutine set_dictionary: not called CC=1 SCAR=6.9
Pod undocumented
246 0 %dictionary = %{$hashref};
247 }
248 sub add_dictionary_items {
249 0 ▶ my $hashref = shift;
Subroutine add_dictionary_items: not called CC=1 SCAR=6.9
Pod undocumented
250 0 %dictionary = (%dictionary, %{$hashref});
251 }
252  
253 sub set_snippet {
254 0 ▶ my $name = shift;
Subroutine set_snippet: not called CC=2 SCAR=17.9
Pod undocumented
255 0 my $obj = shift;
256 0 ▶ if (!ref $obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $obj) 0 0 0
257 0 my $args = shift;
258 0 $obj = fetch($obj, $args);
259 }
260 0 $snippets->{$name} = $obj;
261 }
262 sub get_snippet {
263 0 ▶ my $name = shift;
Subroutine get_snippet: not called CC=1 SCAR=6.9
Pod undocumented
264 0 return $snippets->{$name};
265 }
266 sub append_snippet {
267 0 ▶ my $name = shift;
Subroutine append_snippet: not called CC=4 SCAR=30.0
Pod undocumented
268 0 my $obj = shift;
269 0 ▶ if (!defined $snippets->{$name}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $snippets->{$name}) { } 0 0 0
elsif (ref $snippets->{$name} ne 'ARRAY') { } 0 0 0
270 0 $snippets->{$name} = [];
271 } elsif (ref $snippets->{$name} ne "ARRAY") {
272 0 return;
273 }
274 0 ▶ if (!ref $obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $obj) 0 0 0
275 0 my $args = shift;
276 0 $obj = fetch($obj, $args);
277 }
278 0 push(@{$snippets->{$name}}, $obj);
279 }
280  
281  
282  
283  
284 sub do {
285 0 ▶ HTML::Obj2HTML::print($storage);
Subroutine do: not called CC=1 SCAR=6.9
Pod undocumented
286 }
287  
288 sub init {
289 0 ▶ $storage = shift;
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
290 }
291  
292 sub sort {
293 0 ▶ my $parentblock = shift;
Subroutine sort: not called CC=2 SCAR=17.9
Pod undocumented
294 0 my $sortsub = shift;
295 0 my $arr = shift;
296 0 my @ret = ();
297  
298 0 foreach my $c (sort { $sortsub->($a,$b) } @$arr) {
299 0 push(@ret, $parentblock, $c);
300 }
301 0 return \@ret;
302 }
303  
304 sub iterate {
305 0 ▶ my $parentblock = shift;
Subroutine iterate: not called CC=6 SCAR=37.4
Pod undocumented
306 0 my $arr = shift;
307 0 ▶ my $collapsearrayrefs = 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
308 0 my @ret = ();
309  
310 0 foreach my $c (@$arr) {
311 0 ▶ if (ref($c) eq "ARRAY" && $collapsearrayrefs) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $c eq 'ARRAY' and $collapsearrayrefs) { } 0 0 0
elsif (defined $c) { } 0 0 0
Condition0%0/3
ref $c eq "ARRAY" and $collapsearrayrefs
!ll&&!rl&&r
000
MC/DC0%0/2
ref $c eq "ARRAY" and $collapsearrayrefs
ref $c eq "ARRAY" $collapsearrayrefs
Truth table0%0/3
A and B
A= ref $c eq "ARRAY"B= $collapsearrayrefs
ABresult
0X0
100
111
312 0 my $itr = iterate($parentblock, $c);
313 0 push(@ret, @{$itr});
314 } elsif (defined $c) {
315 0 push(@ret, $parentblock, $c);
316 }
317 }
318 0 return \@ret;
319 }
320  
321 sub fetchraw {
322 0 ▶ my $f = shift;
Subroutine fetchraw: not called CC=3 SCAR=24.8
Pod undocumented
323 # If we want an absolute path, use document root
324 0 ▶ if ($f =~ /\//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f =~ m[/]) 0 0 0
325 0 $f = $ENV{DOCUMENT_ROOT}.$f;
326 }
327 # And don't allow back-tracking through the file system!
328 0 $f =~ s|\/[\.\/]+|\/|;
329 0 my $rawfile;
330 0 ▶ if (-e $f) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $f) 0 0 0
331 0 local($/);
332 0 open(RAWFILE, $f);
333 0 $rawfile = <RAWFILE>;
334 0 close(RAWFILE);
335 }
336 0 return $rawfile;
337 }
338 sub fetch {
339 0 ▶ my $f = shift;
Subroutine fetch: not called CC=7 SCAR=40.3
Pod undocumented
340 0 our $args = shift;
341 0 my $fetch;
342 0 ▶ if ($f !~ /^[\.\/]/) { $f = "./".$f; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($f =~ m[^[\./]]) 0 0 0
343 0 ▶ if (-e $f) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $f) { } 0 0 0
344 0 $fetch = do($f);
345 0 ▶ if (!$fetch) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fetch) 0 0 0
346 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
347 0 carp "Do failed for $f at error: $@\n";
348 }
349 0 ▶ if ($!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($!) 0 0 0
350 0 carp "Do failed for $f bang error: $!\n";
351 }
352 }
353 0 ▶ if (ref $fetch eq "CODE") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fetch eq "CODE") 0 0 0
354 0 $fetch = $fetch->($args);
355 }
356  
357 } else {
358 0 my $pwd = `pwd`;
359 0 chomp($pwd);
360 0 carp "Couldn't find $f ($pwd)\n";
361 0 return [];
362 }
363 0 return $fetch;
364 }
365 sub display {
366 0 ▶ my $f = shift;
Subroutine display: not called CC=1 SCAR=6.9
Pod undocumented
367 0 my $args = shift;
368 0 my $ret = fetch($f, $args);
369 0 print gen($ret);
370 }
371 sub push {
372 0 ▶ my $arr = shift;
Subroutine push: not called CC=1 SCAR=6.9
Pod undocumented
373 0 my $f = shift;
374 0 my $arg = shift;
375 0 my $ret = fetch($f,$arg);
376 0 push(@{$arr}, @{$ret});
377 }
378 sub append {
379 0 ▶ my $insertpoint = shift;
Subroutine append: not called CC=8 SCAR=42.8
Pod undocumented
380 0 my $inserto = shift;
381 0 my $args = shift;
382 0 ▶ if (!ref $inserto && $inserto =~ /staticfile:(.*)/) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $inserto and $inserto =~ /staticfile:(.*)/) { } 0 0 0
elsif (not ref $inserto and $inserto =~ /file:(.*)/) { } 0 0 0
Condition0%0/3
not ref $inserto and $inserto =~ /staticfile:(.*)/
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $inserto and $inserto =~ /staticfile:(.*)/
not ref $inserto $inserto =~ /staticfile:(.*)/
Truth table0%0/3
not(A) and B
A= not ref $insertoB= $inserto =~ /staticfile:(.*)/
ABresult
0X0
100
111
383 0 $inserto = HTML::Obj2HTML::fetchraw($1);
384 ▶ } elsif (!ref $inserto && $inserto =~ /file:(.*)/) {
Condition0%0/3
not ref $inserto and $inserto =~ /file:(.*)/
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $inserto and $inserto =~ /file:(.*)/
not ref $inserto $inserto =~ /file:(.*)/
Truth table0%0/3
not(A) and B
A= not ref $insertoB= $inserto =~ /file:(.*)/
ABresult
0X0
100
111
385 0 $inserto = fetch($1, $args);
386 }
387 0 my $o = find($storage, $insertpoint);
388 0 foreach my $e (@{$o}) {
389 # convert to common format
390 0 ▶ if (!ref $e->[1]) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $e->[1]) { } 0 0 0
elsif (ref $e->[1] eq 'ARRAY') { } 0 0 0
391 0 $e->[1] = { _ => [ _ => $e->[1] ] };
392 } elsif (ref $e->[1] eq "ARRAY") {
393 0 $e->[1] = { _ => $e->[1] };
394 }
395 0 CORE::push(@{$e->[1]->{_}}, @{$inserto});
396 }
397 }
398 sub prepend {
399 0 ▶ my $insertpoint = shift;
Subroutine prepend: not called CC=8 SCAR=42.8
Pod undocumented
400 0 my $inserto = shift;
401 0 my $args = shift;
402 0 ▶ if (!ref $inserto && $inserto =~ /staticfile:(.*)/) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $inserto and $inserto =~ /staticfile:(.*)/) { } 0 0 0
elsif (not ref $inserto and $inserto =~ /file:(.*)/) { } 0 0 0
Condition0%0/3
not ref $inserto and $inserto =~ /staticfile:(.*)/
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $inserto and $inserto =~ /staticfile:(.*)/
not ref $inserto $inserto =~ /staticfile:(.*)/
Truth table0%0/3
not(A) and B
A= not ref $insertoB= $inserto =~ /staticfile:(.*)/
ABresult
0X0
100
111
403 0 $inserto = HTML::Obj2HTML::fetchraw($1);
404 ▶ } elsif (!ref $inserto && $inserto =~ /file:(.*)/) {
Condition0%0/3
not ref $inserto and $inserto =~ /file:(.*)/
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $inserto and $inserto =~ /file:(.*)/
not ref $inserto $inserto =~ /file:(.*)/
Truth table0%0/3
not(A) and B
A= not ref $insertoB= $inserto =~ /file:(.*)/
ABresult
0X0
100
111
405 0 $inserto = fetch($1, $args);
406 }
407 0 my $o = find($storage, $insertpoint);
408 0 foreach my $e (@{$o}) {
409 # convert to common format
410 0 ▶ if (!ref $e->[1]) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $e->[1]) { } 0 0 0
elsif (ref $e->[1] eq 'ARRAY') { } 0 0 0
411 0 $e->[1] = { _ => [ _ => $e->[1] ] };
412 } elsif (ref $e->[1] eq "ARRAY") {
413 0 $e->[1] = { _ => $e->[1] };
414 }
415 0 unshift(@{$e->[1]->{_}}, @{$inserto});
416 }
417 }
418  
419 sub find {
420 0 ▶ my $o = shift;
Subroutine find: not called CC=10 SCAR=47.0
Pod undocumented
421 0 my $query = shift;
422 0 ▶ my $ret = shift || [];
Condition0%0/2
shift() || []
l!l
00
MC/DC0%0/1
shift() || []
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
423  
424 0 my @tags = @{$o};
425 0 ▶ while (@tags) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tags) 0 0 0
426 0 my $tag = shift(@tags);
427 0 my $attr = shift(@tags);
428  
429 0 ▶ if (ref $attr eq "ARRAY") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $attr eq 'ARRAY') { } 0 0 0
elsif (ref $attr eq 'HASH') { } 0 0 0
430 0 find($attr, $query, $ret);
431 } elsif (ref $attr eq "HASH") {
432 0 my %attrs = %{$attr};
433 0 my $content;
434 0 ▶ if ($attrs{_}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs{"_"}) 0 0 0
435 0 find($attrs{_}, $query, $ret);
436 }
437 0 ▶ if ($query =~ /\#(.*)/ && $attrs{id} eq $1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($query =~ /\#(.*)/ and $attrs{'id'} eq $1) { } 0 0 0
elsif ($query =~ /^([^\#\.]\S*)/ and $tag eq $1) { } 0 0 0
Condition0%0/3
$query =~ /\#(.*)/ and $attrs{"id"} eq $1
!ll&&!rl&&r
000
MC/DC0%0/2
$query =~ /\#(.*)/ and $attrs{"id"} eq $1
$query =~ /\#(.*)/ $attrs{"id"} eq $1
Truth table0%0/3
A and B
A= $query =~ /\#(.*)/B= $attrs{"id"} eq $1
ABresult
0X0
100
111
438 0 CORE::push(@{$ret}, [$tag, $attr]);
439 ▶ } elsif ($query =~ /^([^\#\.]\S*)/ && $tag eq $1) {
Condition0%0/3
$query =~ /^([^\#\.]\S*)/ and $tag eq $1
!ll&&!rl&&r
000
MC/DC0%0/2
$query =~ /^([^\#\.]\S*)/ and $tag eq $1
$query =~ /^([^\#\.]\S*)/ $tag eq $1
Truth table0%0/3
A and B
A= $query =~ /^([^\#\.]\S*)/B= $tag eq $1
ABresult
0X0
100
111
440 0 CORE::push(@{$ret}, [$tag, $attr]);
441 }
442 }
443 }
444 0 return $ret;
445 }
446  
447 sub gen {
448 4 ▶ my $o = shift;
Subroutine gen: called CC=120 SCAR=89.4
Pod undocumented
449 4 my $ret = "";
450  
451 4 ▶ if (!ref $o) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $o) 0 4 4
452 0 $o = web_escape($o);
453 0 return $o;
454 }
455 4 ▶ if (ref $o eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $o eq "HASH") 0 4 4
456 0 carp "HTML::Obj2HTML::gen called with a hash reference!";
457 0 return "";
458 }
459 4 ▶ if (ref $o eq "CODE") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $o eq "CODE") 0 4 4
460 0 eval {
461 0 $ret = HTML::Obj2HTML::gen($o->());
462 };
463 0 ▶ if ($@) { carp "Error parsing HTML::Obj2HTML objects when calling code ref: $@\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
464 0 return $ret;
465 }
466 4 ▶ if (ref $o ne "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $o ne "ARRAY") 0 4 4
467 0 return "";
468 }
469  
470 4 my @tags = @{$o};
471 4 ▶ while (@tags) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tags) 6 4 10
472 6 my $tag = shift(@tags);
473 6 ▶ if (!defined $tag) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tag) 0 6 6
474 0 next;
475 }
476 6 ▶ if (ref $tag eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tag eq "ARRAY") 0 6 6
477 0 $ret .= HTML::Obj2HTML::gen($tag);
478 0 next;
479 }
480 6 ▶ if (ref $tag eq "CODE") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tag eq "CODE") 0 6 6
481 0 eval {
482 0 $ret .= HTML::Obj2HTML::gen($tag->());
483 };
484 0 ▶ if ($@) { carp "Error parsing HTML::Obj2HTML objects when calling code ref: $@\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
485 0 next;
486 }
487 6 ▶ if ($tag =~ /_(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /_(.+)/) 0 6 6
488 0 $ret .= HTML::Obj2HTML::gen(get_snippet($1));
489 0 next;
490 }
491 # If the tag has a space it's not a valid tag, so output it as content instead
492 6 ▶ if ($tag =~ /\s/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /\s/) 0 6 6
493 0 $ret .= $tag;
494 0 next;
495 }
496  
497 6 my $attr = shift(@tags);
498 6 ▶ if ($html_fromarrayref_format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($html_fromarrayref_format) 0 6 6
499 # Make this module behave more like HTML::FromArrayref, where you have elementname, { attributes }, content
500 # This should be considered for backward compatibility; The find routine would struggle with this...
501 0 ▶ if (ref $attr eq "HASH" && ($tags{$tag} & END_TAG_FORBIDDEN) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr eq "HASH" and ($tags{$tag} & 2) == 0) 0 0 0
Condition0%0/3
ref $attr eq "HASH" and ($tags{$tag} & 2) == 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref $attr eq "HASH" and ($tags{$tag} & 2) == 0
ref $attr eq "HASH" ($tags{$tag} & 2) == 0
Truth table0%0/3
A and B
A= ref $attr eq "HASH"B= ($tags{$tag} & 2) == 0
ABresult
0X0
100
111
502 0 $attr->{"_"} = shift(@tags);
503 }
504 }
505 # Typically linking to another file will return an arrayref, but could equally return a hashref to also set the
506 # attributes of the element calling it
507 6 ▶ if (!ref $attr && $attr =~ /staticfile:(.+)/) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $attr and $attr =~ /staticfile:(.+)/) { } 0 6 6
elsif (not ref $attr and $attr =~ /file:(.+)/) { } 0 6 6
elsif (not ref $attr and $attr =~ /raw:(.+)/) { } 0 9 9
Condition66%2/3
not ref $attr and $attr =~ /staticfile:(.+)/
!ll&&!rl&&r
330
MC/DC0%0/2
not ref $attr and $attr =~ /staticfile:(.+)/
not ref $attr $attr =~ /staticfile:(.+)/
Truth table66%2/3
not(A) and B
A= not ref $attrB= $attr =~ /staticfile:(.+)/
ABresult
0X0
100
111
508 0 $attr = HTML::Obj2HTML::fetchraw($1);
509 ▶ } elsif (!ref $attr && $attr =~ /file:(.+)/) {
Condition66%2/3
not ref $attr and $attr =~ /file:(.+)/
!ll&&!rl&&r
330
MC/DC0%0/2
not ref $attr and $attr =~ /file:(.+)/
not ref $attr $attr =~ /file:(.+)/
Truth table66%2/3
not(A) and B
A= not ref $attrB= $attr =~ /file:(.+)/
ABresult
0X0
100
111
510 0 $attr = HTML::Obj2HTML::fetch($1);
511 ▶ } elsif (!ref $attr && $attr =~ /raw:(.+)/) {
Condition66%2/3
not ref $attr and $attr =~ /raw:(.+)/
!ll&&!rl&&r
330
MC/DC0%0/2
not ref $attr and $attr =~ /raw:(.+)/
not ref $attr $attr =~ /raw:(.+)/
Truth table66%2/3
not(A) and B
A= not ref $attrB= $attr =~ /raw:(.+)/
ABresult
0X0
100
111
512 0 $attr = HTML::Obj2HTML::fetchraw($1);
513 }
514  
515 # Run the current tag through extentions
516 6 my $origtag = $tag;
517 6 ▶ if (defined $extensions{$origtag}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $extensions{$origtag}) 0 6 6
518 0 ▶ if (defined $extensions{$origtag}->{scalarattr} && !ref $attr) { $attr = { $extensions{$origtag}->{scalarattr} => $attr }; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $extensions{$origtag}{"scalarattr"} and not ref $attr) 0 0 0
Condition0%0/3
defined $extensions{$origtag}{"scalarattr"} and not ref $attr
!ll&&!rl&&r
000
MC/DC0%0/2
defined $extensions{$origtag}{"scalarattr"} and not ref $attr
defined $extensions{$origtag}{"scalarattr"} not ref $attr
Truth table0%0/3
A and not(B)
A= defined $extensions{$origtag}{"scalarattr"}B= not ref $attr
ABresult
0X0
100
111
519  
520 0 ▶ if (defined $extensions{$origtag}->{before}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $extensions{$origtag}{"before"}) 0 0 0
521 0 my $o = $extensions{$origtag}->{before}($attr);
522 0 ▶ if (ref $o eq "ARRAY") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $o eq 'ARRAY') { } 0 0 0
elsif (ref $o eq '') { } 0 0 0
523 0 $ret .= HTML::Obj2HTML::gen($o);
524 } elsif (ref $o eq "") {
525 0 $ret .= $o;
526 }
527 }
528  
529 0 ▶ if (defined $extensions{$origtag}->{tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $extensions{$origtag}{"tag"}) 0 0 0
530 0 $tag = $extensions{$origtag}->{tag};
531 }
532 0 ▶ if (defined $extensions{$origtag}->{attr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $extensions{$origtag}{"attr"}) 0 0 0
533 0 ▶ if (ref $attr ne "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr ne "HASH") 0 0 0
534 0 $attr = { _ => $attr };
535 }
536 0 foreach my $k (keys %{$extensions{$origtag}->{attr}}) {
537 0 ▶ if (defined $attr->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr->{$k}) { } 0 0 0
538 0 $attr->{$k} = $extensions{$origtag}->{attr}->{$k}." ".$attr->{$k};
539 0 ▶ if ($k eq "class") {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "class") 0 0 0
540 0 $attr->{$k} = join(" ", uniq(split(/\s+/, $attr->{$k})));
541 }
542 } else {
543 0 $attr->{$k} = $extensions{$origtag}->{attr}->{$k};
544 }
545 }
546 }
547  
548 0 ▶ if (defined $extensions{$origtag}->{replace}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $extensions{$origtag}{"replace"}) 0 0 0
549 0 my $o = HTML::Obj2HTML::gen($extensions{$origtag}->{replace}($attr));
550 0 ▶ if (ref $o eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $o eq 'HASH') { } 0 0 0
elsif (ref $o eq '') { } 0 0 0
551 0 $ret .= HTML::Obj2HTML::gen($o);
552 } elsif (ref $o eq "") {
553 0 $ret .= $o;
554 }
555 0 $tag = "";
556 }
557 }
558  
559 # Non-HTML functions
560 6 ▶ if ($tag eq "_") {
Branch: 15 branches
BranchTrueFalseTotal
if ($tag eq '_') { } 0 6 6
elsif ($tag eq 'raw') { } 0 6 6
elsif ($tag eq 'if') { } 0 6 6
elsif ($tag eq 'switch') { } 0 6 6
elsif ($tag eq 'md') { } 0 6 6
elsif ($tag eq 'plain') { } 0 6 6
elsif ($tag eq 'currency') { } 0 6 6
elsif ($tag eq 'pluralize') { } 0 6 6
elsif ($tag eq 'include') { } 0 6 6
elsif ($tag eq 'javascript') { } 0 6 6
elsif ($tag eq 'includejs') { } 0 6 6
elsif ($tag eq 'includecss') { } 0 6 6
elsif ($tag eq 'doctype') { } 1 5 6
elsif (ref $attr eq 'HASH' and defined $attr->{'removeif'} and $attr->{'removeif'}) { } 0 5 5
elsif ($tag) { } 5 0 5
561 0 ▶ if (ref $attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr) { } 0 0 0
562 0 carp("HTML::Obj2HTML: _ element called, but attr wasn't a scalar.");
563 } else {
564 0 $ret .= web_escape($attr);
565 }
566  
567 } elsif ($tag eq "raw") {
568 0 ▶ if (ref $attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr) { } 0 0 0
569 0 carp("HTML::Obj2HTML: raw element called, but attr wasn't a scalar.");
570 } else {
571 0 $ret .= "$attr";
572 }
573  
574 } elsif ($tag eq "if") {
575 0 ▶ if (ref $attr eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $attr eq 'HASH') { } 0 0 0
elsif (ref $attr eq 'ARRAY') { } 0 0 0
576 0 ▶ if ($attr->{cond} && $attr->{true}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attr->{'cond'} and $attr->{'true'}) { } 0 0 0
elsif (not $attr->{'cond'} and $attr->{'false'}) { } 0 0 0
Condition0%0/3
$attr->{"cond"} and $attr->{"true"}
!ll&&!rl&&r
000
MC/DC0%0/2
$attr->{"cond"} and $attr->{"true"}
$attr->{"cond"} $attr->{"true"}
Truth table0%0/3
A and B
A= $attr->{"cond"}B= $attr->{"true"}
ABresult
0X0
100
111
577 0 $ret .= HTML::Obj2HTML::gen($attr->{true});
578 ▶ } elsif (!$attr->{cond} && $attr->{false}) {
Condition0%0/3
not $attr->{"cond"} and $attr->{"false"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $attr->{"cond"} and $attr->{"false"}
not $attr->{"cond"} $attr->{"false"}
Truth table0%0/3
not(A) and B
A= not $attr->{"cond"}B= $attr->{"false"}
ABresult
0X0
100
111
579 0 $ret .= HTML::Obj2HTML::gen($attr->{false});
580 }
581 } elsif (ref $attr eq "ARRAY") {
582 0 ▶ for (my $i = 0; $i<$#{$attr}; $i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#{$attr;}) 0 0 0
583 0 ▶ if ($attr->[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->[$i]) 0 0 0
584 0 $ret .= HTML::Obj2HTML::gen($attr->[$i+1]);
585 0 last;
586 }
587 }
588 } else {
589 0 carp("HTML::Obj2HTML: if element called, but attr wasn't a hash ref or array ref.");
590 }
591 } elsif ($tag eq "switch") {
592 0 ▶ if (ref $attr eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr eq 'HASH') { } 0 0 0
593 0 ▶ if (defined $attr->{$attr->{val}}) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $$attr{$attr->{'val'}}) { } 0 0 0
elsif (defined $attr->{'_default'}) { } 0 0 0
elsif (defined $attr->{'_'}) { } 0 0 0
594 0 $ret .= HTML::Obj2HTML::gen($attr->{$attr->{val}});
595 } elsif (defined $attr->{"_default"}) {
596 0 $ret .= HTML::Obj2HTML::gen($attr->{"_default"});
597 } elsif (defined $attr->{"_"}) {
598 0 $ret .= HTML::Obj2HTML::gen($attr->{"_"});
599 }
600 } else {
601 0 carp("HTML::Obj2HTML: switch element called, but attr wasn't a hash ref.");
602 }
603  
604 } elsif ($tag eq "md") {
605 0 ▶ if (ref $attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr) { } 0 0 0
606 0 carp("HTML::Obj2HTML: md element called, but attr wasn't a scalar.");
607 } else {
608 0 $ret .= markdown($attr);
609 }
610  
611 } elsif ($tag eq "plain") {
612 0 ▶ if (ref $attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr) { } 0 0 0
613 0 carp("HTML::Obj2HTML: plain element called, but attr wasn't a scalar.");
614 } else {
615 0 $ret .= plain($attr);
616 }
617  
618 } elsif ($tag eq "currency") {
619 0 ▶ if (ref $attr eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $attr eq 'HASH') { } 0 0 0
elsif (not ref $attr) { } 0 0 0
620 0 ▶ $ret .= web_escape(currency_format($attr->{currency} || $default_currency, $attr->{"_"}, FMT_SYMBOL));
Condition0%0/3
$attr->{'currency'} || $default_currency
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr->{'currency'} || $default_currency
$attr->{'currency'} $default_currency
Truth table0%0/3
A || B
A= $attr->{'currency'}B= $default_currency
ABresult
1X1
011
000
621 } elsif (!ref $attr) {
622 0 $ret .= web_escape(currency_format($default_currency, $attr, FMT_SYMBOL));
623 } else {
624 0 carp("HTML::Obj2HTML: currency called, but attr wasn't a hash ref or plain scalar.");
625 }
626  
627 } elsif ($tag eq "pluralize") {
628 0 ▶ if (ref $attr eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr eq 'ARRAY') { } 0 0 0
629 0 $ret .= pluralize($attr->[0], $attr->[1]);
630 } else {
631 0 carp("HTML::Obj2HTML: pluralize called, but attr wasn't a array ref");
632 }
633  
634 } elsif ($tag eq "include") {
635 0 $ret .= HTML::Obj2HTML::gen(HTML::Obj2HTML::fetch($o->{src}.".po", $attr));
636  
637 } elsif ($tag eq "javascript") {
638 0 $ret .= "<script language='javascript' type='text/javascript' defer='1'><!--\n$attr\n//--></script>";
639  
640 } elsif ($tag eq "includejs") {
641 0 ▶ if (!ref $attr) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $attr) { } 0 0 0
elsif (ref $attr == 'HASH') { } 0 0 0
642 0 $ret .= "<script language='javascript' type='text/javascript' defer='1' async='1' src='$attr'></script>";
643 } elsif (ref $attr == "HASH") {
644 0 $ret .= "<script language='javascript' type='text/javascript' ";
645 0 ▶ if ($attr->{defer}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{"defer"}) 0 0 0
646 0 $ret .= "defer='1' ";
647 }
648 0 ▶ if ($attr->{async}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{"async"}) 0 0 0
649 0 $ret .= "async='1' ";
650 }
651 0 $ret .= "src='$attr->{src}'></script>";
652 }
653  
654  
655 } elsif ($tag eq "includecss") {
656 0 $ret .= "<link rel='stylesheet' type='text/css' href='$attr' />";
657  
658 } elsif ($tag eq "doctype") {
659 1 $ret .= "<!DOCTYPE $attr>";
660  
661 ▶ } elsif (ref $attr eq "HASH" && defined $attr->{removeif} && $attr->{removeif}) {
Condition33%2/6
ref $attr eq "HASH" and defined $attr->{"removeif"} and $attr->{"removeif"}
!ll&&!rl&&r
500
ref $attr eq "HASH" and defined $attr->{"removeif"}
!ll&&!rl&&r
500
MC/DC0%0/3
ref $attr eq "HASH" and defined $attr->{"removeif"} and $attr->{"removeif"}
ref $attr eq "HASH" defined $attr->{"removeif"} $attr->{"removeif"}
Truth table25%1/4
A and B and C
A= ref $attr eq "HASH"B= defined $attr->{"removeif"}C= $attr->{"removeif"}
ABCresult
0XX0
10X0
1100
1111
662 0 $ret .= HTML::Obj2HTML::gen($attr->{_});
663  
664 # Finally through all the non-HTML elements ;)
665 } elsif ($tag) {
666  
667 # It's perfectly allowed to omit content from a tag where the end tag was forbidden
668 # If we have content, we have to assume that it should appear after the
669 # tag - not discard it, or show it within
670 # If we've got a hash ref though, we have attributes :)
671 # Note that this has to go here, because the attribute might have been a staticfile: or similar
672 # to execute some additional code
673 5 ▶ if ($tags{$tag} & END_TAG_FORBIDDEN && ref $attr ne "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if ($tags{$tag} & 2 and ref $attr ne "HASH") 0 5 5
Condition33%1/3
$tags{$tag} & 2 and ref $attr ne "HASH"
!ll&&!rl&&r
500
MC/DC0%0/2
$tags{$tag} & 2 and ref $attr ne "HASH"
$tags{$tag} & 2 ref $attr ne "HASH"
Truth table33%1/3
A and B
A= $tags{$tag} & 2B= ref $attr ne "HASH"
ABresult
0X0
100
111
674 0 unshift(@tags, $attr);
675 0 $attr = undef;
676 }
677  
678 5 ▶ if ($warn_on_unknown_tag && !defined $tags{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($warn_on_unknown_tag and not defined $tags{$tag}) 0 5 5
Condition33%1/3
$warn_on_unknown_tag and not defined $tags{$tag}
!ll&&!rl&&r
050
MC/DC0%0/2
$warn_on_unknown_tag and not defined $tags{$tag}
$warn_on_unknown_tag not defined $tags{$tag}
Truth table33%1/3
A and not(B)
A= $warn_on_unknown_tagB= not defined $tags{$tag}
ABresult
0X0
100
111
679 0 carp "Warning: Unknown tag $tag in HTML::Obj2HTML\n";
680 }
681  
682 5 $ret .= "<$tag";
683 5 ▶ if (!defined $attr) {
Branch: 5 branches
BranchTrueFalseTotal
if (not defined $attr) { } 0 5 5
elsif (ref $attr eq 'ARRAY') { } 3 2 5
elsif (ref $attr eq 'HASH') { } 0 2 2
elsif (ref $attr eq 'CODE') { } 0 2 2
elsif (ref $attr eq '') { } 2 0 2
684 0 ▶ if ($tags{$tag} & END_TAG_FORBIDDEN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tags{$tag} & 2) { } 0 0 0
elsif ($tags{$tag} & 1) { } 0 0 0
685 0 ▶ if ($mode eq "XHTML") {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'XHTML') { } 0 0 0
686 0 $ret .= " />";
687 } else {
688 0 $ret .= ">";
689 }
690 } elsif ($tags{$tag} & END_TAG_REQUIRED) {
691 0 $ret .= "></$tag>";
692 }
693  
694 } elsif (ref $attr eq "ARRAY") {
695 3 $ret .= ">";
696 3 $ret .= HTML::Obj2HTML::gen($attr);
697 3 $ret .= "</$tag>";
698  
699 } elsif (ref $attr eq "HASH") {
700 0 my %attrs = %{$attr};
701 0 my $content;
702 0 foreach my $k (keys(%attrs)) {
703 0 ▶ if (ref $k eq "ARRAY") {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $k eq 'ARRAY') { } 0 0 0
elsif (ref $attrs{$k} eq 'ARRAY') { } 0 0 0
elsif (ref $attrs{$k} eq 'HASH') { } 0 0 0
elsif ($k eq '_') { } 0 0 0
704 0 $content = $k;
705  
706 } elsif (ref $attrs{$k} eq "ARRAY") {
707 # shorthand, you can defined the content within the classname, e.g. div => { "ui segment" => [ _ => "Content" ] }
708 0 ▶ if ($k ne "_") {
Branch: 1 branch
BranchTrueFalseTotal
if ($k ne "_") 0 0 0
709 0 $ret .= format_attr("class", $k);
710 }
711 0 ▶ $content = $attrs{$k} || '';
Condition0%0/2
$attrs{$k} || ''
l!l
00
MC/DC0%0/1
$attrs{$k} || ''
$attrs{$k}
Truth table0%0/2
A
A= $attrs{$k}
Aresult
11
00
712  
713 } elsif (ref $attrs{$k} eq "HASH") {
714  
715 0 ▶ if ($k eq "style") {
Branch: 3 branches
BranchTrueFalseTotal
if ($k eq 'style') { } 0 0 0
elsif ($k eq 'if') { } 0 0 0
elsif (defined $attrs{$k}{'if'}) { } 0 0 0
716 0 my @styles = ();
717 0 ▶ while (my ($csskey, $cssval) = each(%{$attrs{$k}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$attrs{$k};}) 0 0 0
718 0 CORE::push(@styles, $csskey.":".$cssval.";");
719 }
720 0 $ret .= format_attr("style", join("",@styles));
721 } elsif ($k eq "if") {
722 0 my $val = $attrs{$k};
723 0 ▶ if ($val->{cond} && $val->{true}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val->{'cond'} and $val->{'true'}) { } 0 0 0
elsif (not $val->{'cond'} and $val->{'false'}) { } 0 0 0
Condition0%0/3
$val->{"cond"} and $val->{"true"}
!ll&&!rl&&r
000
MC/DC0%0/2
$val->{"cond"} and $val->{"true"}
$val->{"cond"} $val->{"true"}
Truth table0%0/3
A and B
A= $val->{"cond"}B= $val->{"true"}
ABresult
0X0
100
111
724 0 foreach my $newk (keys(%{$val->{true}})) {
725 0 $ret .= format_attr($newk, $val->{true}->{$newk})
726 }
727 ▶ } elsif (!$val->{cond} && $val->{false}) {
Condition0%0/3
not $val->{"cond"} and $val->{"false"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $val->{"cond"} and $val->{"false"}
not $val->{"cond"} $val->{"false"}
Truth table0%0/3
not(A) and B
A= not $val->{"cond"}B= $val->{"false"}
ABresult
0X0
100
111
728 0 foreach my $newk (keys(%{$val->{false}})) {
729 0 $ret .= format_attr($newk, $val->{false}->{$newk})
730 }
731 }
732 } elsif (defined $attrs{$k}->{if}) {
733 0 ▶ if ($attrs{$k}->{if} && defined $attrs{$k}->{true}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attrs{$k}{'if'} and defined $attrs{$k}{'true'}) { } 0 0 0
elsif (not $attrs{$k}{'if'} and defined $attrs{$k}{'false'}) { } 0 0 0
Condition0%0/3
$attrs{$k}{"if"} and defined $attrs{$k}{"true"}
!ll&&!rl&&r
000
MC/DC0%0/2
$attrs{$k}{"if"} and defined $attrs{$k}{"true"}
$attrs{$k}{"if"} defined $attrs{$k}{"true"}
Truth table0%0/3
A and B
A= $attrs{$k}{"if"}B= defined $attrs{$k}{"true"}
ABresult
0X0
100
111
734 0 $ret .= format_attr($k, $attrs{$k}->{true});
735 ▶ } elsif (!$attrs{$k}->{if} && defined $attrs{$k}->{false}) {
Condition0%0/3
not $attrs{$k}{"if"} and defined $attrs{$k}{"false"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $attrs{$k}{"if"} and defined $attrs{$k}{"false"}
not $attrs{$k}{"if"} defined $attrs{$k}{"false"}
Truth table0%0/3
not(A) and B
A= not $attrs{$k}{"if"}B= defined $attrs{$k}{"false"}
ABresult
0X0
100
111
736 0 $ret .= format_attr($k, $attrs{$k}->{false});
737 }
738 }
739  
740 } elsif ($k eq "_") {
741 0 ▶ $content = $attrs{$k} || '';
Condition0%0/2
$attrs{$k} || ''
l!l
00
MC/DC0%0/1
$attrs{$k} || ''
$attrs{$k}
Truth table0%0/2
A
A= $attrs{$k}
Aresult
11
00
742  
743 } else {
744 0 $ret .= format_attr($k, $attrs{$k});
745 }
746 }
747 0 ▶ if ($tags{$tag} & END_TAG_FORBIDDEN) {
Branch: 3 branches
BranchTrueFalseTotal
if ($tags{$tag} & 2) { } 0 0 0
elsif (defined $content) { } 0 0 0
elsif ($tags{$tag} & 1) { } 0 0 0
748 # content is also forbidden!
749 0 ▶ if ($mode eq "XHTML") {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'XHTML') { } 0 0 0
750 0 $ret .= " />";
751 } else {
752 0 $ret .= ">";
753 }
754 } elsif (defined $content) {
755 0 $ret .= ">";
756 0 $ret .= HTML::Obj2HTML::gen($content);
757 0 $ret .= "</$tag>";
758 } elsif ($tags{$tag} & END_TAG_REQUIRED) {
759 0 $ret .= "></$tag>";
760 } else {
761 0 ▶ if ($mode eq "XHTML") {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'XHTML') { } 0 0 0
762 0 $ret .= " />";
763 } else {
764 0 $ret .= ">";
765 }
766 }
767 } elsif (ref $attr eq "CODE") {
768 0 $ret .= ">";
769 0 eval {
770 0 $ret .= gen($attr->());
771 };
772 0 $ret .= "</$tag>";
773 0 ▶ if ($@) { warn "Error parsing HTML::Obj2HTML objects when calling code ref: $@\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
774 } elsif (ref $attr eq "") {
775 2 my $val = web_escape($attr);
776 2 $ret .= ">$val</$tag>";
777 }
778 }
779  
780 6 ▶ if (defined $extensions{$origtag} && defined $extensions{$origtag}->{after}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $extensions{$origtag} and defined $extensions{$origtag}{"after"}) 0 6 6
Condition33%1/3
defined $extensions{$origtag} and defined $extensions{$origtag}{"after"}
!ll&&!rl&&r
600
MC/DC0%0/2
defined $extensions{$origtag} and defined $extensions{$origtag}{"after"}
defined $extensions{$origtag} defined $extensions{$origtag}{"after"}
Truth table33%1/3
A and B
A= defined $extensions{$origtag}B= defined $extensions{$origtag}{"after"}
ABresult
0X0
100
111
781 0 $ret .= $extensions{$origtag}->{after}($attr);
782 }
783  
784 }
785 4 return $ret;
786 }
787  
788 sub format_attr {
789 0 ▶ my $k = shift;
Subroutine format_attr: not called CC=2 SCAR=17.9
Pod undocumented
790 0 my $val = shift;
791 0 $val = web_escape($val);
792 0 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 0 0 0
793 0 return " $k=\"$val\"";
794 }
795 0 return "";
796 }
797 sub substitute_dictionary {
798 2 ▶ my $val = shift;
Subroutine substitute_dictionary: called CC=1 SCAR=0.0
Pod undocumented
799 2 $val =~ s/%([A-Za-z0-9]+)%/$dictionary{$1}/g;
800 2 return $val;
801 }
802 sub web_escape {
803 2 ▶ my $val = shift;
Subroutine web_escape: called CC=1 SCAR=0.0
Pod undocumented
804 2 $val = HTML::Entities::encode($val);
805 2 $val = substitute_dictionary($val);
806 2 return $val;
807 }
808 sub plain {
809 0 ▶ my $txt = shift;
Subroutine plain: not called CC=1 SCAR=6.9
Pod undocumented
810 0 $txt = web_escape($txt);
811 0 $txt =~ s|\n|<br />|g;
812 0 return $txt;
813 }
814 sub markdown {
815 0 ▶ my $txt = shift;
Subroutine markdown: not called CC=1 SCAR=6.9
Pod undocumented
816 0 $txt = substitute_dictionary($txt);
817 0 my $m = new Text::Markdown;
818 0 my $val = $m->markdown($txt);
819 0 return $val;
820 }
821  
822 sub print {
823 0 ▶ my $o = shift;
Subroutine print: not called CC=1 SCAR=6.9
Pod undocumented
824 0 print gen($o);
825 }
826  
827 sub format {
828 0 ▶ my $plain = shift;
Subroutine format: not called CC=1 SCAR=6.9
Pod undocumented
829 0 $plain =~ s/\n/<br \/>/g;
830 0 return [ raw => $plain ];
831 }
832  
833 sub register_extension {
834 39 ▶ my $tag = shift;
Subroutine register_extension: called CC=2 SCAR=7.1
Pod undocumented
835 39 my $def = shift;
836 39 my $flags = shift;
837 39 $extensions{$tag} = $def;
838 39 ▶ if (defined $flags) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $flags) { } 0 39 39
839 0 $tags{$tag} = $flags;
840 } else {
841 39 $tags{$tag} = END_TAG_OPTIONAL;
842 }
843 }
844  
845 1 1;
846 __END__
↑ Summary Obj2HTML/Plugin/SemanticUIForms.pm »