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

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


On 5/25/05, Mark Stosberg <suppressed> wrote:
> To me, there is a trade-off hiding here:  Calling
> $self->SUPER::something makes for clearer, more explicit code.

But it is easy to forget if you didn't write the code that depends on
you calling SUPER.  I would agree that in your own private classes you
will have more control if you use the $self->SUPER:: method when
overriding the hooks, and skip using the callbacks.

But this completely breaks down when you use Plugins, since they are
implemented as a mixin, and hence don't use inheritance at all.  In a
plugin you can not export a cgiapp_prerun method, because you will
most likely clobber any existing cgiapp_prerun method that exists in
the class that is using the plugin.  This is where callbacks are
really useful.  It is also why callbacks are not that important to end
users, since they didn't have a problem that needed solving in the
first place.

> The callback system creates conveniences for the end-user, at the
> expense of possibly making debugging a little harder when you want to
> trace the flow of what's happening. (Since the activity of callbacks
> may not be immediately visible).

True.  Program flow may be a little more muddled if you don't know
what is happening, but that is one of the reasons I wrote the
LogDispatch plugin, which contains a feature that will log the
execution flow of your application.  It will log a message right
before every function is called (with the parameters being passed),
and log a second message when the function returns (with the return
value).  You can selectively turn on specific modules that you want
traced so that it doesn't trace into DBI or other big support modules.
 Here is a quick example:

$self->log_config(
          LOG_DISPATCH_MODULES => [
            {        module => 'Log::Dispatch::Screen',
                       name => 'screen',
                     stderr => 1,
                  min_level => 'debug',
             append_newline => 1
            }
          ],
          LOG_METHOD_EXECUTION => [qw(__PACKAGE__ CGI::Application CGI)],
);

This will log all function calls in the current package, CGIApp and
CGI.pm.  You can add as many modules to that list as you like,
including any of the plugins.

I haven't tested this with the callbacks support, but it should work
just the same.  The only thing that I am not sure about is how it will
react to anonymous subroutines.  My guess is that it will not see
them.

Cheers,

Cees

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