当我运行Devel::Cover
时ModPerl::Registry
,除了BEGIN
块之外,我没有得到任何覆盖信息。当我Devel::Cover
从命令行或作为 CGI 运行相同的脚本时,一切正常(显然)。
如何让Devel::Cover
“看到”我的代码在运行时执行?
这是Devel::Cover
我的相关内容httpd.conf
:
MaxClients 1
PerlSetEnv DEVEL_COVER_OPTIONS -db,/tmp/cover_db,-silent,1
PerlRequire /var/www/project/startup.pl
这是startup.pl
:
#!/usr/bin/perl
use strict;
use warnings;
use Apache2::Directive ();
BEGIN {
# Devel::Cover database must be writable by worker processes
my $conftree = Apache2::Directive::conftree->as_hash;
my $name = $conftree->{User}
or die "couldn't find user in Apache config";
print "user=$name\n";
my $uid = getpwnam($name);
defined $uid
or die "couldn't determine uid by name";
no warnings 'redefine';
local $> = $uid;
require Devel::Cover;
my $old_report = \&Devel::Cover::report;
*Devel::Cover::report = sub { local $> = $uid; $old_report->(@_) };
Devel::Cover->import;
}
1;
(如您所见,我为Devel::Cover
since startup.pl
is running by 做了一个猴子补丁root
,但工作进程在不同的用户下运行,否则他们无法读取由 . 创建的目录startup.pl
。如果您知道更好的解决方案,请记下.)