|Syntactic Confectionery Delight|
Exceptions vs Context Objectsby eric256 (Parson)
|on Mar 31, 2006 at 04:36 UTC||Need Help??|
eric256 has asked for the wisdom of the Perl Monks concerning the following question:
I'm working on an extension of Module::Pluggable that builds in an Event/Trigger/Callback System. The event system allows all plugins to register for three slots of each event. I.e. calling the event "filter_html" will call it once for all plugins registered to handle it _before, once for _middle and once for _after. This seemed to give me some nice control and allow plugins to control exactly when they want to run. For instance if the plugin deals with cleaning up before the actual event then maybe it registers _before, while some might control the output and would therefore be after.
The Problem is that now sometimes a plugin might need to yell and say "stop processing other plugins at this level (before|middle|after)" and sometimes it might need to yell and say "hey we are dead in the water here so don't process any other plugins on this event." This is all fine and dandy so I set of with the idea to have magic return values. Immediatly this became a problem and had to be forgoten. So now i'm considering some alternatives. It would make sense if each plugin can edit the input and output, so that sounds like a context object, but i also want them to be able to abort which sounds like Exceptions.
The question then is....what do you think? I'm seeking some perl wisdom in this matter. I've never touched Exceptions and my experience with Context objects is that they are often a bit of extra code. Amy I missing something? Is this all a bad idea :) ? ... Thoughts, wisdom, guidance, stern yelling, and a swift paddle are all welcome.
Thanks in advance for any ideas.