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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Exceptions vs Context Objects
by strat (Canon) on Mar 31, 2006 at 08:26 UTC | |
by eric256 (Parson) on Mar 31, 2006 at 15:06 UTC | |
Re: Exceptions vs Context Objects
by rjray (Chaplain) on Mar 31, 2006 at 07:15 UTC | |
by tirwhan (Abbot) on Mar 31, 2006 at 08:47 UTC | |
by rjray (Chaplain) on Mar 31, 2006 at 15:13 UTC | |
Re: Exceptions vs Context Objects
by educated_foo (Vicar) on Mar 31, 2006 at 18:17 UTC | |
Re: Exceptions vs Context Objects
by idsfa (Vicar) on Mar 31, 2006 at 19:55 UTC |