Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: I don't care about *your* warnings!

by philcrow (Priest)
on Feb 28, 2007 at 19:50 UTC ( [id://602575]=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://602575]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-25 11:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found