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.


In reply to Control warnings for each module by creating new warning categories by bliako

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.