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

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


Mark Stosberg <suppressed> wrote:

> On Mon, May 23, 2005 at 09:46:48PM -0400, Michael Graham wrote:
> >
> >     package My::Project;
> >
> >     My::Project->add_callback('init', \&my_project_init);
> >
> >     sub my_project_init {
> >         my $self = shift;
> >
> >         $self->new_hook('database_setup');  # just in case it's
> >                                             # not defined
> >
> >         $self->call_hook('database_setup');
> >     }
>
> Could you just call &my_project_init directly from cgiapp_init() for the
> same effect?
>
> Would the difference by that now you don't have to make a project a
> sub-class of 'My::Project', but just 'use' the module instead?

Yes, that's it exactly.

We are working on a framework based on CGI::Application.  At the moment
we've structured it so that our framework is a subclass of
CGI::Application, and the user's app will be a subclass of our
framework.

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.

> I guess part of what hooks provide is TIMTOWTDI. They let you think
> about how an application is structured and ordered in another way.

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.


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.