本文介绍了Devel :: Cover和ModPerl :: Registry对运行时没有覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 ModPerl :: Registry 运行 Devel :: Cover 时,除了覆盖范围之外,我没有任何覆盖信息对于 BEGIN 块。当我使用 Devel :: Cover 从命令行或作为CGI运行相同的脚本时,一切正常(显然)。

When I'm running Devel::Cover with ModPerl::Registry, I get no coverage info except for BEGIN blocks. When I'm running the same script with Devel::Cover from command line or as a CGI, everything works alright (obviously).

如何使 Devel :: Cover 看到我的代码在运行时正在执行?

How can I make Devel::Cover "see" my code being executed in the runtime?

我的 httpd.conf 中的 Devel :: Cover 相关内容:

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制作了一个猴子补丁::掩盖,因为 startup.pl 是由 root 运行的,但是工作进程在一个不同的用户,否则他们将无法读取 startup.pl 创建的目录。如果您知道更好的解决方案,请做个注释。)

(As you may see, I made a monkey patch for Devel::Cover since startup.pl is being run by root, but worker processes run under a different user, and otherwise they couldn't read directories created by startup.pl. If you know a better solution, make a note, please.)

推荐答案

我认为这是由于Devel :: Cover来不及添加钩子所致,即在所有代码都已编译之后。我会尝试在startup.pl开头添加 use Devel :: Cover PerlModule Devel :: Cover 在httpd.conf中其他mod_perl之前。

I think is due to Devel::Cover coming in too late to add hooks, i.e. after all your code has been compiled. I'd try adding use Devel::Cover at the beginning of your startup.pl, or PerlModule Devel::Cover before the other mod_perl stuff in httpd.conf.

这篇关于Devel :: Cover和ModPerl :: Registry对运行时没有覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 16:38