in reply to I don't care about *your* warnings!

You can't disable a module's warnings if they were enabled using use warnings;.

If the module's warnings are enabled using -w or $^W, you can disable them using

{ local $^W = 0; call_other_module(); }

If you want others to be able to disable your warnings, you can do something like the following:

use if !$ENV{NOWARN}, 'warnings';

Note: The condition — !$ENV{NOWARN} in this case — is evaluated at the module's compile time, when its loaded.

( philcrow mentioned warnings::register as another means of letting others silence your warnings. )

Replies are listed 'Best First'.
Re^2: I don't care about *your* warnings! (register)
by tye (Sage) on Feb 28, 2007 at 20:32 UTC

    The docs on warnings aren't particularly clear on this point to me.

    It looks like warnings::register allows me to define a new class of warnings (with the same name as the module). But "uninit value" is already in a class so would disabling the "Contextual::Return" class of warnings disable "uninit value" warnings that come from the Contextual::Return package?

    It looks like it only works to disable warnings when the package goes out of its way to use things like warnings::warnif(...) and so I'm doubtful that it has any impact on the warnings being discussed here.

    Sorry, I don't have the time/motivation at the moment to construct test cases to answer this question myself (for my version of things, anyway); but I am interested in coming back later and reading more about this. (:

    - tye        

      I ran some tests, and warnif (and similar constructs) is the only thing affected.

      Update: Specifically,

      • no warnings 'OtherModule'; has no effect on builtin warnings.
      • use warnings 'OtherModule'; has no effect on builtin warnings.
      • use warnings 'OtherModule'; has no effect on warn warnings.
      • no warnings 'OtherModule'; has no effect on warn warnings.
      • use warnings 'OtherModule'; in the caller enables warnings::warnif warnings in the module.
      • no warnings 'OtherModule'; in the caller disables warnings::warnif warnings in the module.
      • use warnings 'OtherModule'; in the module has no effect.
      • no warnings 'OtherModule'; in the module has no effect.
      • use warnings; in the caller enables warnings::warnif warnings in the module.
      • no warnings; in the caller disables warnings::warnif warnings in the module.
      • use warnings; in the module has no effect on warnings::warnif warnings in the module.
      • no warnings; in the module has no effect on warnings::warnif warnings in the module.