模块在循环中相互使用。Perl中的编译错误
有3个模块,因此它们按模式相互使用 a->b->c->a。我无法编撰这样的案例 比如说, 我得到一个编译错误模块在循环中相互使用。Perl中的编译错误,perl,exporter,Perl,Exporter,有3个模块,因此它们按模式相互使用 a->b->c->a。我无法编撰这样的案例 比如说, 我得到一个编译错误 "Throw" is not exported by the LIB::Common::Utils module Can't continue after import errors at /root/bin/ppm/LIB/Common/EnvConfigMgr.pm line 13 BEGIN failed--compilation aborted at /root/bin/ppm/
"Throw" is not exported by the LIB::Common::Utils module
Can't continue after import errors at /root/bin/ppm/LIB/Common/EnvConfigMgr.pm line 13
BEGIN failed--compilation aborted at /root/bin/ppm/LIB/Common/EnvConfigMgr.pm line 13.
Utils.pm
use Exporter qw(import);
our @EXPORT_OK = qw(
GetDirCheckSum
AreDirsEqual
onError
Throw);
use LIB::Common::Logger::Log;
下午六时正
use Log::Log4perl;
use LIB::Common::EnvConfigMgr qw/Expand/;
环境管理主任
use Exporter qw(import);
our @EXPORT = qw(TransformShellVars ExpandString InitSearchLocations);
our @EXPORT_OK = qw(Expand);
use LIB::Common::Utils qw/Throw/;
为什么不编译它以及如何使它工作?您需要使用
require
,而不是在依赖项循环中的某个地方使用,以延迟绑定。使用不导出任何内容的模块最为方便,否则需要编写显式的import
调用
在您的情况下,LIB::Common::Logger::Log
不使用Export
,因此
require LIB::Common::Logger::Log
intoLIB/Common/Utils.pm
修复了该问题
您可以访问不工作的代码,只需显示出现故障的代码就可以为我们节省大量时间。你忽略了两条要求更多信息的评论,所以我设置了这些文件
注意,这段代码什么都不做:它只是编译
LIB/Common/Utils.pm
LIB/Common/Logger/EnvConfigMgr.pm
LIB/Common/Logger/Log.pm
main.pl
你还应该包括你正在导出的函数的存根,这样我们就可以复制/粘贴它并进行尝试。请显示一个使用这些模块并显示相同问题的main.pl
。您可以键入短语“…延迟绑定…”的详细信息吗?@osiv:术语“延迟绑定”在这里有点用词不当。它恰当地引用了面向对象的概念,即方法调用是在运行时根据继承原则解析的,而不是在编译时解析的。这是Perl使用的方法。我在这里的意思是在运行时建立任何标识符的含义的更一般的想法。@osiv:use
使用隐式BEGIN
块,因此在编译阶段编译模块并导入任何符号require
在运行时执行,因此当循环成为具有开始和结束的链时,您可以通过使用至少一个require
来打破依赖循环。正是出于这个原因,您经常会在CPAN模块中看到require
。
package LIB::Common::Utils;
use Exporter 'import';
our @EXPORT_OK = qw/
GetDirCheckSum
AreDirsEqual
onError
Throw
/;
require LIB::Common::Logger::Log;
sub GetDirCheckSum { }
sub AreDirsEqual { }
sub onError { }
sub Throw { }
1;
package LIB::Common::EnvConfigMgr;
use Exporter 'import';
our @EXPORT = qw/ TransformShellVars ExpandString InitSearchLocations /;
our @EXPORT_OK = 'Expand';
use LIB::Common::Utils 'Throw';
sub TransformShellVars { }
sub ExpandString { }
sub InitSearchLocations { }
sub Expand { }
1;
package LIB::Common::Logger::Log;
use Log::Log4perl;
use LIB::Common::EnvConfigMgr 'Expand';
1;
use strict;
use warnings 'all';
use FindBin;
use lib $FindBin::Bin;
use LIB::Common::Utils;