Hi all,

Richard Dice and I are writing a web application framework based on
CGI::Application.  As much as possible, we are trying to use existing
CGI::Application::Plugin::* modules, or to package up chunks of our
own framework into plugins of their own.

When it comes to Authentication and Authorization, we'd like to merge
the features from our framework with those in Cees's prototype CAP::Auth
plugin.

CAP::Auth requires a callback-enabled CGI::Application, and this hasn't
been released yet.

As I understand it, there are a couple of issues with the proposed
callback system that are holding up its release:

 * Plugins can't register callbacks to be run at the cgiapp_init phase

 * Plugins that are configured via class methods can't register
   callbacks at all (since $self doesn't exist yet when configuration
   takes place).

Back when Mark released the experimental version 4.0_1 with callbacks
enabled, Tony Fraser submitted a patch that seemed to solve both of
these problems.  I spent some time this weekend playing with his patch.

Basically, the patch provides a (very minimal) plugin base class called
CGI::Application::Plugin.  All C::A plugins can inherit from this class.
(They don't have to, but they should do so if they want to register
init callbacks.).

When a module calls:

    use CGI::Application::Plugin;

the module is automatically registered as a C::A plugin.
CGI::Application then calls the module's 'initialize' and
'add_callbacks' methods, giving the plugin an opportunity to register
callbacks and create new callback hooks.  Plugins registered in this way
can also register init callbacks.

One pleasant side effect of Tony's solution is that it also allows
classes unrelated to CGI::Application to register hooks using the same
mechanism.  For instance, database classes can arrange to set up their
tables during the CGI::Application init phase; the web application
doesn't need to know anything about the database classes or what they
do.  We use this approach in our framework.  It's a good separation of
model and controller, IMO.

Anyway, I've made some minor changes to Tony's patch and made a tarball
available here:

    
http://www.occamstoothbrush.com/downloads/perl/CGI-Application-4.0_2-plugin-patch.tgz

Changes:

  - patched against version 4.0_2
  - now safe for persistent environments (e.g. mod_perl):
    - any plugin can register itself
    - only plugins loaded by $self or superclasses of $self
      will be initialized at runtime
  - changed implementation to use a private hash instead of
    the symbol table for storage of registered plugins
  - the example script is called test-plugin.pl


I would appreciate feedback on this.  Does it seem like a reasonable
solution to the callbacks issues?

I know there are a lot of issues to sort through and everybody is short
on time.  If the C::A maintainers decide to go ahead with this solution,
I will be happy to write the docs and tests and to help prepare the
release.


Michael


-----------------------------------------------------------------------
Michael Graham <[EMAIL PROTECTED]>

YAPC::NA 2005 Toronto - http://www.yapc.org/America/ - [EMAIL PROTECTED]
-----------------------------------------------------------------------



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

Reply via email to