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

Update: Sorry for my previous wrong answer. I was thinking about some code of mine that uses warnings::register. Then the caller can turn off its warnings:
{ no warnings qw( PackageName ); PackageName::subname(...); }
Of course, that requires more cooperation from the used module than the OP has.

Phil

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

    No, that's wrong. The warnings pragma is lexically (statically) scoped, not dynamically scoped.

    { package OtherModule; use warnings; sub routine { my $n = 0; my $i = $n + "a"; } } { no warnings; OtherModule->routine(); }
    Argument "a" isn't numeric in addition (+) at 602580.pl line 4.

    And unfortunately, use warnings; (and no warnings;) overrides $^W.

    { package OtherModule; use warnings; sub routine { my $n = 0; my $i = $n + "a"; } } { local $^W = 0; OtherModule->routine(); }
    Argument "a" isn't numeric in addition (+) at 602580.pl line 4.

    Update: The warnings was initially a compile-time warning. Fixed it to be a run-time warning.

Re^2: I don't care about *your* warnings!
by dave_the_m (Monsignor) on Feb 28, 2007 at 20:11 UTC
    If the other module has 'use warnings;', you should be able to suppress its warnings with a block like this
    No you shouldn't. The 'warnings' pragma's effect is lexically scoped, not dynamically scoped.

    Dave.

Re^2: I don't care about *your* warnings!
by agianni (Hermit) on Feb 28, 2007 at 20:00 UTC

    That's actually the first thing I tried. I'm having trouble overriding Test::Class methods when I sub-class (I'm still working on that problem) but even if I localize the module and modify it to put the call in a block with warnings turned off, it still emits warnings. That method still doesn't work even in this simplified example:

    { no warnings; Foo->bar(); } package Foo; use warnings; sub bar{ print $baz }

    Or am I doing something wrong here?