开发者

How to use %EXPORT_TAGS

I have a module something like this, in "lib", called Fool.pm, which is based on the source code of CGI.pm (since that was the first module I thought of when I was thinking about exporting tags):

package Fool;
require Exporter;
@ISA = qw(Exporter);开发者_如何学编程
@EXPORT_OK = qw/raspberry/;
%EXPORT_TAGS = (
    ':all' => \@EXPORT_OK,
);
1;

and a test script like this:

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

I try to run the script and get the following:

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.

I can't see what the mistake is here, can anyone help?


There shouldn't be a colon in your key. Also, I think the variables must be declared our in order to have it be available to Exporter:

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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜