| Next | Tricks of the Wizards | Slide #157 |
package Devel::Coverage;
sub DB::DB {
my ($package, $file, $line) = caller();
$files{$file} = 1;
$covered{$file}[$line] = 1;
}
END {
for my $file (keys %files) {
my $array = \@{"::_<$file"};
my ($executable, $covered) = (0, 0);
for my $line (1 .. $#$array) {
next if $array->[$line] == 0;
$executable += 1;
$covered += $covered{$file}[$line];
}
printf STDERR "%4d/%4d (%3.0f%%) covered in %s.\n",
$covered, $executable, 100*$covered/$executable, $file
unless $executable == 0;
}
}
In numeric context, @{"::_<foo"} elements are special
They are equal to zero only when the line is not executable
10/ 31 ( 32%) covered in /usr/local/lib/perl5/5.6.0/Exporter.pm.
10/ 70 ( 14%) covered in /usr/local/lib/perl5/5.6.0/Getopt/Std.pm.
8/ 12 ( 67%) covered in /tmp/Devel/Coverage.pm.
60/ 74 ( 81%) covered in ./MAKE_SLIDES.
| Next | ![]() |
Copyright © 2000 M-J. Dominus |