Well, my thinking was that since I've used warnings::register in my modules and warnings::warnif to create custom warnings, and that function is sensitive to FATAL warnings, I thought it'd be sensitive to no warnings as well, since AFAIK warn just unconditionally warns (and AFAIK the only way to catch it is with %SIG). And it does indeed work, but unfortunately it seems that it only works across package boundaries, I'm not entirely sure yet why, but from a quick look at the source it seems to be because it uses (parts of) Carp under the hood, looking up the call stack.

use warnings; use strict; { package Foo; use warnings::register; sub bar { warnings::warnif("bar: $_[0]"); } } { no warnings; Foo::bar("inside"); } Foo::bar("outside"); use warnings::register; use Carp; { no warnings; warn "warn"; warnings::warn("warnings::warn"); carp "carp"; warnings::warnif("inside 2"); } warnings::warnif("outside 2"); __END__ bar: outside at w.pl line 17. warn at w.pl line 23. warnings::warn at w.pl line 24. carp at w.pl line 25.

So at the moment my only two suggestions are to either go across package boundaries like I did in the above, or write your own debug function, which I tend to do. Just one example from here:

sub _debug { my ($self, $lvl, @out) = @_; return if $self->{debug}<$lvl || !@out; print STDERR __PACKAGE__, " DEBUG: ", @out, "\n"; } # ... $self->_debug(2, ...);

In reply to Re^2: Using 'no warnings' to disable own debug warn(ing)s? by haukex
in thread Using 'no warnings' to disable own debug warn(ing)s? by LanX

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.