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

Re: [cgiapp] Preview Release available with callbacks code integrated


On Mon, 20 Dec 2004 09:25:07 -0500, Jesse Erlbaum <suppressed> wrote:
> Hi Mark --
> 
> > I think I spent more time 'on the fence' about integrating callbacks
> > into the core than anyone. So I thought it would be worth
> > explaining my
> > thinking about accepting the patch now.
> 
> I took a look at the proposed docs, and I do have a question:
> 
> >  $self->add_callback('prerun', \&callback);
> >  $self->add_callback('teardown', \&callback, 'FIRST');
> 
> Why couldn't this same effect be accomplished via sub-classing and
> overriding functions, just like load_tmpl()?

The problem comes when two developers want to run two different things
at the same stage.  Using the sub-classing technique works fine when
working on a project by yourself, but we are trying to solve a problem
for people that want to distribute modules (or plugins) for others to
use.

If I write a module that needs to hook into the prerun phase, and I
use subclassing to handle this, then anyone that uses this module, and
also wants to use the prerun phase to do some processing will have to
add $self->SUPER::cgiapp_prerun() to their own prerun method, or else
things will start breaking.  That isn't very user friendly (at least
not for code released on CPAN)...

By allowing the module developer to register multiple functions at
each stage, we eliminate this problem.  CGI::App still works exactly
the same as always (ie you can still override cgiapp_prerun and it
will still work).  We just have the added feature of being able to
execute extra bits of code at any stage without needing to subclass,
and removing the risk that our method will be clobbered by another
sub-class.

I can come up with some example code if that would help...

Also, the other addition is the ability to create new stages in the
CGI::App processing pipeline.  The Template Toolkit plugin already
does something similar, by giving you a pre and post process hook that
executes everytime a template gets processed.

-- 
Cees Hek

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