[Catalyst] running a function once on all requests
John Napiorkowski
jjn1056 at yahoo.com
Mon Jun 4 19:07:10 GMT 2007
--- Steve Francia <steve at takkle.com> wrote:
> I have a routine I would like to run once for each
> request.
>
> After reading through the docs, I think I have found
> a good approach and
> am wondering what others have done.
>
> I created a base controller which uses base
> 'Catalyst::Controller' .
> Inside the base controller I create a begin
> function:
>
> sub begin : Private {
> my ( $self, $c ) = @_;
>
> $c->stash->{ controller } = $c->namespace;
> }
>
> In all my other controllers I use this base class.
>
> If I want to add a controller specific begin routine
> to a controller I
> place the following in that controller class:
>
> sub begin : Private {
> my ( $self, $c ) = @_;
>
> $self->SUPER::begin($c);
> # CONTROLLER SPECIFIC LOGIC HERE
> }
>
>
> Anyone know of any good reason to do it differently,
> or has anyone used
> other strategies in the past?
>
> Thanks,
> Steve Francia
I think begin actions where created for exactly this
reason. The only thing I do differently is to use
NEXT or C3 instead of SUPER.
--john
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Catalyst
mailing list