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

Hey, this is a wierd problem and I really haven't been able to figure out why it's happening, so maybe some of you monks can help!

I've implemented a module that happens to have a __WARN__ signal handler (let's call it TheLoader) and a universal autoloader:
package TheLoader; BEGIN { $SIG{__WARN__} = sub { return if $_[0] =~ /inherited AUTOLOAD/; print STDERR @_; }; } package UNIVERSAL sub AUTOLOAD { ... }
All of my other modules use this package. I also have a few .cgi files that just use the modules they need (they don't use TheLoader directly, but they all use at least one module that uses TheLoader)

When I load up a .cgi file through the web server (apache), I end up getting the warnings I'm trying to suppress.
Use of inherited AUTOLOAD for non-method Foo::Bar::getSomething() is d +eprecated at ....Test.pm line 200 (#1) ....
I would have thought that my signal handler for __WARN__ would have handled this signal correctly. I've seen it suppress other warnings from running my tests, but with this setup it's not.

Anyone have clues? Many thanks.

Replies are listed 'Best First'.
Re: handling __WARN__ funkiness
by cazz (Pilgrim) on Oct 07, 2005 at 20:49 UTC
    I'm willing to bet your signal handler is being overwritten by someone else. To find out what is stomping on your __WARN__ handler, tie the signal handler hash to a simple Tie::StdHash with a bit of reporting to see where else people are changing $SIG{__WARN__}.

    Here is my solutino that will find you where your __WARN__ handle is getting overwritten.

      Thanks cazz, using tie I was able to "hijack" the other people setting up a __WARN__ signal handler, and verify that the message wasn't the deprecation message before calling theirs. Works like a champ!
Re: handling __WARN__ funkiness
by japhy (Canon) on Oct 07, 2005 at 19:47 UTC
    The code works fine for me (5.8.4). What version of Perl do you have?

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
      5.8.3 Note that I'm running the cgi script through a webserver, when I try to do some test scripts just from the command line it works just fine...