Should Perl introduce a language-level private attribute for subroutines?
0 reputation · 30 Nov 2022, 15:22 UTC
Goal: Prevent unintended public access to helper subroutines in Perl packages while preserving the ability for developers to expose intended APIs.
Currently, all globally declared subroutines appear in a package's symbol table and can be called via their fully qualified name, even if they are not listed in @EXPORT or @EXPORT_OK. Developers rely on naming conventions (leading underscore) or lexical closures to signal privacy, but these conventions are not enforced, leaving APIs fragile.
The Perl community has discussed adding a language-level private attribute or similar mechanism to enforce encapsulation, but no consensus exists on its design, impact on existing code, or interaction with tools like Exporter and Devel::Symdump.
What syntax and semantics should a private attribute have? How would it interact with Exporter's @EXPORT and @EXPORT_OK lists and existing symbol‑table introspection? What migration strategy would allow CPAN modules to adopt the feature without breaking backward compatibility?