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

Re: [cgiapp] Re: positional plugin ordering


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.

Something else to think about: Apache2 only allows registering callbacks
at startup time. Once it has built the ordered list it hangs on to the
list and reuses it each time it has to call the hook. This wouldn't
really be a big deal under CGI but under PersistentPerl or mod_perl it's
something to think about.

> What this doesn't solve is the issue where a plugin needs to do
> something different based on whether another plugin is being used or
> not.  ie the DBH plugin may look to a configuration plugin for
> database info, but only if it is in use.  But I think that is a
> separate issue and is only loosely related to callback ordering.

I think this type of problem is best solved with $self->can(...) isn't
it?

-- 
Tony Fraser
suppressed
Sybaspace Internet Solutions                        System Administrator
phone: (250) 246-5368                                fax: (250) 246-5398


---------------------------------------------------------------------
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.