[Catalyst] MyApp::C::PageHooks - thoughts ?

Wade.Stuart at fallon.com Wade.Stuart at fallon.com
Mon Oct 29 20:52:53 GMT 2007



Matthew Pitts <mpitts at a3its.com> wrote on 10/29/2007 03:24:10 PM:

> I wanted to get some thoughts on something a little different that I'm
> doing...
>
> What I want to to have is Controllers that are temporary (i.e. date
> sensitive) that represent a particular "promotion" that's running on a
> site. This promotion may need to affect different areas of the site, but
> I don't want to have $c->forward calls like the following everywhere
> that I need the Promo's code to inject stash data.
>
> $c->forward('Controller::Promos::Foo', 'some_action')
>
> So, I decided to do a form of "hooks" within my app so that any given
> controller can affect the stash for a defined set of hooks.
>
> Below is the first run of my code to implement this. Basically, I
> override Controller->register_actions and run through all the
> controllers looking for C->config->{pagehooks} and build a local hashref
> containing the hook definitions.
>
> Then, in all the places throughout the app that are defined as
> "hookable" I just do a:
>
> $c->forward('Controller::PageHooks', 'run_hook', 'hook_name', [ 'arg1',
> 'arg2' ]);
>
> and it "just works".
>
> The main advantage with is that I can remove the promo's controller and
> don't need to change any other controllers. I can even get my design
> guys to code their templates in such a way that when the promo expires,
> every place on the site affected by the promo magically goes back to
> pre-promo look-and-feel.
>
> Any thoughts on my level of sanity here?

Why not just store promos in the database and have a static controller that
acts on active promos?  No changing application code for the promo.  easy
to do future promos too as you can have an epoch start and end time for the
promo in the db tables that the controller takes into account.





More information about the Catalyst mailing list