Disable warnings from specific module

S

snunes

Hi,

I'm using a module with a couple of experimental features (SOAP::Lite)
and, every time these features are used, a warning message is
outputted. I would like to know how can I simply disable these outputs
while keeping warnings for my code?

use strict;
use warnings;

use SOAP::Lite;

[...]

Thanks in advance,
Sérgio Nunes
 
P

Paul Lalli

I'm using a module with a couple of experimental features
(SOAP::Lite) and, every time these features are used, a warning
message is outputted. I would like to know how can I simply
disable these outputs while keeping warnings for my code?

You could try wrapping a call to any of those experimental features in
a block in which $SIG{__WARN__} has been changed to ignore warnings.
Or you could try locally setting $^W to 0 in a block around those
features (though I don't think that would handle the case where the
module's code is specifically generating a warning using the warn()
function).

{
local $SIG{__WARN__} = sub { 1 };
do_something_experimental();
}

Hope that helps,
Paul Lalli
 
M

Mark Clements

Hi,

I'm using a module with a couple of experimental features (SOAP::Lite)
and, every time these features are used, a warning message is
outputted. I would like to know how can I simply disable these outputs
while keeping warnings for my code?

use strict;
use warnings;

use SOAP::Lite;

I would have expected this to have worked:

mark@owl:~$ cat AA.pm
package AA;

use strict;
use warnings;

sub testsub {
my $test;
print "$test\n";

}

1;
mark@owl:~$ cat testaa.pl
use strict;
use warnings;

use AA;

{
package AA;
use warnings::register;
}
no warnings q(AA);

AA::testsub();
mark@owl:~$ perl testaa.pl
Use of uninitialized value in concatenation (.) or string at AA.pm line 8.

but it doesn't surpress the warning message, although adding

use warnings::register;

to AA.pm has the desired effect.

Mark
 
C

comp.llang.perl.moderated

On Feb 27, 11:38 am, (e-mail address removed) wrote:

....

You could try wrapping a call to any of those experimental features in
a block in which $SIG{__WARN__} has been changed to ignore warnings.
Or you could try locally setting $^W to 0 in a block around those
features (though I don't think that would handle the case where the
module's code is specifically generating a warning using the warn()
function).

{
local $SIG{__WARN__} = sub { 1 };
do_something_experimental();

}

Ugly but you could filter stderr entirely...
I think:


open( SAVE, '>&STDERR') or die $!;
{ open(STDERR, '>', File::Spec->devnull);
do_something_experimental();
}
open( STDERR, '>&SAVE' ) or die $!;
....
 
C

comp.llang.perl.moderated

Ugly but you could filter stderr entirely...
I think:

open( SAVE, '>&STDERR') or die $!;
{ open(STDERR, '>', File::Spec->devnull);
do_something_experimental();}

open( STDERR, '>&SAVE' ) or die $!;
...

Sorry, my suggestion is really dumb the more I think about it.. You
might lose a fatal message from SOAP::Lite for instance. I'm not
sure why setting SIG{__WARN__} or even $^W locally wouldn't do
what's needed. The 'warnings' pragma would be better than the
global $^W however. A 'no warnings "blah.." for example could just
filter out the specific nuisance warning(s) whiile leaving other
unexpected errors intact. perldoc warnings.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top