[Catalyst] Catalyst global object

Scott M Parrish anithri at gmail.com
Wed Jul 13 13:45:20 CEST 2005

On 7/13/05, Marcus Ramberg <marcus at thefeed.no> wrote:
> luke saunders skrev:
> > My application is called Holiday, the skeleton of which was created
> > with the create.pl script. It uses the controller Page and CDBI::Sweet
> > for the DB stuff. In Holiday.pm I create a new Handler object which is
> > needed for the Holiday system to work properly. Now I need this
> > Handler object to be available globally (to the controller and models)
> > and therefore it would be ideal if I could put it in the catalyst
> > Context object somewhere as that's available everywhere. Is there
> > anywhere I can put it in the Context object? If not how could I make
> > this Handler object available to the objects instantiated by Catalyst?
> Hey Luke.
> Why don't you just put it in the stash?
> $c->stash->{handler} = MyHandler->new(); in begin or whatnot?
> then it'll be available from all your classes as $c->stash->{handler},
> and just handler in your templates. you say you need this available in
> models as well. Models usually don't have access to context, but you can
> use the Catalyst::Plugin::Singleton to get a context from anywhere.
If this object only needs to be created once per server as opposed to
once per request, than putting it into $c->config might be easier.  I
added a how-to on this at
http://dev.catalyst.perl.org/wiki/DynamicConfiguration that way you
still have the information but don't have to perform any expensive Io
or processing time *every* request cycle


More information about the Catalyst mailing list