ibm1620 has asked for the wisdom of the Perl Monks concerning the following question:
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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl modules, Exporter, and @EXPORT vs. @EXPORT_OK
by choroba (Cardinal) on Jul 23, 2022 at 23:44 UTC | |
by LanX (Saint) on Jul 23, 2022 at 23:59 UTC | |
by ibm1620 (Hermit) on Jul 24, 2022 at 03:07 UTC | |
|
Re: Perl modules, Exporter, and @EXPORT vs. @EXPORT_OK
by ikegami (Patriarch) on Jul 24, 2022 at 20:37 UTC |