正如标题所述,我在尝试使用我的perl模块时遇到此错误,但我不知道这意味着什么,我似乎无法在互联网上找到任何明确的结果.我的代码由3个文件组成:一个脚本(myApp.pl),它使用一个模块(MyLib.pm),后者又使用另一个模块(Secret.pm).在这里他们是完整的:
myApp.pl
#!/path/to/perl
my $version = "1.0.0";
use warnings;
use strict;
use Testing::MyLib;
Run Code Online (Sandbox Code Playgroud)
MyLib.pm
package Testing::MyLib;
use strict;
use warnings;
use Testing::Secret;
Run Code Online (Sandbox Code Playgroud)
Secret.pm
package Testing::Secret;
use strict;
use warnings;
use Exporter qw( import );
our @EXPORT = ();
our %EXPORT_TAGS = (
'all' => [ qw( MY_CONSTANT )]
);
our @EXPORT_OK = (
@{ $EXPORT_TAGS{all}}
);
use constant MY_CONSTANT => 'bla bla bla';
Run Code Online (Sandbox Code Playgroud)
它们以此文件结构退出:
/bin/myApp.pl
/lib/perl/Testing/MyLib.pm
/lib/perl/Testing/Secret.pm
Run Code Online (Sandbox Code Playgroud)
错误消息的详细信息是:
[user@pc ~]$ myApp.pl
"import" is not exported by the Exporter module at /###/lib/perl/Testing/Secret.pm line 6
Can't continue after import errors at /###/lib/perl/Testing/Secret.pm line 6
BEGIN failed--compilation aborted at /###/lib/perl/Testing/Secret.pm line 6.
Compilation failed in require at /###/lib/perl/Testing/MyLib.pm line 6.
BEGIN failed--compilation aborted at /###/lib/perl/Testing/MyLib.pm line 6.
Compilation failed in require at /###/bin/myApp.pl line 7.
BEGIN failed--compilation aborted at /###/bin/myApp.pl line 7.
Run Code Online (Sandbox Code Playgroud)
use Exporter qw( import ); 请求 Exporter import在模块的命名空间中导出(创建).这是处理从模块导出的请求的方法.早于5.57的Exporter版本无法识别此请求,从而导致您获得的错误消息.
自从Perl 5.8.3以来,Exporter 5.57或更新版本已与Perl捆绑在一起,你必须拥有一个非常古老的Perl版本和模块!
你可以升级Exporter,或者你可以import从Exporter 继承,这有点麻烦,但适用于任何版本的Exporter.
package MyPackage;
use strict;
use warnings;
use Exporter;
our @ISA = 'Exporter';
our @EXPORT_OK = ...;
Run Code Online (Sandbox Code Playgroud)