dragonchild has asked for the wisdom of the Perl Monks concerning the following question:

In Excel::Template, I'm trying to make some of the warnings I emit only happen if $^W is true. However, in my tests, it's being set to true whether or not I'm setting it in my .t files.

So, I went looking and found that 5.8.5's File::Basename has use warnings; in it. *blinks* Two questions:

  1. I thought that use warnings; in one module won't trigger warnings in that file that module was use'd in. Is that true?
  2. If File::Basename isn't the culprit, how can I find out where $^W is being set to true?

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re: Who is turning $^W on?
by demerphq (Chancellor) on Nov 08, 2004 at 16:19 UTC
    $|++; package Foo; { use strict; use warnings; use warnings::register; sub t { warnings::warnif "Bang! '@_'"; print ": @_\n"; } } package main; { no warnings; Foo::t('no warnings'); } { use warnings; Foo::t('use warnings'); } { use warnings; no warnings 'Foo'; Foo::t('no warnings "Foo"'); } { no warnings; use warnings 'Foo'; Foo::t('use warnings "Foo"'); } __END__ : no warnings Bang! 'use warnings' at C:\Temp\warnings_register.pl line 23 : use warnings : no warnings "Foo" Bang! 'use warnings "Foo"' at C:\Temp\warnings_register.pl line 33 : use warnings "Foo"
    ---
    demerphq

Re: Who is turning $^W on?
by itub (Priest) on Nov 08, 2004 at 15:57 UTC
    Test::Harness calls the tests with the -w option. I think it didn't do that in older versions (well, on further checking it seems like it did).
      Gods, that's deep into the Makefile. How do I turn it off, either globally or locally to a given test?

      Being right, does not endow the right to be rude; politeness costs nothing.
      Being unknowing, is not the same as being stupid.
      Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
      Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

        While not very pretty, this seems to work when added at the top of the test file:

        BEGIN { $^W = 0 }

        Test::Harness lets you add command-line switches by setting the HARNESS_PERL_SWITCHES environment variable. But that doesn't work for removing the warnings, because it is just added to the existing switches.

Re: Who is turning $^W on?
by Aighearach (Initiate) on Nov 08, 2004 at 16:02 UTC
    If you take a look at perldoc perllexwarn you'll find that the warnings pragma is not exactly the same as setting $^W. In particular, the pragma is scoped to the enclosing block. So if $^W is getting set, you can be pretty sure that you need to search for an actual $^W assignment, and not a use warnings pragma.

    You could use the perl debugger to find the offender. Or just grep your files and modules you use for $^W.

    Also note that, if you don't need pre-5.6.0 compatability, then look at perldoc warnings and in particular warnings::register() which provides a good way of turning on and off your own warnings, giving finer control to the user of your module.


    --
    Snazzy tagline here