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

See "How to Import" in Exporter:

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. The advanced export features of Exporter are accessed like this, but with list entries that are syntactically distinct from symbol names.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Perl modules, Exporter, and @EXPORT vs. @EXPORT_OK
by LanX (Saint) on Jul 23, 2022 at 23:59 UTC
    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

      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.