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

Re: [cgiapp] Re: Yet another callback system proposal


Hi Mark,

Thanks for looking into this!

> > I have also changed the position scheme.  Instead of limiting the
> > positions to 'REALLY_FIRST', 'FIRST', 'MIDDLE', 'LAST', and
> > 'REALLY_LAST', you can now specify a numeric position between 0 and 100.

...

> I don't like this idea. The position seems already seems a little
> over-engineered and muddled. "First" isn't really first, because there's
> "really first". Now you are proposing that "really first" isn't really
> first either, there are 5 positions before it.

Well, I was pretty conservative (read: timid) in my numbering.  We could
obviously change it to:

    FIRST         => 1
    MIDDLE        => 50
    DONTCARE      => 50
    LAST          => 100

Then the names don't lie, and people can use the numbers if they
really need precise control.

> I think "really first" should be "really first" (there should be only
> one possible occupant for this position or it's an error).
>
> I think five positions should be sufficient to start with, and a finer
> grained layer can be added later if the need is proven.

I think it's actually pretty common to want two or three things to go
REALLY_FIRST, but to need them all to start in a precise order.

For instance consider the case where you want to send your debug
messages to a database table.  You need to get your plugins to
initialize themselves in this order:

  * configuration (config file holds the db username/password)
  * database (needed as log target)
  * log

> If the plugin loading becomes complex, it probably won't be numeric
> slots that will be most helpful, but being able to express something in
> terms a human could actually understand, like "this needs to be loaded
> after the database handle is available".

I was thinking about exactly this sort of thing!  If this approach is
not considered to be too complex, I'm willing to take a stab at it.

I guess the question is how to express the dependencies?  For instance,
how does a plugin request a callback "after the configuration module has
loaded"?

We could do:

   $caller->add_callback('init', 'my_setup', {
       'DEPENDS_ON' => 'CGI::Application::Plugin::ConfigMumble',
   });

But the obvious problem here is that there are at least three CAP config
modules out there, so how does the plugin say "after whatever
configuration plugin the user happens to prefer"?

Or does each plugin indicate its "provides" and "requires" properties
when it requests the callback?  Something like:

   $caller->add_callback('init', 'my_setup', {
       'POSITION' => 'FIRST',
       'PROVIDES' => [ 'log' ],
       'REQUIRES' => [ 'config', 'database' ],
   });

That could work.  We could even make it so that a module automatically
'provides' its own package name, so that plugins can explicitly require
a specific plugin by name if they need to do that.


Michael


-----------------------------------------------------------------------
Michael Graham <suppressed>

YAPC::NA 2005 Toronto - http://www.yapc.org/America/ - suppressed
-----------------------------------------------------------------------


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