blib/lib/Devel/Cover/Report/Html_minimal.pm untested

filter: Statementstmt 0.0% 0 / 372 Branchbran 0.0% 0 / 114 Conditioncond 0.0% 0 / 62 MC/DCmcdc 0.0% 0 / 34 Subroutinesub 0.0% 0 / 35 Podpod 0.0% 0 / 27 totaltotal 0.0% 0 / 644 CC 58 SCAR 40.6
CC
58
Cov
0%
print_file_report
240.0
print_summary_report
72.0
merge_lineops
56.0
CRAP 58.1
1 package Devel::Cover::Report::Html_minimal;
2  
3 use strict;
4 use warnings;
5 use HTML::Entities qw( encode_entities );
6 use Getopt::Long qw( GetOptions );
7 use Devel::Cover::Html_Common qw( launch ); ## no perlimports
8 use Devel::Cover::Truth_Table ();
9  
10 our $VERSION;
11  
12 BEGIN {
13 our $VERSION = '1.52'; # VERSION
14 }
15  
16 use Devel::Cover::Inc ();
17  
18 BEGIN { $VERSION //= $Devel::Cover::Inc::VERSION }
19  
20 #-------------------------------------------------------------------------------
21 # Subroutine : get_coverage_for_line
22 # Purpose : Retrieve all available data for requested metrics on a line.
23 # Notes :
24 #-------------------------------------------------------------------------------
25 sub get_coverage_for_line {
26 my ($options, $data, $line) = @_;
27 my %coverage;
28 foreach my $c (grep { $data->$_() } keys %{ $options->{show} }) {
29 my $m = $data->$c()->location($line);
30 $coverage{$c} = $m if $m;
31 }
32 return \%coverage;
33 }
34  
35 #-------------------------------------------------------------------------------
36 # Subroutine : get_summary_for_file
37 # Purpose :
38 # Notes :
39 #-------------------------------------------------------------------------------
40 sub get_summary_for_file {
41  
42 my $db = shift;
43 my $file = shift;
44 my $show = shift;
45 my %summary;
46  
47 my $data = $db->{summary}{$file};
48  
49 for my $c (@$show) {
50 if (exists $data->{$c}) {
51 $summary{$c} = {
52 percent => do {
53 my $x = sprintf "%5.2f", $data->{$c}{percentage};
54 chop $x;
55 $x
56 },
57 ratio => sprintf("%d / %d",
58 $data->{$c}{covered} || 0,
59 $data->{$c}{total} || 0),
60 error => $data->{$c}{error},
61 };
62 } else {
63 $summary{$c} = { percent => 'n/a', ratio => undef, error => undef };
64 }
65 }
66 return \%summary;
67 }
68  
69 #-------------------------------------------------------------------------------
70 # Subroutine : get_showing_headers
71 # Purpose :
72 # Notes :
73 #-------------------------------------------------------------------------------
74 sub get_showing_headers {
75  
76 my $db = shift;
77 my $options = shift;
78  
79 my @crit = $db->criteria;
80 my @short_crit = $db->criteria_short;
81 my @showing = grep $options->{show}{$_}, @crit;
82 my @headers = map { $short_crit[$_] }
83 grep { $options->{show}{ $crit[$_] } } (0 .. $#crit);
84  
85 return (\@showing, \@headers);
86 }
87  
88 #-------------------------------------------------------------------------------
89 # Subroutine : truth_table
90 # Purpose :
91 # Notes :
92 #-------------------------------------------------------------------------------
93 sub truth_table {
94 return if @_ > 16;
95 my @lops;
96 my $n = 0;
97 foreach my $c (@_) {
98 my $op = $c->[1]{type};
99 my @hit = map { defined() && $_ > 0 ? 1 : 0 } @{ $c->[0] };
100 @hit = reverse @hit if $op =~ /^or_[23]$/;
101 my $t = {
102 tt => Devel::Cover::Truth_Table->new_primitive($op, @hit),
103 # tt => Devel::Cover::Truth_Table->new_primitive($op, $c, $n++);
104 cvg => $c->[1],
105 expr => join(' ', @{ $c->[1] }{qw/left op right/}),
106 };
107 push(@lops, $t);
108 }
109 return map { [ $_->{tt}->sort, $_->{expr} ] } merge_lineops(@lops);
110 }
111  
112 #-------------------------------------------------------------------------------
113 # Subroutine : merge_lineops()
114 # Purpose : Merge multiple conditional expressions into composite
115 # truth table(s).
116 # Notes :
117 #-------------------------------------------------------------------------------
118 sub merge_lineops {
119 my @ops = @_;
120 my $rotations;
121 while ($#ops > 0) {
122 my $rm;
123 for (1 .. $#ops) {
124 if ($ops[0]{expr} eq $ops[$_]{cvg}{left}) {
125 $ops[$_]{tt}->left_merge($ops[0]{tt});
126 $ops[0] = $ops[$_];
127 $rm = $_;
128 last;
129 } elsif ($ops[0]{expr} eq $ops[$_]{cvg}{right}) {
130 $ops[$_]{tt}->right_merge($ops[0]{tt});
131 $ops[0] = $ops[$_];
132 $rm = $_;
133 last;
134 } elsif ($ops[$_]{expr} eq $ops[0]{cvg}{left}) {
135 $ops[0]{tt}->left_merge($ops[$_]{tt});
136 $rm = $_;
137 last;
138 } elsif ($ops[$_]{expr} eq $ops[0]{cvg}{right}) {
139 $ops[0]{tt}->right_merge($ops[$_]{tt});
140 $rm = $_;
141 last;
142 }
143 }
144 if ($rm) {
145 splice(@ops, $rm, 1);
146 $rotations = 0;
147 } else {
148 # First op didn't merge with anything. Rotate @ops in hopes
149 # of finding something that can be merged.
150 unshift(@ops, pop @ops);
151  
152 # Hmm... we've come full circle and *still* haven't found
153 # anything to merge. Did the source code have multiple
154 # statements on the same line?
155 last if ($rotations++ > $#ops);
156 }
157 }
158 return @ops;
159 }
160  
161 #===============================================================================
162 my %Filenames;
163 my @class = qw'c0 c1 c2 c3';
164 my $threshold = { c0 => 75, c1 => 90, c2 => 100 };
165  
166 #-------------------------------------------------------------------------------
167 # Subroutine : bclass()
168 # Purpose : Determine the CSS class for an element based on boolean coverage.
169 # Notes :
170 #-------------------------------------------------------------------------------
171 sub bclass {
172 my @c = map { $_ ? $class[-1] : $class[0] } @_;
173 return wantarray ? @c : $c[0];
174 }
175  
176 #-------------------------------------------------------------------------------
177 # Subroutine : pclass()
178 # Purpose : Determine the CSS class for an element based on percent covered
179 # Notes :
180 #-------------------------------------------------------------------------------
181 sub pclass {
182 my ($p, $e) = @_;
183 return $class[3] unless $e;
184 $p < $threshold->{c0} && return $class[0];
185 $p < $threshold->{c1} && return $class[1];
186 $p < $threshold->{c2} && return $class[2];
187 $class[3]
188 }
189  
190 #-------------------------------------------------------------------------------
191 # Subroutine : get_coverage_report
192 # Purpose :
193 # Notes :
194 #-------------------------------------------------------------------------------
195 sub get_coverage_report {
196 my $type = shift;
197 my $data = shift;
198 return _branch_report($data) if $type eq 'branch';
199 return _condition_report($data) if $type eq 'condition';
200 return _time_report($data) if $type eq 'time';
201 return _count_report($type, $data);
202 }
203 #-------------------------------------------------------------------------------
204 sub _count_report {
205 my $type = shift;
206 my $data = shift;
207 return map { {
208 class => bclass(!$_->error || $_->covered),
209 percentage => $_->covered,
210 } }
211 @{ $data->{$type} }
212 }
213 #-------------------------------------------------------------------------------
214 sub _branch_report {
215 my $coverage = shift;
216 my $sfmt
217 = qq'<table width="100%%"><tr><td class="%s">T</td><td class="%s">F</td></tr></table>';
218  
219 return map { {
220 percentage => sprintf("%.0f", $_->percentage),
221 title => sprintf("%s/%s", $_->[0][0] ? 'T' : '-', $_->[0][1] ? 'F' : '-'),
222 class => pclass($_->percentage, $_->error),
223 string => sprintf($sfmt, bclass($_->[0][0]), bclass($_->[0][1])),
224 } }
225 @{ $coverage->{branch} }
226 }
227 #-------------------------------------------------------------------------------
228 sub _condition_report {
229 my $coverage = shift;
230 # use Devel::Cover::Dumper; print STDERR Dumper $coverage;
231  
232 my @tables = truth_table(@{ $coverage->{condition} });
233 return unless @tables;
234 return map { {
235 percentage => sprintf("%.0f", $_->[0]->percentage),
236 class => pclass($_->[0]->percentage, $_->[0]->error),
237 string => $_->[0]->html(bclass(0, 1)),
238 } } @tables;
239 }
240 #-------------------------------------------------------------------------------
241 sub _time_report {
242 my $coverage = shift;
243 return map { { string => $_->covered } } @{ $coverage->{time} };
244 }
245 #-------------------------------------------------------------------------------
246  
247 #-------------------------------------------------------------------------------
248 # Subroutine : print_stylesheet()
249 # Purpose : Create the stylesheet for HTML reports.
250 # Notes :
251 #-------------------------------------------------------------------------------
252 sub print_stylesheet {
253 my ($db, $options) = @_;
254 my $file = "$options->{outputdir}/cover.css";
255  
256 open(my $css, '>', $file) or return;
257 my $p = tell(DATA);
258 print $css <DATA>;
259 seek(DATA, $p, 0);
260 close($css);
261 }
262  
263 #-------------------------------------------------------------------------------
264 # Subroutine : print_html_header
265 # Purpose :
266 # Notes :
267 #-------------------------------------------------------------------------------
268 sub print_html_header {
269 my $fh = shift;
270 my $title = shift;
271  
272 print $fh <<"END_HTML";
273 <!DOCTYPE html
274 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
275 "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
276 <html xmlns="https://www.w3.org/1999/xhtml">
277 <!--
278 This file was generated by Devel::Cover Version $VERSION
279 Devel::Cover is copyright 2001-2026, Paul Johnson (paul\@pjcj.net)
280 Devel::Cover is free. It is licensed under the same terms as Perl itself.
281 The latest version of Devel::Cover should be available from my homepage:
282 https://pjcj.net
283 -->
284 <head>
285 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
286 <meta http-equiv="Content-Language" content="en-us"></meta>
287 <link rel="stylesheet" type="text/css" href="cover.css"></link>
288 <link rel="stylesheet" type="text/css" href="cover.css"></link>
289 <title>$title</title>
290 </head>
291 END_HTML
292  
293 }
294  
295 #-------------------------------------------------------------------------------
296 # Subroutine : print_summary
297 # Purpose :
298 # Notes :
299 #-------------------------------------------------------------------------------
300 sub print_summary {
301  
302 my $fh = shift;
303 my $title = shift;
304 my $file = shift;
305 my $percent = sprintf("%.1f", shift @_ || 0);
306 my $error = shift;
307 my $db = shift;
308 my $class = pclass($percent, $error);
309  
310 my $meta = $db->{meta}{$file};
311  
312 print $fh <<"END_HTML";
313 <body>
314 <h1>$title</h1>
315 <table>
316 <tr><td class="h" align="right">File:</td><td align="left">$file</td></tr>
317 <tr><td class="h" align="right">Coverage:</td><td align="left" class="$class">$percent\%</td></tr>
318 </table>
319 <div><br/></div>
320 <table>
321 END_HTML
322  
323 }
324  
325 #-------------------------------------------------------------------------------
326 # Subroutine : print_th
327 # Purpose :
328 # Notes :
329 #-------------------------------------------------------------------------------
330 sub print_th {
331 my ($fh, $th, $span) = @_;
332 print $fh '<tr>';
333 foreach my $h (@$th) {
334 print $fh $span->{$h}
335 ? qq'<th colspan="$span->{$h}">$h</th>'
336 : "<th>$h</th>";
337 }
338 print $fh "</tr>\n";
339 }
340  
341 #-------------------------------------------------------------------------------
342 # Subroutine : get_link
343 # Purpose :
344 # Notes :
345 #-------------------------------------------------------------------------------
346 sub get_link {
347 my $file = shift;
348 my $type = shift;
349 my $line = shift;
350 return unless exists $Filenames{$file};
351 my $link = $Filenames{$file};
352 $link .= "--$type" if $type;
353 $link .= ".html";
354 $link .= "#L$line" if $line;
355 return $link;
356 }
357  
358 #-------------------------------------------------------------------------------
359 # Subroutine : print_summary_report()
360 # Purpose : Print the database summary report.
361 # Notes :
362 #-------------------------------------------------------------------------------
363 sub print_summary_report {
364 my ($db, $options) = @_;
365  
366 my $outfile = "$options->{outputdir}/$options->{option}{outputfile}";
367  
368 open(my $fh, '>', $outfile)
369 or warn("Unable to open file '$outfile' [$!]\n"), return;
370  
371 my ($show, $th) = get_showing_headers($db, $options);
372 push @$show, 'total';
373  
374 my $le = sub { ($_[0] > 0 ? "&lt;" : "=") . " $_[0]%" };
375 my $ge = sub { ($_[0] < 100 ? "&gt;" : "") . "= $_[0]%" };
376 my @c = (
377 $le->($options->{report_c0}), $le->($options->{report_c1}),
378 $le->($options->{report_c2}), $ge->($options->{report_c2}),
379 );
380 my $date = do {
381 my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
382 sprintf "%04d-%02d-%02d %02d:%02d:%02d", $year + 1900, $mon + 1, $mday,
383 $hour, $min, $sec
384 };
385 my $perl_v = $^V;
386 my $os = $^O;
387  
388 print_html_header($fh, $options->{option}{summarytitle});
389 # TODO - >= 100% doesn't look nice. See also Html_basic.
390 print $fh <<"END_HTML";
391 <body>
392 <h1>$options->{option}{summarytitle}</h1>
393 <table>
394 <tr><td class="h" align="right">Database:</td><td align="left" colspan="4">$db->{db}</td></tr>
395 <tr><td class="h" align="right">Report Date:</td><td align="left" colspan="4">$date</td></tr>
396 <tr><td class="h" align="right">Perl Version:</td><td align="left" colspan="4">$perl_v</td></tr>
397 <tr><td class="h" align="right">OS:</td><td align="left" colspan="4">$os</td></tr>
398 <tr>
399 <td class="h" align="right">Thresholds:</td>
400 <td class="c0">$c[0]</td><td class="c1">$c[1]</td><td class="c2">$c[2]</td><td class="c3">$c[3]</td>
401 </tr>
402 </table>
403 <div><br/></div>
404 <table>
405 END_HTML
406 print_th($fh, [ 'file', @$th, 'total' ]);
407  
408 my @files = (grep($db->{summary}{$_}, @{ $options->{file} }), 'Total');
409  
410 for my $file (@files) {
411 my $summary = get_summary_for_file($db, $file, $show);
412  
413 my $url = get_link($file);
414 if ($url) {
415 print $fh qq'<tr><td align="left"><a href="$url">$file</a></td>';
416 } else {
417 print $fh qq'<tr><td align="left">$file</td>';
418 }
419  
420 for my $c (@$show) {
421 my $pc = $summary->{$c}{percent};
422 my ($class, $popup, $link);
423  
424 if ($pc eq 'n/a' || $c eq 'time') {
425 $class = $popup = '';
426 } else {
427 $class = sprintf(qq' class="%s"', pclass($pc, $summary->{$c}{error}));
428 $popup = sprintf(qq' title="%s"', $c . ': ' . $summary->{$c}{ratio});
429 if ($c =~ /branch|condition|subroutine/) {
430 $link = get_link($file, $c);
431 }
432 }
433  
434 if ($link) {
435 printf $fh qq'<td%s%s><a href="%s">%s</a></td>', $class, $popup, $link,
436 $pc;
437 } else {
438 printf $fh qq'<td%s%s>%s</td>', $class, $popup, $pc;
439 }
440 }
441 print $fh "</tr>\n";
442 }
443 print $fh "</table>\n</body>\n</html>\n";
444 close($fh) or warn "Unable to close '$outfile' [$!]";
445  
446 print "HTML output written to $outfile\n" unless $options->{silent};
447 }
448  
449 #-------------------------------------------------------------------------------
450 # Subroutine : escape_HTML
451 # Purpose : make source code web-safe
452 # Notes :
453 #-------------------------------------------------------------------------------
454 sub escape_HTML {
455 my $text = shift;
456 chomp $text;
457  
458 $text = encode_entities($text);
459  
460 # Do not allow FF in text
461 $text =~ tr/\x0c//d;
462  
463 # IE doesn't honor "white-space: pre" CSS
464 my @text = split m/\n/ => $text;
465 for (@text) {
466 # Expand all tabs to spaces
467 1 while s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
468 # make multiple spaces be multiple spaces
469 s/( +)/'&nbsp;' x length $1/ge;
470 }
471  
472 return join "\n" => @text;
473 }
474  
475 #-------------------------------------------------------------------------------
476 # Subroutine : print_file_report()
477 # Purpose : Print coverage overview report for a file.
478 # Notes :
479 #-------------------------------------------------------------------------------
480 sub print_file_report {
481 my ($db, $fin, $opt) = @_;
482  
483 my $fout = "$opt->{outputdir}/$Filenames{$fin}.html";
484 open(my $in, '<', $fin) or warn("Can't read file '$fin' [$!]\n"), return;
485 open(my $out, '>', $fout) or warn("Can't open file '$fout' [$!]\n"), return;
486  
487 my ($show, $th) = get_showing_headers($db, $opt);
488 my $file_data = $db->cover->file($fin);
489  
490 print_html_header($out, "File Coverage: $fin");
491 print_summary(
492 $out, 'File Coverage',
493 $fin,
494 $db->{summary}{$fin}{total}{percentage},
495 $db->{summary}{$fin}{total}{error}, $db
496 );
497 print_th($out, [ 'line', @$th, 'code' ]);
498  
499 my $autoloader = 0;
500 while (my $sloc = <$in>) {
501 $autoloader ||= $sloc =~ /use\s+AutoLoader/;
502  
503 # Process stuff after __END__ or __DATA__ tokens
504 if (!$autoloader && $sloc =~ /^__(END|DATA)__/) {
505 if ($opt->{option}{data}) {
506 # print all data in one cell
507 my ($i, $n) = ($., scalar @$th);
508 while (my $line = <$in>) { $sloc .= $line }
509 $sloc = escape_HTML($sloc);
510 print $out
511 qq'<tr><td class="h">$i - $.</td><td colspan="$n"></td><td class="s"><pre>$sloc</pre></td></tr>\n';
512 # &nbsp; is IE empty cell hack
513 #print $out qq'<tr><td class="h">$i - $.</td><td colspan="$n">&nbsp;</td><td class="s"><pre>$sloc</pre></td></tr>\n';
514 }
515 last;
516 }
517  
518 # Process embedded POD
519 if ($sloc =~ /^=(pod|head|over|item|begin|for)/) {
520 if ($opt->{option}{pod}) {
521 # print all POD in one cell
522 my ($i, $n) = ($., scalar @$th);
523 while (my $line = <$in>) {
524 $sloc .= $line;
525 last if $line =~ /^=cut/;
526 }
527 $sloc = escape_HTML($sloc);
528 print $out
529 qq'<tr><td class="h">$i - $.</td><td colspan="$n"></td><td class="s"><pre>$sloc</pre></td></tr>\n';
530 # &nbsp; is IE empty cell hack
531 #print $out qq'<tr><td class="h">$i - $.</td><td colspan="$n">&nbsp;</td><td class="s"><pre>$sloc</pre></td></tr>\n';
532 } else {
533 1 while (<$in> !~ /^=cut/);
534 }
535 next;
536 }
537  
538 if ($sloc =~ /^\s*$/) {
539 if ($opt->{option}{pod}) {
540 my $n = @$th + 1;
541 print $out qq'<tr><td class="h">$.</td><td colspan="$n"></td></tr>';
542 # &nbsp; is IE empty cell hack
543 #print $out qq'<tr><td class="h">$.</td><td colspan="$n">&nbsp;</td></tr>';
544 }
545 next;
546 }
547  
548 $sloc = escape_HTML($sloc);
549  
550 print $out qq'<tr><td class="h">$.</td>';
551  
552 my $metric = get_coverage_for_line($opt, $file_data, $.);
553  
554 foreach my $c (@$show) {
555 my @m = get_coverage_report($c, $metric);
556 print $out '<td>';
557 foreach my $m (@m) {
558  
559 if ($opt->{option}{unified} && ($c eq 'branch' || $c eq 'condition')) {
560 print $out '<div>', $m->{string}, '</div>';
561 } else {
562 my $link;
563 if ($c =~ /branch|condition|subroutine/) {
564 $link = get_link($fin, $c, $.);
565 }
566  
567 no warnings "uninitialized"; # TODO - hack, get rid of this
568 my $text = '<div';
569 $text .= $m->{class} ? qq' class="$m->{class}"' : '';
570 $text .= $m->{title} ? qq' title="$m->{title}"' : '';
571 $text .= '>';
572 $text .= $link ? qq'<a href="$link">' : '';
573 $text .= $m->{class} ? $m->{percentage} : $m->{string};
574 $text .= $link ? '</a></div>' : '</div>';
575 print $out $text;
576 }
577 }
578 print $out '</td>';
579 #print $out '&nbsp;' unless @m; # IE empty cell hack
580 }
581 print $out qq'<td class="s">$sloc</td></tr>\n';
582 }
583 print $out "</table>\n</body>\n</html>\n";
584  
585 close($in) or warn "Can't close file '$fin' [$!]";
586 close($out) or warn "Can't close file '$fout' [$!]";
587 }
588  
589 #-------------------------------------------------------------------------------
590 # Subroutine : print_branch_report()
591 # Purpose : Print branch coverage report for a file.
592 # Notes :
593 #-------------------------------------------------------------------------------
594 sub print_branch_report {
595 my ($db, $file, $opt) = @_;
596 my $data = $db->cover->file($file)->branch;
597 return unless $data;
598  
599 my $fout = "$opt->{outputdir}/$Filenames{$file}--branch.html";
600 open(my $out, '>', $fout) or warn("Can't open file '$fout' [$!]\n"), return;
601  
602 print_html_header($out, "Branch Coverage: $file");
603 print_summary(
604 $out, 'Branch Coverage',
605 $file,
606 $db->{summary}{$file}{branch}{percentage},
607 $db->{summary}{$file}{branch}{error}, $db
608 );
609 print_th($out, [ 'line', '%', 'coverage', 'branch' ], { coverage => 2 });
610  
611 my $fmt
612 = qq'<tr><td class="h">%s</td>'
613 . qq'<td class="%s">%.0f</td>'
614 . qq'<td class="%s">T</td>'
615 . qq'<td class="%s">F</td>'
616 . qq'<td class="s">%s</td></tr>\n';
617  
618 foreach my $line (sort { $a <=> $b } $data->items) {
619 my $n = 0;
620 foreach my $x (@{ $data->location($line) }) {
621 my @tf = $x->values;
622 printf $out (
623 $fmt,
624 $n++ > 0 ? '' : qq'<a id="L$line">$line</a>',
625 pclass($x->percentage, $x->error),
626 $x->percentage,
627 bclass($tf[0]),
628 bclass($tf[1]),
629 escape_HTML($x->text),
630 );
631 }
632 }
633 print $out "</table>\n</body>\n</html>\n";
634 close($out) or warn "Can't close file '$fout' [$!]";
635 }
636  
637 #-------------------------------------------------------------------------------
638 # Subroutine : print_condition_report()
639 # Purpose : Print condition coverage report for a file.
640 # Notes :
641 #-------------------------------------------------------------------------------
642 sub print_condition_report {
643 my ($db, $file, $opt) = @_;
644 my $data = $db->cover->file($file)->condition;
645 return unless $data;
646  
647 my $fout = "$opt->{outputdir}/$Filenames{$file}--condition.html";
648 open(my $out, '>', $fout) or warn("Can't open file '$fout' [$!]\n"), return;
649  
650 print_html_header($out, "Condition Coverage: $file");
651 print_summary(
652 $out, 'Condition Coverage',
653 $file,
654 $db->{summary}{$file}{condition}{percentage},
655 $db->{summary}{$file}{condition}{error}, $db
656 );
657 print_th($out, [ 'line', '%', 'coverage', 'condition' ]);
658  
659 my $fmt
660 = qq'<tr><td class="h">%s</td>'
661 . qq'<td class="%s">%.0f</td>'
662 . qq'<td>%s</td>'
663 . qq'<td class="s">%s</td></tr>\n';
664  
665 foreach my $line (sort { $a <=> $b } $data->items) {
666 my @tt = $data->truth_table($line);
667 my $n = 0;
668 foreach my $x (@tt) {
669 printf $out (
670 $fmt,
671 $n++ > 0 ? '' : qq'<a id="L$line">$line</a>',
672 pclass($x->[0]->percentage, $x->[0]->error),
673 $x->[0]->percentage,
674 '<div>' . $x->[0]->html(bclass(0, 1)) . '</div>',
675 escape_HTML($x->[1]),
676 );
677 }
678 }
679 print $out "</table>\n</body>\n</html>\n";
680 close($out) or warn "Can't close file '$fout' [$!]";
681 }
682  
683 #-------------------------------------------------------------------------------
684 # Subroutine : print_sub_report
685 # Purpose :
686 # Notes :
687 #-------------------------------------------------------------------------------
688 sub print_sub_report {
689 my ($db, $file, $opt) = @_;
690 my $data = $db->cover->file($file)->subroutine;
691 return unless $data;
692  
693 my $fout = "$opt->{outputdir}/$Filenames{$file}--subroutine.html";
694 open(my $out, '>', $fout) or warn("Can't open file '$fout' [$!]\n"), return;
695  
696 print_html_header($out, "Subroutine Coverage: $file");
697 print_summary(
698 $out, 'Subroutine Coverage',
699 $file,
700 $db->{summary}{$file}{subroutine}{percentage},
701 $db->{summary}{$file}{subroutine}{error}, $db
702 );
703 print_th($out, [ 'line', 'subroutine' ]);
704  
705 my $fmt = qq'<tr><td class="h">%s</td>'
706 . qq'<td class="%s"><div class="s">%s</div></td></tr>\n';
707  
708 foreach my $line (sort { $a <=> $b } $data->items) {
709 my $l = $data->location($line);
710 my $n = 0;
711 foreach my $x (@$l) {
712 printf $out (
713 $fmt,
714 $n++ > 0 ? '' : qq'<a id="L$line">$line</a>',
715 pclass($x->percentage, $x->error),
716 escape_HTML($x->name),
717 );
718 }
719 }
720 print $out "</table>\n</body>\n</html>\n";
721 close($out) or warn "Can't close file '$fout' [$!]";
722 }
723  
724 sub get_options {
725 my ($self, $opt) = @_;
726 $opt->{option}{pod} = 1;
727 $opt->{option}{outputfile} = "coverage.html";
728 $opt->{option}{summarytitle} = "Coverage Summary";
729 $threshold->{$_} = $opt->{"report_$_"}
730 for grep { defined $opt->{"report_$_"} } qw( c0 c1 c2 );
731 die "Invalid command line options" unless GetOptions(
732 $opt->{option}, qw(
733 data!
734 outputfile=s
735 pod!
736 summarytitle=s
737 unified!
738 report_c0=s
739 report_c1=s
740 report_c2=s
741 )
742 );
743 }
744  
745 #-------------------------------------------------------------------------------
746 # Subroutine : report()
747 # Purpose : Entry point for printing HTML reports.
748 # Notes :
749 #-------------------------------------------------------------------------------
750 sub report {
751 my (undef, $db, $opt) = @_;
752  
753 my @files = @{ $opt->{file} };
754 %Filenames = map { $_ => do { (my $f = $_) =~ s/\W/-/g; $f } } @files;
755  
756 print_stylesheet($db, $opt);
757 for my $file (@files) {
758 print_file_report($db, $file, $opt);
759 unless ($opt->{option}{unified}) {
760 print_branch_report($db, $file, $opt) if $opt->{show}{branch};
761 print_condition_report($db, $file, $opt) if $opt->{show}{condition};
762 print_sub_report($db, $file, $opt) if $opt->{show}{subroutine};
763 }
764 }
765 print_summary_report($db, $opt);
766  
767 print "done.\n" unless $opt->{silent};
768 }
769  
770 =pod
771  
772 =head1 NAME
773  
774 Devel::Cover::Report::Html_minimal - HTML backend for Devel::Cover
775  
776 =head1 VERSION
777  
778 version 1.52
779  
780 =head1 SYNOPSIS
781  
782 cover -report html_minimal
783  
784 =head1 DESCRIPTION
785  
786 This module provides a HTML reporting mechanism for coverage data. It is
787 designed to be called from the C<cover> program.
788  
789 Based on an original by Paul Johnson, the output was greatly improved by Michael
790 Carman (mjcarman@mchsi.com).
791  
792 =head1 OPTIONS
793  
794 Options are specified by adding the appropriate flags to the C<cover> program.
795 This report format supports the following:
796  
797 =over 4
798  
799 =item outputfile
800  
801 Specifies the filename of the main output file. The default is
802 F<coverage.html>. Specify F<index.html> if you just want to publish the whole
803 directory.
804  
805 =item pod
806  
807 Includes POD (and blank lines) in the file report. This is on by default. It
808 may be turned off with -nopod.
809  
810 =item data
811  
812 Includes text after the C<__DATA__> or C<__END__> tokens in the file report. By
813 default, this text is trimmed.
814  
815 Note: If your POD is after an C<__END__>, you have to specify 'data' to include
816 it, not 'pod'. The 'pod' option only applies to POD before the C<__END__>.
817  
818 =item unified
819  
820 Generates a "unified" report for each file. The detailed data that normally
821 appears in the auxiliary reports (branch, condition, etc.) are placed in the
822 file report, and the auxiliary reports are not generated.
823  
824 =item summarytitle
825  
826 Specify the title of the summary. The default is "Coverage Summary".
827  
828 =back
829  
830 =head1 SEE ALSO
831  
832 Devel::Cover
833  
834 =head1 LICENCE
835  
836 Copyright 2001-2026, Paul Johnson (paul@pjcj.net)
837  
838 This software is free. It is licensed under the same terms as Perl itself.
839  
840 The latest version of this software should be available from my homepage:
841 https://pjcj.net
842  
843 =cut
844  
845 1;
846  
847 __DATA__