我已经在包含语句的更大代码块上浪费了很多天Exporter
,这在大约一年前曾经可以工作。这方面的几个变体都失败了,包括一个安装./FOO/BAR/Foobar.pm
成功的信号。
我正在使用为 MSWin32-x64-multi-thread 构建的 Windows 10,Perl v5.26.0
调用者.pl
#!/usr/bin/perl
use lib ".";
use lib "./FOO/BAR";
use strict;
use warnings;
use FOO::BAR::Foobar;
print "try FOO::BAR::Foobar::foo()\n";
FOO::BAR::Foobar::foo(); # perl can't find this
print "try foo()\n";
foo(); # errors out - can't find &main::foo
print "done\n";
./FOO/BAR/Foobar.pl
#!/usr/bin/perl -w
use strict;
use warnings;
package Foobar;
our($VERSION , @ISA , @EXPORT , @EXPORT_OK , %EXPORT_TAGS , $FOO);
BEGIN {
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(foo);
}
sub foo {
print "Loaded\n";
$FOO = q{some val};
}
1;
执行转储
perl Caller.pl
try FOO::BAR::Foobar::foo()
Undefined subroutine &FOO::BAR::Foobar::foo called at Caller.pl line 12.
这是怎么回事?我应该放弃任何使用Exporter
吗?但是如何跨模块链接功能呢?