It appears, however, that if a program use's a module and requests symbols from @EXPORT_OK, the symbols in @EXPORT are no longer implicitly imported -- they must be explicitly listed in the use statement.
Program 1 doesn't request anything in its use statement. Its call to "always_imported" compiles and executes correctly.package Foo; use v5.36; use Exporter 'import'; our @EXPORT = qw/always_imported/; our @EXPORT_OK = qw/optionally_imported/; sub always_imported { say "Always imported."; } sub optionally_imported { say "Optionally imported."; } 1;
Program 2 requests an optional symbol in @EXPORT_OK. Its call to "always_imported" no longer compiles, because the symbol wasn't imported.#!/usr/bin/env perl use v5.36; use Foo; always_imported; # works
I've noted the strong warnings against modules automatically exporting symbols, but I didn't run across anything that described the behavior I'm seeing. Is this working as designed?#!/usr/bin/env perl use v5.36; use Foo qw/optionally_imported/; always_imported; # bareword error ("always_imported" sub not defined)
In reply to Perl modules, Exporter, and @EXPORT vs. @EXPORT_OK by ibm1620
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |