Disable warnings from specific module

Discussion in 'Perl Misc' started by snunes@gmail.com, Feb 27, 2007.

  1. Guest

    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
    , Feb 27, 2007
    #1
    1. Advertising

  2. Paul Lalli Guest

    On Feb 27, 11:38 am, wrote:

    > 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
    Paul Lalli, Feb 27, 2007
    #2
    1. Advertising

  3. wrote:
    > 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
    Mark Clements, Feb 27, 2007
    #3
  4. On Feb 27, 11:52 am, "Paul Lalli" <> wrote:
    > On Feb 27, 11:38 am, 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 $!;
    ....

    --
    Charles DeRykus
    comp.llang.perl.moderated, Mar 2, 2007
    #4
  5. On Mar 1, 10:15 pm, "comp.llang.perl.moderated" <c...@blv-
    sam-01.ca.boeing.com> wrote:
    > On Feb 27, 11:52 am, "Paul Lalli" <> wrote:
    >
    >
    >
    > > On Feb 27, 11:38 am, 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 $!;
    > ...
    >


    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.

    --
    Chales DeRykus
    comp.llang.perl.moderated, Mar 2, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Maas, see http://tinyurl.com/uh3t

    How to disable stdio echoplex from java code (unix specific)?

    Robert Maas, see http://tinyurl.com/uh3t, Jun 7, 2005, in forum: Java
    Replies:
    0
    Views:
    392
    Robert Maas, see http://tinyurl.com/uh3t
    Jun 7, 2005
  2. Jason Heyes
    Replies:
    3
    Views:
    2,118
    Gene Wirchenko
    Dec 9, 2003
  3. Grant Edwards

    How do I disable warnings?

    Grant Edwards, Sep 10, 2007, in forum: Python
    Replies:
    2
    Views:
    1,591
    Grant Edwards
    Sep 10, 2007
  4. Asfand Yar Qazi
    Replies:
    1
    Views:
    149
    Florian Groß
    Mar 19, 2006
  5. Ted Sung
    Replies:
    1
    Views:
    307
    Sherm Pendley
    Aug 30, 2004
Loading...

Share This Page