in reply to Re: Perl modules, Exporter, and @EXPORT vs. @EXPORT_OK
in thread Perl modules, Exporter, and @EXPORT vs. @EXPORT_OK

I think it's even clearer seen with the two points before, emphasize added

  1. use YourModule;

    This imports all the symbols from YourModule's @EXPORT into the namespace of the use statement.

  2. use YourModule ();

    This causes perl to load your module but does not import any symbols.

  3. use YourModule qw(...);

    This imports only the symbols listed by the caller into their namespace. All listed symbols must be in your @EXPORT or @EXPORT_OK, else an error occurs.

it would be inconsistent with case two with an empty list, if auto-imports were allowed in the third case.

edit

but I agree with the ibm1620 that always_imported is misleading. something like default_imported would be better.

Probably worth a doc patch.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^3: Perl modules, Exporter, and @EXPORT vs. @EXPORT_OK
by ibm1620 (Hermit) on Jul 24, 2022 at 03:07 UTC
    I agree, a phrase like "default import" or "default list of symbols" would help to clarify it, as would stating that the default list is used when -- or only if -- no explicit list is supplied on the 'use' statement. That would help make the point that the word "default" refers to a list, rather than to the entities in the list, if that distinction makes any sense to anyone else :-).

    I think it's unfortunate that the arrays are named EXPORT and EXPORT_OK, since to me that suggested a "mandatory/optional" relationship.

    Thanks for the explanation.