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

I am trying to write a filter using Mail::Audit. It works 95% of the time but some mails cause the program to abort with Can't call method "_log" on an undefined value at /usr/opt/perl5/lib/site_perl/5.8.2/Mail/Audit.pm line 203 The senders get this as an undeliverable mail message. How can I debug it or, at least, stop the logging?

Replies are listed 'Best First'.
Re: How do I debug a .pm module
by chrestomanci (Priest) on Feb 11, 2011 at 10:16 UTC

    As ikegami hinted, if you are not using the latest version of Mail::Audit, then you should consider upgrading, though it would be an idea to read the changelog and bug reports to see if your problem has been fixed, or if anyone else is seeing the same problem.

    If the problem persits when you are on the latest version, then you need to figure out what set of curcumstances are triggering the problem. (Assuming you don't allready know). The way to do this is with logging. If I where in your sitution I would install Log::Log4perl, then make local coppies of the modules that you suspect, including your code that calls Mail::Audit. I would add lots of logging statements, so that when your mail program next aborts, you can trace back and figure out what caused it to break.

    Chances are once you find the set of curcumstances trigger the problem, you will do a facepalm because it will be something silly like passing in a hash ref to the cc list when you should have passed in an array ref.

    If it is not your bug, then you can either report the bug to the module author, or debug the module and fix the bug yourself. Presumably you know how to use the perl debugger?

Re: How do I debug a .pm module
by ikegami (Patriarch) on Feb 11, 2011 at 05:36 UTC
    What version of Mail::Audit are you using? That error means the following occurred: $undef->_log(...).
Re: How do I debug a .pm module
by locked_user sundialsvc4 (Abbot) on Feb 11, 2011 at 16:09 UTC

    My instincts tell me that this is probably a subtle error with your code, instead of Mail::Audit.   So, I would suggest that you start with this statement and trace it back to the method-calls in your software which lead up to that call.   Trace the variable (whose _log method is ultimately being called) back to its point of origin within your code.

    Since the problem occurs only rarely, it is most certainly “data-driven.”   That is to say, some subtle and rarely-occurring characteristic of the message itself.   I can’t predict what the software should be doing with these particular messages, but maybe it should not be logging them, or even processing them at all.   Every single one of the messages which are triggering this problem ought to have some characteristic that every single other one does not.   This is where your debugging efforts should begin.   As a rule of thumb, presume that the CPAN module does not contain an error, until you can demonstrate otherwise.   This will almost certainly prove to be the case.

      Thanks you for your responses. Yes, I have the newest module, Yes, the problem is data driven and no, it is not in my code which I reduced to one line (not to say that I could not have an error in a one liner - I did many times). It seams to be an error triggered by mail containing complex html code.