| 1 | # Copyright 2001-2026, Paul Johnson (paul@pjcj.net) | ||
| 2 | |||
| 3 | # This software is free. It is licensed under the same terms as Perl itself. | ||
| 4 | |||
| 5 | # The latest version of this software should be available from my homepage: | ||
| 6 | # https://pjcj.net | ||
| 7 | |||
| 8 | package Devel::Cover::Report::Html_basic; | ||
| 9 | |||
| 10 | use strict; | ||
| 11 | use warnings; | ||
| 12 | |||
| 13 | our $VERSION; | ||
| 14 | |||
| 15 | BEGIN { | ||
| 16 | our $VERSION = '1.52'; # VERSION | ||
| 17 | } | ||
| 18 | |||
| 19 | use Devel::Cover::Html_Common qw( launch ); ## no perlimports | ||
| 20 | use Devel::Cover::Inc (); | ||
| 21 | use Devel::Cover::Web qw( write_file ); | ||
| 22 | |||
| 23 | BEGIN { $VERSION //= $Devel::Cover::Inc::VERSION } | ||
| 24 | |||
| 25 | use HTML::Entities qw( encode_entities ); | ||
| 26 | use Getopt::Long qw( GetOptions ); | ||
| 27 | use Template 2.00 (); | ||
| 28 | |||
| 29 | my ($Have_highlighter, $Have_PPI, $Have_perltidy); | ||
| 30 | |||
| 31 | BEGIN { | ||
| 32 | eval "use PPI; use PPI::HTML;"; | ||
| 33 | $Have_PPI = !$@; | ||
| 34 | eval "use Perl::Tidy"; | ||
| 35 | $Have_perltidy = !$@; | ||
| 36 | $Have_highlighter = $Have_PPI || $Have_perltidy; | ||
| 37 | } | ||
| 38 | |||
| 39 | my $Template; | ||
| 40 | my %R; | ||
| 41 | |||
| 42 | sub oclass { | ||
| 43 | my ($o, $criterion) = @_; | ||
| 44 | $o ? class($o->percentage, $o->error, $criterion) : "" | ||
| 45 | } | ||
| 46 | |||
| 47 | my $threshold = { c0 => 75, c1 => 90, c2 => 100 }; | ||
| 48 | |||
| 49 | sub class { | ||
| 50 | my ($pc, $err, $criterion) = @_; | ||
| 51 | return "" if $criterion eq "time"; | ||
| 52 | no warnings "uninitialized"; | ||
| 53 | !$err ? "c3" | ||
| 54 | : $pc < $threshold->{c0} ? "c0" | ||
| 55 | : $pc < $threshold->{c1} ? "c1" | ||
| 56 | : $pc < $threshold->{c2} ? "c2" | ||
| 57 | : "c3" | ||
| 58 | } | ||
| 59 | |||
| 60 | sub get_summary { | ||
| 61 | my ($file, $criterion) = @_; | ||
| 62 | |||
| 63 | my %vals; | ||
| 64 | @vals{ "pc", "class" } = ("n/a", ""); | ||
| 65 | |||
| 66 | my $part = $R{db}->summary($file); | ||
| 67 | return \%vals unless exists $part->{$criterion}; | ||
| 68 | my $c = $part->{$criterion}; | ||
| 69 | $vals{class} = class($c->{percentage}, $c->{error}, $criterion); | ||
| 70 | |||
| 71 | return \%vals unless defined $c->{percentage}; | ||
| 72 | $vals{pc} = do { my $x = sprintf "%5.2f", $c->{percentage}; chop $x; $x }; | ||
| 73 | $vals{covered} = $c->{covered} || 0; | ||
| 74 | $vals{total} = $c->{total}; | ||
| 75 | $vals{details} = "$vals{covered} / $vals{total}"; | ||
| 76 | |||
| 77 | my $cr = $criterion eq "pod" ? "subroutine" : $criterion; | ||
| 78 | return \%vals | ||
| 79 | if $cr !~ /^branch|condition|subroutine$/ || !exists $R{filenames}{$file}; | ||
| 80 | $vals{link} = "$R{filenames}{$file}--$cr.html"; | ||
| 81 | |||
| 82 | \%vals | ||
| 83 | } | ||
| 84 | |||
| 85 | sub print_summary { | ||
| 86 | my $vars = { | ||
| 87 | R => \%R, | ||
| 88 | files => [ "Total", grep $R{db}->summary($_), @{ $R{options}{file} } ], | ||
| 89 | }; | ||
| 90 | |||
| 91 | my $html = "$R{options}{outputdir}/$R{options}{option}{outputfile}"; | ||
| 92 | $Template->process("summary", $vars, $html) or die $Template->error(); | ||
| 93 | |||
| 94 | $html | ||
| 95 | } | ||
| 96 | |||
| 97 | sub _highlight_ppi { | ||
| 98 | |||
| 99 | my @all_lines = @_; | ||
| 100 | my $code = join "", @all_lines; | ||
| 101 | my $document = PPI::Document->new(\$code); | ||
| 102 | my $highlight = PPI::HTML->new(line_numbers => 1); | ||
| 103 | my $pretty = $highlight->html($document); | ||
| 104 | |||
| 105 | my $split = '<span class="line_number">'; | ||
| 106 | |||
| 107 | no warnings "uninitialized"; | ||
| 108 | |||
| 109 | # turn significant whitespace into | ||
| 110 | @all_lines = map { | ||
| 111 | $_ =~ s{</span>( +)}{"</span>" . (" " x length($1))}e; | ||
| 112 | "$split$_"; | ||
| 113 | } split /$split/, $pretty; | ||
| 114 | |||
| 115 | # remove the line number | ||
| 116 | @all_lines = map { | ||
| 117 | s{<span class="line_number">.*?</span>}{}; | ||
| 118 | $_; | ||
| 119 | } @all_lines; | ||
| 120 | @all_lines = map { | ||
| 121 | s{<span class="line_number">}{}; | ||
| 122 | $_; | ||
| 123 | } @all_lines; | ||
| 124 | |||
| 125 | # remove the BR | ||
| 126 | @all_lines = map { | ||
| 127 | s{<br>$}{}; | ||
| 128 | $_; | ||
| 129 | } @all_lines; | ||
| 130 | @all_lines = map { | ||
| 131 | s{<br>\n</span>}{</span>}; | ||
| 132 | $_; | ||
| 133 | } @all_lines; | ||
| 134 | |||
| 135 | shift @all_lines if $all_lines[0] eq ""; | ||
| 136 | |||
| 137 | @all_lines | ||
| 138 | } | ||
| 139 | |||
| 140 | sub _highlight_perltidy { | ||
| 141 | my @all_lines = @_; | ||
| 142 | my @coloured; | ||
| 143 | |||
| 144 | my ($stderr, $errorfile); | ||
| 145 | Perl::Tidy::perltidy( | ||
| 146 | source => \@all_lines, | ||
| 147 | destination => \@coloured, | ||
| 148 | argv => "-html -pre -nopod2html", | ||
| 149 | stderr => \$stderr, | ||
| 150 | errorfile => \$errorfile | ||
| 151 | ); | ||
| 152 | |||
| 153 | # remove the PRE | ||
| 154 | shift @coloured; | ||
| 155 | pop @coloured; | ||
| 156 | @coloured = grep { !/<a name=/ } @coloured; | ||
| 157 | |||
| 158 | @coloured | ||
| 159 | } | ||
| 160 | |||
| 161 | sub _highlight { | ||
| 162 | if ($Have_PPI && !$R{options}{option}{noppihtml}) { | ||
| 163 | return _highlight_ppi(@_); | ||
| 164 | } else { | ||
| 165 | if ($Have_perltidy && !$R{options}{option}{noperltidy}) { | ||
| 166 | return _highlight_perltidy(@_); | ||
| 167 | } | ||
| 168 | } | ||
| 169 | |||
| 170 | return; | ||
| 171 | } | ||
| 172 | |||
| 173 | sub print_file { | ||
| 174 | my @lines; | ||
| 175 | my $f = $R{db}->cover->file($R{file}); | ||
| 176 | |||
| 177 | open F, $R{file} or warn("Unable to open $R{file}: $!\n"), return; | ||
| 178 | my @all_lines = <F>; | ||
| 179 | |||
| 180 | if (!($R{options}{option}{noppihtml} && $R{options}{option}{noperltidy})) { | ||
| 181 | @all_lines = _highlight(@all_lines) if $Have_highlighter; | ||
| 182 | } | ||
| 183 | |||
| 184 | my $linen = 1; | ||
| 185 | LINE: while (defined(my $l = shift @all_lines)) { | ||
| 186 | my $n = $linen++; | ||
| 187 | chomp $l; | ||
| 188 | |||
| 189 | my %criteria; | ||
| 190 | for my $c (@{ $R{showing} }) { | ||
| 191 | my $criterion = $f->$c(); | ||
| 192 | if ($criterion) { | ||
| 193 | my $l = $criterion->location($n); | ||
| 194 | $criteria{$c} = $l ? [@$l] : undef; | ||
| 195 | } | ||
| 196 | } | ||
| 197 | |||
| 198 | my $count = 0; | ||
| 199 | my $more = 1; | ||
| 200 | while ($more) { | ||
| 201 | my %line; | ||
| 202 | |||
| 203 | $count++; | ||
| 204 | $line{number} = length $n ? $n : " "; | ||
| 205 | $line{text} = length $l ? $l : " "; | ||
| 206 | |||
| 207 | my $error = 0; | ||
| 208 | $more = 0; | ||
| 209 | for my $ann (@{ $R{options}{annotations} }) { | ||
| 210 | for my $a (0 .. $ann->count - 1) { | ||
| 211 | my $text = $ann->text($R{file}, $n, $a); | ||
| 212 | $text = " " unless $text && length $text; | ||
| 213 | push @{ $line{criteria} }, | ||
| 214 | { text => $text, class => $ann->class($R{file}, $n, $a) }; | ||
| 215 | $error ||= $ann->error($R{file}, $n, $a); | ||
| 216 | } | ||
| 217 | } | ||
| 218 | for my $c (@{ $R{showing} }) { | ||
| 219 | my $o = shift @{ $criteria{$c} }; | ||
| 220 | $more ||= @{ $criteria{$c} }; | ||
| 221 | |||
| 222 | my $link = $c !~ /statement|time/; | ||
| 223 | my $pc = $link && $c !~ /subroutine|pod/; | ||
| 224 | my $text = $o ? $pc ? $o->percentage : $o->covered : " "; | ||
| 225 | my %criterion = (text => $text, class => oclass($o, $c)); | ||
| 226 | my $cr = $c eq "pod" ? "subroutine" : $c; | ||
| 227 | |||
| 228 | $criterion{link} = "$R{filenames}{$R{file}}--$cr.html#$n-$count" | ||
| 229 | if $o && $link; | ||
| 230 | push @{ $line{criteria} }, \%criterion; | ||
| 231 | $error ||= $o->error if $o; | ||
| 232 | } | ||
| 233 | |||
| 234 | push @lines, \%line; | ||
| 235 | |||
| 236 | last LINE if $l =~ /^__(END|DATA)__/; | ||
| 237 | $n = $l = ""; | ||
| 238 | } | ||
| 239 | } | ||
| 240 | close F or die "Unable to close $R{file}: $!"; | ||
| 241 | |||
| 242 | # Add forward references to uncovered lines ... | ||
| 243 | # first line has a ref to the first uncovered line unless | ||
| 244 | # the first line already is uncovered in which case it links | ||
| 245 | # to the *next* uncovered line | ||
| 246 | { | ||
| 247 | my @unc = grep { | ||
| 248 | $_->{criteria}[0]{class} eq "c0" && $_->{criteria}[0]{text} eq "0" | ||
| 249 | } @lines; | ||
| 250 | while (@unc) { | ||
| 251 | my $u = pop @unc; | ||
| 252 | my $link = "#" . $u->{number}; | ||
| 253 | (@unc ? $unc[-1] : $lines[0])->{criteria}[0]{link} ||= $link; | ||
| 254 | } | ||
| 255 | } | ||
| 256 | |||
| 257 | my $vars = { R => \%R, lines => \@lines }; | ||
| 258 | |||
| 259 | $Template->process("file", $vars, $R{file_html}) or die $Template->error(); | ||
| 260 | } | ||
| 261 | |||
| 262 | sub print_branches { | ||
| 263 | my $branches = $R{db}->cover->file($R{file})->branch; | ||
| 264 | return unless $branches; | ||
| 265 | |||
| 266 | my @branches; | ||
| 267 | for my $location (sort { $a <=> $b } $branches->items) { | ||
| 268 | my $count = 0; | ||
| 269 | for my $b (@{ $branches->location($location) }) { | ||
| 270 | $count++; | ||
| 271 | my $text = $b->text; | ||
| 272 | ($text) = _highlight($text) if $Have_highlighter; | ||
| 273 | |||
| 274 | push @branches, { | ||
| 275 | number => $count == 1 ? $location : "", | ||
| 276 | parts => [ | ||
| 277 | map { | ||
| 278 | text => $b->value($_), | ||
| 279 | class => class($b->value($_), $b->error($_), "branch") | ||
| 280 | }, | ||
| 281 | 0 .. $b->total - 1, | ||
| 282 | ], | ||
| 283 | text => $text, | ||
| 284 | }; | ||
| 285 | } | ||
| 286 | } | ||
| 287 | |||
| 288 | my $vars = { R => \%R, branches => \@branches }; | ||
| 289 | |||
| 290 | my $html = "$R{options}{outputdir}/$R{filenames}{$R{file}}--branch.html"; | ||
| 291 | $Template->process("branches", $vars, $html) or die $Template->error(); | ||
| 292 | } | ||
| 293 | |||
| 294 | sub print_conditions { | ||
| 295 | my $conditions = $R{db}->cover->file($R{file})->condition; | ||
| 296 | return unless $conditions; | ||
| 297 | |||
| 298 | my %r; | ||
| 299 | for my $location (sort { $a <=> $b } $conditions->items) { | ||
| 300 | my %count; | ||
| 301 | for my $c (@{ $conditions->location($location) }) { | ||
| 302 | $count{ $c->type }++; | ||
| 303 | # print "-- [$count{$c->type}][@{[$c->text]}]}]\n"; | ||
| 304 | my $text = $c->text; | ||
| 305 | ($text) = _highlight($text) if $Have_highlighter; | ||
| 306 | |||
| 307 | push @{ $r{ $c->type } }, { | ||
| 308 | number => $count{ $c->type } == 1 ? $location : "", | ||
| 309 | condition => $c, | ||
| 310 | parts => [ | ||
| 311 | map { | ||
| 312 | text => $c->value($_), | ||
| 313 | class => class($c->value($_), $c->error($_), "condition") | ||
| 314 | }, | ||
| 315 | 0 .. $c->total - 1, | ||
| 316 | ], | ||
| 317 | text => $text, | ||
| 318 | }; | ||
| 319 | } | ||
| 320 | } | ||
| 321 | |||
| 322 | my @types = map { | ||
| 323 | name => do { my $n = $_; $n =~ s/_/ /g; $n }, | ||
| 324 | headers => | ||
| 325 | [ map { encode_entities($_) } @{ $r{$_}[0]{condition}->headers || [] } ], | ||
| 326 | conditions => $r{$_}, | ||
| 327 | }, sort keys %r; | ||
| 328 | |||
| 329 | my $vars = { R => \%R, types => \@types }; | ||
| 330 | |||
| 331 | # use Devel::Cover::Dumper; print Dumper \@types; | ||
| 332 | |||
| 333 | my $html = "$R{options}{outputdir}/$R{filenames}{$R{file}}--condition.html"; | ||
| 334 | $Template->process("conditions", $vars, $html) or die $Template->error(); | ||
| 335 | } | ||
| 336 | |||
| 337 | sub print_subroutines { | ||
| 338 | my $subroutines = $R{db}->cover->file($R{file})->subroutine; | ||
| 339 | return unless $subroutines; | ||
| 340 | my $s = $R{options}{show}{subroutine}; | ||
| 341 | |||
| 342 | my $pods; | ||
| 343 | $pods = $R{db}->cover->file($R{file})->pod if $R{options}{show}{pod}; | ||
| 344 | |||
| 345 | my $subs; | ||
| 346 | for my $line (sort { $a <=> $b } $subroutines->items) { | ||
| 347 | my @p; | ||
| 348 | if ($pods) { | ||
| 349 | my $l = $pods->location($line); | ||
| 350 | @p = @$l if $l; | ||
| 351 | } | ||
| 352 | for my $o (@{ $subroutines->location($line) }) { | ||
| 353 | my $p = shift @p; | ||
| 354 | push @$subs, { | ||
| 355 | line => $line, | ||
| 356 | name => $o->name, | ||
| 357 | count => $s ? $o->covered : "", | ||
| 358 | class => $s ? oclass($o, "subroutine") : "", | ||
| 359 | pod => $p ? $p->covered ? "Yes" : "No" : "n/a", | ||
| 360 | pclass => $p ? oclass($p, "pod") : "", | ||
| 361 | }; | ||
| 362 | } | ||
| 363 | } | ||
| 364 | |||
| 365 | my $vars = { R => \%R, subs => $subs }; | ||
| 366 | |||
| 367 | my $html = "$R{options}{outputdir}/$R{filenames}{$R{file}}--subroutine.html"; | ||
| 368 | $Template->process("subroutines", $vars, $html) or die $Template->error(); | ||
| 369 | } | ||
| 370 | |||
| 371 | sub get_options { | ||
| 372 | my ($self, $opt) = @_; | ||
| 373 | $opt->{option}{outputfile} = "coverage.html"; | ||
| 374 | $opt->{option}{restrict} = 1; | ||
| 375 | $threshold->{$_} = $opt->{"report_$_"} | ||
| 376 | for grep { defined $opt->{"report_$_"} } qw( c0 c1 c2 ); | ||
| 377 | die "Invalid command line options" unless GetOptions( | ||
| 378 | $opt->{option}, qw( | ||
| 379 | noppihtml | ||
| 380 | noperltidy | ||
| 381 | outputfile=s | ||
| 382 | restrict! | ||
| 383 | ) | ||
| 384 | ); | ||
| 385 | } | ||
| 386 | |||
| 387 | sub report { | ||
| 388 | my ($pkg, $db, $options) = @_; | ||
| 389 | |||
| 390 | $Template = Template->new({ | ||
| 391 | LOAD_TEMPLATES => | ||
| 392 | [ Devel::Cover::Report::Html_basic::Template::Provider->new({}) ] | ||
| 393 | }); | ||
| 394 | |||
| 395 | my $le = sub { ($_[0] > 0 ? "<" : "=") . " $_[0]" }; | ||
| 396 | my $ge = sub { ($_[0] < 100 ? ">" : "") . "= $_[0]" }; | ||
| 397 | |||
| 398 | my $fname = (sort keys %{ $db->{runs} })[0] or return; | ||
| 399 | my $run = $db->{runs}{$fname}; | ||
| 400 | |||
| 401 | %R = ( | ||
| 402 | module => { name => $run->name, version => $run->version }, | ||
| 403 | db => $db, | ||
| 404 | date => do { | ||
| 405 | my ($sec, $min, $hour, $mday, $mon, $year) = localtime; | ||
| 406 | sprintf "%04d-%02d-%02d %02d:%02d:%02d", $year + 1900, $mon + 1, $mday, | ||
| 407 | $hour, $min, $sec | ||
| 408 | }, | ||
| 409 | perl_v => $^V, | ||
| 410 | os => $^O, | ||
| 411 | options => $options, | ||
| 412 | version => $VERSION, | ||
| 413 | showing => [ grep $options->{show}{$_}, $db->criteria ], | ||
| 414 | headers => [ | ||
| 415 | map { ($db->criteria_short)[$_] } | ||
| 416 | grep { $options->{show}{ ($db->criteria)[$_] } } | ||
| 417 | (0 .. $db->criteria - 1) | ||
| 418 | ], | ||
| 419 | annotations => [ | ||
| 420 | map { my $a = $_; map $a->header($_), 0 .. $a->count - 1 } | ||
| 421 | @{ $options->{annotations} } | ||
| 422 | ], | ||
| 423 | filenames => { | ||
| 424 | map { $_ => do { (my $f = $_) =~ s/\W/-/g; $f } } @{ $options->{file} } | ||
| 425 | }, | ||
| 426 | exists => { map { $_ => -e } @{ $options->{file} } }, | ||
| 427 | get_summary => \&get_summary, | ||
| 428 | c0 => $le->($options->{report_c0}), | ||
| 429 | c1 => $le->($options->{report_c1}), | ||
| 430 | c2 => $le->($options->{report_c2}), | ||
| 431 | c3 => $ge->($options->{report_c2}), | ||
| 432 | ); | ||
| 433 | |||
| 434 | write_file $R{options}{outputdir}, "all"; | ||
| 435 | |||
| 436 | for (@{ $options->{file} }) { | ||
| 437 | $R{file} = $_; | ||
| 438 | $R{file_link} = "$R{filenames}{$_}.html"; | ||
| 439 | $R{file_html} = "$options->{outputdir}/$R{file_link}"; | ||
| 440 | my $show = $options->{show}; | ||
| 441 | print_file; | ||
| 442 | print_branches if $show->{branch}; | ||
| 443 | print_conditions if $show->{condition}; | ||
| 444 | print_subroutines if $show->{subroutine} || $show->{pod}; | ||
| 445 | } | ||
| 446 | |||
| 447 | my $html = print_summary; | ||
| 448 | print "HTML output written to $html\n" unless $options->{silent}; | ||
| 449 | } | ||
| 450 | |||
| 451 | 1; | ||
| 452 | |||
| 453 | package Devel::Cover::Report::Html_basic::Template::Provider; | ||
| 454 | |||
| 455 | use strict; | ||
| 456 | use warnings; | ||
| 457 | |||
| 458 | our $VERSION = '1.52'; # VERSION | ||
| 459 | |||
| 460 | use base "Template::Provider"; | ||
| 461 | |||
| 462 | my %Templates; | ||
| 463 | |||
| 464 | sub fetch { | ||
| 465 | my $self = shift; | ||
| 466 | my ($name) = @_; | ||
| 467 | # print "Looking for <$name>\n"; | ||
| 468 | $self->SUPER::fetch(exists $Templates{$name} ? \$Templates{$name} : $name) | ||
| 469 | } | ||
| 470 | |||
| 471 | $Templates{html} = <<'EOT'; | ||
| 472 | <!DOCTYPE html | ||
| 473 | PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
| 474 | "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
| 475 | <html xmlns="https://www.w3.org/1999/xhtml"> | ||
| 476 | <!-- | ||
| 477 | This file was generated by Devel::Cover Version [% R.version %] | ||
| 478 | Devel::Cover is copyright 2001-2026, Paul Johnson (paul@pjcj.net) | ||
| 479 | Devel::Cover is free. It is licensed under the same terms as Perl itself. | ||
| 480 | The latest version of Devel::Cover should be available from my homepage: | ||
| 481 | https://pjcj.net | ||
| 482 | --> | ||
| 483 | <head> | ||
| 484 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta> | ||
| 485 | <meta http-equiv="Content-Language" content="en-us"></meta> | ||
| 486 | <link rel="stylesheet" type="text/css" href="cover.css"></link> | ||
| 487 | <script type="text/javascript" src="common.js"></script> | ||
| 488 | <script type="text/javascript" src="css.js"></script> | ||
| 489 | <script type="text/javascript" src="standardista-table-sorting.js"></script> | ||
| 490 | <title> [% title || "Coverage Summary" %] </title> | ||
| 491 | </head> | ||
| 492 | <body> | ||
| 493 | [% content %] | ||
| 494 | </body> | ||
| 495 | </html> | ||
| 496 | EOT | ||
| 497 | |||
| 498 | $Templates{header} = <<'EOT'; | ||
| 499 | <table> | ||
| 500 | <tr> | ||
| 501 | <th colspan="4">[% R.file %]</th> | ||
| 502 | </tr> | ||
| 503 | <tr class="hblank"><td class="dblank"></td></tr> | ||
| 504 | <tr> | ||
| 505 | <th class="hh">Criterion</th> | ||
| 506 | <th class="hh">Covered</th> | ||
| 507 | <th class="hh">Total</th> | ||
| 508 | <th class="hh">%</th> | ||
| 509 | </tr> | ||
| 510 | [% FOREACH criterion = criteria %] | ||
| 511 | [% vals = R.get_summary(R.file, criterion) %] | ||
| 512 | <tr> | ||
| 513 | <td class="h">[% criterion %]</td> | ||
| 514 | <td>[% vals.covered %]</td> | ||
| 515 | <td>[% vals.total %]</td> | ||
| 516 | <td [% IF vals.class %]class="[% vals.class %]" [% END %]title="[% vals.details %]"> | ||
| 517 | [% IF vals.link.defined %] | ||
| 518 | <a href="[% vals.link %]"> [% vals.pc %] </a> | ||
| 519 | [% ELSE %] | ||
| 520 | [% vals.pc %] | ||
| 521 | [% END %] | ||
| 522 | </td> | ||
| 523 | </tr> | ||
| 524 | [% END %] | ||
| 525 | </table> | ||
| 526 | <div><br></br></div> | ||
| 527 | EOT | ||
| 528 | |||
| 529 | $Templates{summary} = <<'EOT'; | ||
| 530 | [% WRAPPER html %] | ||
| 531 | |||
| 532 | <h1> Coverage Summary </h1> | ||
| 533 | <table> | ||
| 534 | <tr> | ||
| 535 | <td class="sh" align="right">Module</td> | ||
| 536 | <td class="sv" align="left" colspan="4">[% R.module.name %]</td> | ||
| 537 | </tr> | ||
| 538 | <tr> | ||
| 539 | <td class="sh" align="right">Version</td> | ||
| 540 | <td class="sv" align="left" colspan="4">[% R.module.version %]</td> | ||
| 541 | </tr> | ||
| 542 | <tr> | ||
| 543 | <td class="sh" align="right">Database:</td> | ||
| 544 | <td class="sv" align="left" colspan="4">[% R.db.db %]</td> | ||
| 545 | </tr> | ||
| 546 | <tr> | ||
| 547 | <td class="sh" align="right">Report date:</td> | ||
| 548 | <td class="sv" align="left" colspan="4">[% R.date %]</td> | ||
| 549 | </tr> | ||
| 550 | <tr> | ||
| 551 | <td class="sh" align="right">Perl version:</td> | ||
| 552 | <td class="sv" align="left" colspan="4">[% R.perl_v %]</td> | ||
| 553 | </tr> | ||
| 554 | <tr> | ||
| 555 | <td class="sh" align="right">OS:</td> | ||
| 556 | <td class="sv" align="left" colspan="4">[% R.os %]</td> | ||
| 557 | </tr> | ||
| 558 | <tr> | ||
| 559 | <td class="sh" align="right">Thresholds:</td> | ||
| 560 | <td class="sv c0">[% R.c0 | html %]%</td> | ||
| 561 | <td class="sv c1">[% R.c1 | html %]%</td> | ||
| 562 | <td class="sv c2">[% R.c2 | html %]%</td> | ||
| 563 | <td class="sv c3">[% R.c3 | html %]%</td> | ||
| 564 | </tr> | ||
| 565 | </table> | ||
| 566 | <div><br /></div> | ||
| 567 | |||
| 568 | [% IF R.options.option.restrict %] | ||
| 569 | <script type="text/javascript"> | ||
| 570 | <!-- hide | ||
| 571 | function filter_files(filter_by) { | ||
| 572 | var allElements = document.getElementsByTagName("tr"); | ||
| 573 | var re_now = new RegExp(filter_by, "i"); | ||
| 574 | for (var i = 0; i < allElements.length; i++) { | ||
| 575 | if (allElements[i].className) { | ||
| 576 | if (filter_by == "" || allElements[i].className == "Total" || | ||
| 577 | (filter_by.length && re_now.test(allElements[i].className))) { | ||
| 578 | allElements[i].style.display = "table-row"; | ||
| 579 | } else if (filter_by.length && | ||
| 580 | !re_now.test(allElements[i].className)) { | ||
| 581 | allElements[i].style.display = "none"; | ||
| 582 | } | ||
| 583 | } | ||
| 584 | } | ||
| 585 | } | ||
| 586 | // --> | ||
| 587 | </script> | ||
| 588 | |||
| 589 | <form name="filterform" | ||
| 590 | action='javascript:filter_files(document.forms["filterform"]["filterfield"].value)'> | ||
| 591 | Restrict to regex: | ||
| 592 | <input type="text" name="filterfield" /><input type="submit" /> | ||
| 593 | </form> | ||
| 594 | |||
| 595 | <br /> | ||
| 596 | [% END %] | ||
| 597 | |||
| 598 | <table class="sortable" id="coverage_table"> | ||
| 599 | <thead> | ||
| 600 | <tr> | ||
| 601 | <th> file </th> | ||
| 602 | [% FOREACH header = R.headers %] | ||
| 603 | <th> [% header %] </th> | ||
| 604 | [% END %] | ||
| 605 | <th> total </th> | ||
| 606 | </tr> | ||
| 607 | </thead> | ||
| 608 | |||
| 609 | <tfoot> | ||
| 610 | [% FOREACH file = files %] | ||
| 611 | <tr align="center" valign="top" class="[% file %]"> | ||
| 612 | <td align="left"> | ||
| 613 | [% IF R.exists.$file %] | ||
| 614 | <a href="[% R.filenames.$file %].html"> [% file %] </a> | ||
| 615 | [% ELSE %] | ||
| 616 | [% file %] | ||
| 617 | [% END %] | ||
| 618 | </td> | ||
| 619 | |||
| 620 | [% FOREACH criterion = R.showing %] | ||
| 621 | [% vals = R.get_summary(file, criterion) %] | ||
| 622 | [% IF vals.class %] | ||
| 623 | <td class="[% vals.class %]" title="[% vals.details %]"> | ||
| 624 | [% ELSE %] | ||
| 625 | <td> | ||
| 626 | [% END %] | ||
| 627 | [% IF vals.link.defined %] | ||
| 628 | <a href="[% vals.link %]"> [% vals.pc %] </a> | ||
| 629 | [% ELSE %] | ||
| 630 | [% vals.pc %] | ||
| 631 | [% END %] | ||
| 632 | </td> | ||
| 633 | [% END %] | ||
| 634 | |||
| 635 | [% vals = R.get_summary(file, "total") %] | ||
| 636 | <td class="[% vals.class %]" title="[% vals.details %]"> | ||
| 637 | [% vals.pc %] | ||
| 638 | </td> | ||
| 639 | </tr> | ||
| 640 | |||
| 641 | [% IF file == "Total" %] | ||
| 642 | </tfoot> | ||
| 643 | <tbody> | ||
| 644 | [% END %] | ||
| 645 | [% END %] | ||
| 646 | </tbody> | ||
| 647 | </table> | ||
| 648 | |||
| 649 | [% END %] | ||
| 650 | EOT | ||
| 651 | |||
| 652 | $Templates{file} = <<'EOT'; | ||
| 653 | [% WRAPPER html %] | ||
| 654 | |||
| 655 | <h1> File Coverage </h1> | ||
| 656 | |||
| 657 | [% | ||
| 658 | crit = []; | ||
| 659 | FOREACH criterion = R.showing; | ||
| 660 | crit.push(criterion) UNLESS criterion == "time"; | ||
| 661 | END; | ||
| 662 | crit.push("total"); | ||
| 663 | PROCESS header criteria = crit; | ||
| 664 | %] | ||
| 665 | |||
| 666 | <table> | ||
| 667 | <tr> | ||
| 668 | <th> line </th> | ||
| 669 | [% FOREACH header = R.annotations.merge(R.headers) %] | ||
| 670 | <th> [% header %] </th> | ||
| 671 | [% END %] | ||
| 672 | <th> code </th> | ||
| 673 | </tr> | ||
| 674 | |||
| 675 | [% FOREACH line = lines %] | ||
| 676 | <tr> | ||
| 677 | <td [% IF line.number %] class="h" [% END %]> | ||
| 678 | <a [% IF line.number != ' ' %]name="[% line.number %]"[% END %]>[% line.number %]</a> | ||
| 679 | </td> | ||
| 680 | [% FOREACH cr = line.criteria %] | ||
| 681 | <td [% IF cr.class %] class="[% cr.class %]" [% END %]> | ||
| 682 | [% IF cr.link.defined %] <a href="[% cr.link %]"> [% END %] | ||
| 683 | [% cr.text %] | ||
| 684 | [% IF cr.link.defined %] </a> [% END %] | ||
| 685 | </td> | ||
| 686 | [% END %] | ||
| 687 | <td class="s"> [% line.text %] </td> | ||
| 688 | </tr> | ||
| 689 | [% END %] | ||
| 690 | </table> | ||
| 691 | |||
| 692 | [% END %] | ||
| 693 | EOT | ||
| 694 | |||
| 695 | $Templates{branches} = <<'EOT'; | ||
| 696 | [% WRAPPER html %] | ||
| 697 | |||
| 698 | <h1> Branch Coverage </h1> | ||
| 699 | |||
| 700 | [% PROCESS header criteria = [ "branch" ] %] | ||
| 701 | |||
| 702 | <table> | ||
| 703 | <tr> | ||
| 704 | <th> line </th> | ||
| 705 | <th> true </th> | ||
| 706 | <th> false </th> | ||
| 707 | <th> branch </th> | ||
| 708 | </tr> | ||
| 709 | |||
| 710 | [% FOREACH branch = branches %] | ||
| 711 | <a name="[% branch.ref %]"> </a> | ||
| 712 | <tr> | ||
| 713 | <td class="h"> | ||
| 714 | <a href="[% R.file_link %]#[% branch.number %]">[% branch.number %]</a> | ||
| 715 | </td> | ||
| 716 | [% FOREACH part = branch.parts %] | ||
| 717 | <td class="[% part.class %]"> [% part.text %] </td> | ||
| 718 | [% END %] | ||
| 719 | <td class="s"> [% branch.text %] </td> | ||
| 720 | </tr> | ||
| 721 | [% END %] | ||
| 722 | </table> | ||
| 723 | |||
| 724 | [% END %] | ||
| 725 | EOT | ||
| 726 | |||
| 727 | $Templates{conditions} = <<'EOT'; | ||
| 728 | [% WRAPPER html %] | ||
| 729 | |||
| 730 | <h1> Condition Coverage </h1> | ||
| 731 | |||
| 732 | [% PROCESS header criteria = [ "condition" ] %] | ||
| 733 | |||
| 734 | [% FOREACH type = types %] | ||
| 735 | <h2> [% type.name %] conditions </h2> | ||
| 736 | |||
| 737 | <table> | ||
| 738 | <tr> | ||
| 739 | <th> line </th> | ||
| 740 | [% FOREACH header = type.headers %] | ||
| 741 | <th> [% header %] </th> | ||
| 742 | [% END %] | ||
| 743 | <th> condition </th> | ||
| 744 | </tr> | ||
| 745 | |||
| 746 | [% FOREACH condition = type.conditions %] | ||
| 747 | <a name="[% condition.ref %]"> </a> | ||
| 748 | <tr> | ||
| 749 | <td class="h"> | ||
| 750 | <a href="[% R.file_link %]#[% condition.number %]">[% condition.number %]</a> | ||
| 751 | </td> | ||
| 752 | [% FOREACH part = condition.parts %] | ||
| 753 | <td class="[% part.class %]"> [% part.text %] </td> | ||
| 754 | [% END %] | ||
| 755 | <td class="s"> [% condition.text %] </td> | ||
| 756 | </tr> | ||
| 757 | [% END %] | ||
| 758 | </table> | ||
| 759 | [% END %] | ||
| 760 | |||
| 761 | [% END %] | ||
| 762 | EOT | ||
| 763 | |||
| 764 | $Templates{subroutines} = <<'EOT'; | ||
| 765 | [% WRAPPER html %] | ||
| 766 | |||
| 767 | <h1> Subroutine Coverage </h1> | ||
| 768 | |||
| 769 | [% | ||
| 770 | crit = []; | ||
| 771 | crit.push("subroutine") IF R.options.show.subroutine; | ||
| 772 | crit.push("pod") IF R.options.show.pod; | ||
| 773 | PROCESS header criteria = crit; | ||
| 774 | %] | ||
| 775 | |||
| 776 | <table> | ||
| 777 | <tr> | ||
| 778 | <th> line </th> | ||
| 779 | [% IF R.options.show.subroutine %] | ||
| 780 | <th> count </th> | ||
| 781 | [% END %] | ||
| 782 | [% IF R.options.show.pod %] | ||
| 783 | <th> pod </th> | ||
| 784 | [% END %] | ||
| 785 | <th> subroutine </th> | ||
| 786 | </tr> | ||
| 787 | [% FOREACH sub = subs %] | ||
| 788 | <tr> | ||
| 789 | <td class="h"> | ||
| 790 | <a href="[% R.file_link %]#[% sub.line %]">[% sub.line %]</a> | ||
| 791 | </td> | ||
| 792 | [% IF R.options.show.subroutine %] | ||
| 793 | <td class="[% sub.class %]"> [% sub.count %] </td> | ||
| 794 | [% END %] | ||
| 795 | [% IF R.options.show.pod %] | ||
| 796 | <td class="[% sub.pclass %]"> [% sub.pod %] </td> | ||
| 797 | [% END %] | ||
| 798 | <td> [% sub.name %] </td> | ||
| 799 | </tr> | ||
| 800 | [% END %] | ||
| 801 | </table> | ||
| 802 | |||
| 803 | [% END %] | ||
| 804 | EOT | ||
| 805 | |||
| 806 | # remove some whitespace from templates | ||
| 807 | s/^\s+//gm for values %Templates; | ||
| 808 | |||
| 809 | 1; | ||
| 810 | |||
| 811 | =head1 NAME | ||
| 812 | |||
| 813 | Devel::Cover::Report::Html_basic - HTML backend for Devel::Cover | ||
| 814 | |||
| 815 | =head1 VERSION | ||
| 816 | |||
| 817 | version 1.52 | ||
| 818 | |||
| 819 | =head1 SYNOPSIS | ||
| 820 | |||
| 821 | cover -report html_basic | ||
| 822 | |||
| 823 | =head1 DESCRIPTION | ||
| 824 | |||
| 825 | This module provides a HTML reporting mechanism for coverage data. It | ||
| 826 | is designed to be called from the C<cover> program. It will add syntax | ||
| 827 | highlighting if C<PPI::HTML> or C<Perl::Tidy> is installed. | ||
| 828 | |||
| 829 | =head1 OPTIONS | ||
| 830 | |||
| 831 | The following command line options are supported: | ||
| 832 | |||
| 833 | -outputfile - name of output file (default coverage.html) | ||
| 834 | -restrict - add restrict to regex form (default on) | ||
| 835 | -noppihtml - disables PPI::HTML highlighting (default off) | ||
| 836 | -noperltidy - disables Perl::Tidy highlighting (default off) | ||
| 837 | |||
| 838 | =head1 SEE ALSO | ||
| 839 | |||
| 840 | Devel::Cover | ||
| 841 | |||
| 842 | =head1 LICENCE | ||
| 843 | |||
| 844 | Copyright 2001-2026, Paul Johnson (paul@pjcj.net) | ||
| 845 | |||
| 846 | This software is free. It is licensed under the same terms as Perl itself. | ||
| 847 | |||
| 848 | The latest version of this software should be available from my homepage: | ||
| 849 | https://pjcj.net | ||
| 850 | |||
| 851 | =cut |