[Catalyst] Catalyst global object

luke saunders luke.saunders at gmail.com
Wed Jul 13 13:58:14 CEST 2005


Hey Scott,

The objects I was talking about were all to be created only once per
server so I'll chuck them in the config as you suggest. Thanks.

For reference, if there's an object I need to create at the start of
every request, is there a method I can create in MyApp.pm which will
get called at the start of every request? the opposite of end
basically, probably called something like sub start : private {} .

Thanks for your help guys. Sorry to be vague but I guess I wasn't
quite clear on what I was asking for before.

Cheers,
Luke.

On 7/13/05, Scott M Parrish <anithri at gmail.com> 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