如何使用%EXPORT_TAGS

时间:2010-07-05 03:27:47

标签: perl

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

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.

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

1 个答案:

答案 0 :(得分:1)

你的密钥中不应该有冒号。另外,我认为变量必须声明为our才能让Exporter可用:

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

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