4

我有一个 Perl 模块,它本身似乎可以很好地编译,但是在包含它时会导致其他程序编译失败:

me@host:~/code $ perl -c -Imodules modules/Rebat/Store.pm
modules/Rebat/Store.pm syntax OK
me@host:~/code $ perl -c -Imodules bin/rebat-report-status
Attempt to reload Rebat/Store.pm aborted
Compilation failed in require at bin/rebat-report-status line 4.
BEGIN failed--compilation aborted at bin/rebat-report-status line 4.

的前几行rebat-report-status

...
3 use Rebat;
4 use Rebat::Store;
5 use strict;
...
4

2 回答 2

9

编辑(供后代使用):发生这种情况的另一个原因,也许是最常见的原因,是您正在使用的模块之间存在循环依赖关系。


寻找Rebat/Store.pm线索。您的日志显示尝试重新加载已中止。也许Rebat已经导入了Rebat::Store,并且Rebat::Store有一些包范围检查以防止被加载两次。

这段代码演示了我所说的那种情况:

# m1.pl:
use M1;
use M1::M2;
M1::M2::x();

# M1.pm 
package M1;
use M1::M2;
1;

# M1/M2.pm
package M1::M2;
our $imported = 0;
sub import {
    die "Attempt to reload M1::M2 aborted.\n" if $imported++;
}
sub x { print "42\n" }
1;

$ perl m1.pl
Attempt to reload M1::M2 aborted.
BEGIN failed--compilation aborted at m1.pl line 3.

如果您只删除use M1::M2. m1.pl在您的情况下,您可能不需要use Rebat::Store在您的程序中明确显示。

于 2010-02-04T18:47:17.847 回答
4

perldoc perldiag

 Attempt to reload %s aborted.
           (F) You tried to load a file with "use" or "require" that failed to
           compile once already.  Perl will not try to compile this file again
           unless you delete its entry from %INC.  See "require" in perlfunc
           and "%INC" in perlvar.
于 2010-06-08T15:50:26.307 回答