|Syntactic Confectionery Delight|
Re: Defensive Programming and Audit Trailsby trs80 (Priest)
|on Aug 06, 2002 at 15:37 UTC||Need Help??|
Under mod_perl when working with external modules and most templating/frameworks I have found code similar to this helpful:
So if your _debug method is toggled on this comment would get logged:
If you don't "advertise"* the _debug method or you are doing a minor debug you could simply call it with:
The '1' simply forces the error message to be written.
There are many more robust solutions available, but I have found this method to be very useful and allows me control over the error logging process. Since it is abstracted(?) enough I can make changes to the logging method without recoding other sections of the application.
So you don't want OO?
Then you call it like any other sub:
* In Perl it is not as common to make a method completely private, as it may be in languages like Java. In most cases they are still acessible if you know they exist, that is why I prefer the "advertise" verbiage. Ways to make a method private can be found in other nodes, but I didn't bother to look them up because this node is about logging not private vs. public methods.