我在“ lib”中有一个类似这样的模块,称为Fool.pm,它基于the source code of CGI.pm(因为这是我在考虑导出标签时想到的第一个模块):

package Fool;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw/raspberry/;
%EXPORT_TAGS = (
    ':all' => \@EXPORT_OK,
);
1;


和这样的测试脚本:

use lib 'lib';
use Fool qw/:all/;


我尝试运行脚本并获得以下信息:


perl fool.pl
"all" is not defined in %Fool::EXPORT_TAGS at fool.pl line 2
  main::BEGIN() called at lib/Fool.pm line 2
  eval {...} called at lib/Fool.pm line 2
Can't continue after import errors at fool.pl line 2
BEGIN failed--compilation aborted at fool.pl line 2.



我看不出这里出了什么错误,有人可以帮忙吗?

最佳答案

您的密钥中不应包含冒号。另外,我认为必须将变量声明为our以便对Exporter可用:

our @ISA = qw(Exporter);
our @EXPORT_OK = qw/raspberry/;

our %EXPORT_TAGS = (
    'all' => \@EXPORT_OK,
);

08-28 07:55