/usr/lib/x86_64-linux-gnu/perl5/5.22/Devel/Cover/Report/Text.pm is in libdevel-cover-perl 1.21-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | # Copyright 2001-2015, Paul Johnson (paul@pjcj.net)
# This software is free. It is licensed under the same terms as Perl itself.
# The latest version of this software should be available from my homepage:
# http://www.pjcj.net
package Devel::Cover::Report::Text;
use strict;
use warnings;
our $VERSION = '1.21'; # VERSION
use Devel::Cover::DB;
sub print_runs {
my ($db, $options) = @_;
for my $r (sort {$a->{start} <=> $b->{start}} $db->runs) {
print "Run: ", $r->run, "\n";
print "Perl version: ", $r->perl, "\n";
print "OS: ", $r->OS, "\n";
print "Start: ", scalar gmtime $r->start , "\n";
print "Finish: ", scalar gmtime $r->finish, "\n";
print "\n";
# use Devel::Cover::Dumper; print Dumper $r;
}
}
sub print_statement {
my ($db, $file, $options) = @_;
my $cover = $db->cover;
print "$file\n\n";
my $f = $cover->file($file);
my $fmt = "%-5s %3s ";
my @args = ("line", "err");
for my $ann (@{$options->{annotations}}) {
for my $a (0 .. $ann->count - 1) {
$fmt .= "%-" . $ann->width($a) . "s ";
push @args, $ann->header($a);
}
}
my %cr; @cr{$db->criteria} = $db->criteria_short;
for my $c ($db->criteria) {
if ($options->{show}{$c}) {
$fmt .= "%6s ";
push @args, $cr{$c};
}
}
$fmt .= " %s\n";
push @args, "code";
printf $fmt, @args;
my $autoloader = 0;
open F, $file or warn("Unable to open $file: $!\n"), return;
LINE: while (defined(my $l = <F>)) {
chomp $l;
my $n = $.;
$autoloader ||= $l =~ /use\s+AutoLoader/;
my %criteria;
for my $c ($db->criteria) {
next unless $options->{show}{$c};
my $criterion = $f->$c();
if ($criterion) {
my $l = $criterion->location($n);
$criteria{$c} = $l ? [@$l] : $l;
}
}
my $more = 1;
while ($more) {
my @args = ($n, "");
my $error = 0;
for my $ann (@{$options->{annotations}}) {
for my $a (0 .. $ann->count - 1) {
push @args,
substr $ann->text($file, $n, $a), 0, $ann->width($a);
$error ||= $ann->error($file, $n, $a);
}
}
$more = 0;
for my $c ($db->criteria) {
next unless $options->{show}{$c};
my $o = shift @{$criteria{$c}};
$more ||= @{$criteria{$c}};
my $value = $o
? ($c =~ /statement|sub|pod|time/)
? $o->covered
: $o->percentage
: "";
$value = "-" . $value if $o && $o->uncoverable;
push @args, $value;
$error ||= $o->error if $o;
}
$args[1] = "***" if $error;
push @args, $l;
# print join(", ", map { "[$_]" } @args), "\n";
printf $fmt, @args;
last LINE if !$autoloader && $l =~ /^__(END|DATA)__/;
$n = $l = "";
}
}
close F or die "Unable to close $file: $!";
print "\n\n";
}
sub print_branches {
my ($db, $file, $options) = @_;
my $branches = $db->cover->file($file)->branch;
return unless $branches;
print "Branches\n";
print "--------\n\n";
my $tpl = "%-5s %3s %6s %6s %6s %s\n";
printf $tpl, "line", "err", "%", "true", "false", "branch";
printf $tpl, "-----", "---", ("------") x 3, "------";
for my $location (sort { $a <=> $b } $branches->items) {
my $n = 0;
for my $b (@{$branches->location($location)}) {
printf $tpl,
$n ? "" : $location, $b->error ? "***" : "",
($b->uncoverable ? "-" : "") . $b->percentage,
map (($b->uncoverable($_) ? "-" : "") .
($b->covered($_) || 0), 0 .. $b->total - 1),
$b->text;
$n++;
}
}
print "\n\n";
}
sub print_conditions {
my ($db, $file, $options) = @_;
my $conditions = $db->cover->file($file)->condition;
return unless $conditions;
my $template = sub { "%-5s %3s %6s " . ( "%6s " x shift ) . " %s\n" };
my %r;
for my $location (sort { $a <=> $b } $conditions->items) {
my %seen;
for my $c (@{$conditions->location($location)}) {
push @{$r{$c->type}}, [ $c, $seen{$c->type}++ ? "" : $location ];
}
}
print "Conditions\n";
print "----------\n\n";
my %seen;
for my $type (sort keys %r) {
my $tpl;
for (@{$r{$type}}) {
my ($c, $location) = @$_;
unless ($seen{$type}++) {
my $headers = $c->headers;
my $nh = @$headers;
$tpl = $template->($nh);
(my $t = $type) =~ s/_/ /g;
print "$t conditions\n\n";
printf $tpl, "line", "err", "%", @$headers, "expr";
printf $tpl, "-----", "---", ("------") x ($nh + 1), "----";
}
printf $tpl, $location, $c->error ? "***" : "",
($c->uncoverable ? "-" : "") . $c->percentage,
map (($c->uncoverable($_) ? "-" : "") .
($c->covered($_) || 0), 0 .. $c->total - 1),
$c->text;
}
print "\n";
}
print "\n";
}
sub print_subroutines {
my ($db, $file, $options) = @_;
my $dfil = $db->cover->file($file);
my $subs = $dfil->subroutine or return;
my $pods = $options->{show}{pod} && $dfil->pod;
my $maxh = 8;
my $maxc = 5;
my $maxp = 3;
my $maxs = 10;
my %subs;
for my $location ($subs->items) {
my $l = $subs->location($location);
my $d = $pods && $pods->location($location);
for my $sub (@$l) {
my $h = "$file:$location";
my $c = ($sub->uncoverable ? "-" : "") . $sub->covered;
my $e = $pods && shift @$d;
my $p = $e ? ($e->uncoverable ? "-" : "") . $e->covered : "";
my $s = $sub->name;
$maxh = length $h if length $h > $maxh;
$maxc = length $c if length $c > $maxc;
$maxp = length $p if $p && length $p > $maxp;
$maxs = length $s if length $s > $maxs;
push @{$subs{$sub->covered ? "covered" : "uncovered"}{$s}},
[$c, $pods ? $p : (), $h];
}
}
my $template = "%-${maxs}s %${maxc}s ";
$template .= "%${maxp}s " if $pods;
$template .= "%-${maxh}s\n";
for my $type (sort keys %subs) {
print ucfirst $type, " Subroutines\n";
print "-" x (12 + length $type), "\n\n";
printf $template, "Subroutine", "Count", $pods ? "Pod" : (), "Location";
printf $template, "-" x $maxs, "-" x $maxc, $pods ? "-" x $maxp : (),
"-" x $maxh;
for my $s (sort keys %{$subs{$type}}) {
printf $template, $s, @$_
for sort {$a->[-1] cmp $b->[-1]} @{$subs{$type}{$s}};
}
print "\n";
}
print "\n";
}
sub report {
my ($pkg, $db, $options) = @_;
print_runs($db, $options);
for my $file (@{$options->{file}}) {
print_statement ($db, $file, $options) if $options->{show}{statement};
print_branches ($db, $file, $options) if $options->{show}{branch};
print_conditions ($db, $file, $options) if $options->{show}{condition};
print_subroutines($db, $file, $options)
if $options->{show}{subroutine} || $options->{show}{pod};
}
}
1
__END__
=head1 NAME
Devel::Cover::Report::Text - Text backend for Devel::Cover
=head1 VERSION
version 1.21
=head1 SYNOPSIS
cover -report text
=head1 DESCRIPTION
This module provides a textual reporting mechanism for coverage data.
It is designed to be called from the C<cover> program.
=head1 SEE ALSO
Devel::Cover
=head1 BUGS
Huh?
=head1 LICENCE
Copyright 2001-2015, Paul Johnson (paul@pjcj.net)
This software is free. It is licensed under the same terms as Perl itself.
The latest version of this software should be available from my homepage:
http://www.pjcj.net
=cut
|