How to use% EXPORT_TAGS

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

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

and a test script as follows:

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

I am trying to run a 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 don’t see what mistake is here, can anyone help?

+3
source share
1 answer

There should be no colon in your key. In addition, I think that variables should be declared ourso that they are available for Exporter:

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

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

Source: https://habr.com/ru/post/1753103/


All Articles