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

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


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

In the case of our framework, I'm mostly worried about people one day
deciding to add a cgiapp_prerun method to their application and then
spending an hour wondering why the whole framework suddenly broke.

I guess the safe thing to do (in a callback-free world) would be to
include the following code in every example app:

    sub cgiapp_prerun {
        my $self = shift;

        # leave this line alone!
        $self->SUPER::cgiapp_prerun;

        # ... add your own pre-run code here ...

    }


Anyway, as much as possible we're trying to make the architecture of the
framework transparent and let people write normal CGI::Application
programs (including cgiapp_init, cgiapp_prerun, etc.) without
interference.  Obviously they have to be aware that framework stuff is
going on at the various phases, but the mechanics shouldn't get in their
way.

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

Interesting - that's a pretty clean solution!  I'll give that a try.

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

Yeah - and this is especially useful for Class::DBI because you
typically have many table classes (e.g. My::CDBI::User, My::CDBI::Book,
My::CDBI::Anvil...), that each wants to be initialized.


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.