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

[cgiapp] Re: Yet another callback system proposal


On 2005-05-24, Michael Graham <suppressed> wrote:
>
> But this means that when users want their own cgiapp_prerun,
> cgiapp_init, etc. they have to be careful always to call
> $self->SUPER::cgiapp_prerun and $self->SUPER::cgiapp_init etc.
>
> We could have also made our own framework_init, and framework_prerun
> methods, but the user would have to remember to call these at the
> appropriate times.
>
> It's basically the same inconvenience that some plugins have.  It is
> very nicely solved by the callback system.

To me, there is a trade-off hiding here:  Calling
$self->SUPER::something makes for clearer, more explicit code.

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

> Very true.  In our case, avoiding the inheritance/delegation issues is
> really a convenience and a side benefit.  The real gain is the ability
> decouple the database classes from the controller classes.  The
> controller calls $self->call_hook('database_setup'), but it doesn't need
> to know anything about the database classes or how they work.
>
> That's a huge benefit, because it means that we don't have to force
> users of our framework to use any particular database system.  We
> recommend Class::DBI, but they could use SPOPS or Alzabo or plain DBI, or
> nothing at all.

It seems like just another way to agree on the interface. With callbacks,
one side agrees to call a hook and the other side agrees to register
with the hook, so some glue is still needed.

It seems like mix-ins could work just as well, when you have this in the
controller:

$self->database_setup();

And then a glue plugin creates this method and calls the backend of
choice.

Callbacks really shine in an even more complex case, where you can
replace: 

 $self->setup_for_plugin_1();
 $self->setup_for_plugin_2();

With just: 

 $self->call_hook('setup')

... or nothing at all, because the plugin setup return is hooked into 
one of the built-in hooks.

    Mark

--
 . . . . . . . . . . . . . . . . . . . . . . . . . . . 
   Mark Stosberg            Principal Developer  
   suppressed     Summersault, LLC     
   765-939-9301 ext 202     database driven websites
 . . . . . http://www.summersault.com/ . . . . . . . .


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