For a recent post (Solve IO::Pty warning issues from Net::OpenSSH) I tried to create a new category for warnings for a module and then disable it but it failed (perl 5.34.0) when I used it as *I expected*:
{ package XXX; use strict; # register a new warnings category with this package name use warnings::register; sub expected { warn "ajajaj"; } sub correct { if( warnings::enabled() ){ warn "ajajaj"; } else { print "not warning!\n" } } 1; } # it's already loaded... #use XXX; no warnings('XXX'); # this says 'no' (as expected) print "enabled: ".(warnings::enabled('XXX')?"yes":"no")."\n"; XXX::expected(); # this still warns XXX::correct(); # this does not warn
Firstly, correct me if I am doing something wrong.
Secondly, am I expecting too much to just register a category within a module and then anyone from outside it, to enable or disable it? Why the check to warnings::enabled() in each and every warn() statement of that module. That makes refactoring to using warning categories very difficult.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |