[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cgiapp] Re: positional plugin ordering


On 2005-06-23, Tony Fraser <suppressed> wrote:
> On Thu, 2005-06-23 at 08:49, Cees Hek wrote:
>> This brings me back to what I think would be the simplest (yet still
>> completely flexible) system that Michael Graham proposed way back
>> when, and that is to use a numbering system for the order.  This only
>> needs to be used by plugin authors that know that ordering is
>> important.  End users don't ever have to deal with it, unless they are
>> doing things that also require strict ordering.
>> 
>> __PACKAGE__->add_callback('postrun', \&my_callback, -300);
>> 
>> or for clarity if we moved to named parameters:
>> 
>> __PACKAGE__->add_callback(
>>       hook => 'postrun', 
>>       callback => \&my_callback, -300);
>>       order => -300,  # defaults to 0
>> );
>
> This also brings us back to the Apache2 module interface. Under Apache2
> the names (REALLY_FIRST, FIRST, MIDDLE, LAST, REALLY_LAST) are just
> #define's to numbers, (-10, 0, 10, 20, 30) in Apache2's case.
>
> Another thing to think about is Apache2's more advanced hooking feature:
> specifying the modules/Plugins that need to be before/after the hook
> being reistered. So something like:
>
> package CAP::HTMLTidy;
> use CGI::Application qw/:positions/;
>
> __PACKAGE__->add_callback(
> 	hook => 'postrun',
> 	callback => &tidy_html,
> 	position => DONTCARE, # really any number would work
> 	after => [ qw/CGI::Application/ ] # cgiapp_postrun()
> );
>
> -or-
> package CAP::Config;
> use CGI::Application qw/:positions/;
>
> __PACKAGE__->add_callback(
> 	hook => 'setup',
> 	callback => &read_config,
> 	position => FIRST,
> 	before => [ qw/CGI::Application CAP::DBH/ ]
> );
>
>> at 'call_hook' time we can gather all callbacks registered in all
>> packages in the inheritance tree, and order them by their specified
>> ordering number.
>
> This is the tough part, coming up with a stable sort algorithm that
> respects the position and the before and after constraints. I believe
> Apache2 goes through the list once resolving the before/after
> constraints then goes through the list again using the position to break
> ties.

I like some aspects of all three of these proposals (Michael Peters,
Cees and Tony). Let's discuss this some more in person in Toronto for
those of us who will be there and then see if we can come to a
consensus. 

At the moment I'm leaning towards favoring Tony's proposed design. I
like the "before/after" part, because often I think the relative
relationship is the most important. However, I might make the values
here other hook names rather than package names. On the other hand, Cees
comments about needing precise control in some cases have merits,
although I think code littered with lots of "magic numbers" can be hard
to understand. The Apache approach with words mapping to numbers does
give people the option to use an easier-to-read name if they can, or a 
precise number if they need to. 

Sometime still nags me that we ought be able to get by with something
simpler, though...

Thank you all for the thoughtful discussion!

   Mark 

-- 
http://mark.stosberg.com/ 


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.