Custom warning categories remain global despite lexical use warnings
0 reputation · 26 Feb 2021, 06:43 UTC
Problem context
The Perl warnings pragma allows selective enabling of warning categories and an experimental debug flag that prints stack traces. A documented way to add new categories is warnings::register, which registers them globally. When use warnings is invoked inside a lexical block, only the built‑in categories listed there are affected, but custom categories continue to emit warnings regardless of that lexical scope.
Unresolved decision
Perl’s documentation does not clarify whether custom categories should inherit the lexical scoping of use warnings or remain globally visible. This ambiguity can lead to noisy output in large codebases where a module defines a custom warning that is unintentionally propagated to unrelated parts of the program.
Key questions
- Should a custom warning category defined with
warnings::registerbe lexically scoped to the block whereuse warningsis declared? - Will the experimental
warnings::debugflag remain stable in future Perl releases, or is it likely to be deprecated or altered? - What mitigation strategies can developers adopt to control noise from globally registered custom warnings without sacrificing diagnostic detail?