[Catalyst] Making a hash available across the application

Ido Perlmuter ido at ido50.net
Wed Mar 17 17:54:35 GMT 2010

Catalyst applications are Perl applications just like anyone else. If you
want to access a hash variable (or any variable) which is declared (and
possibly defined) in MyApp.pm (or any module for that matter), then all you
need to do is refer to that variable from external sources (like templates)
by its full name. So, for example, if the name of your variable is %HASH,
then you can access it from your templates as %MyApp::HASH.

As a matter of fact, if when declaring the %HASH variable in MyApp.pm you do
so by its full name, i.e. %MyApp::HASH, you don't even have to use "my
%HASH" but just "%MyApp::HASH". Not that it's any better, but anyway...


On Wed, Mar 17, 2010 at 7:43 PM, Dermot <paikkos at googlemail.com> wrote:

> Hi,
> I'm sure there is a way but it's not jumping out at me.
> I have a list of countries and their associated database ID's that I
> need to stash in the header of (almost) every page on a site. I have
> no problems creating a controller that can do
> $c->model(DB::Countries)->search({foo=3D>1}) and stick that into a
> $c->stash but I don't want to make repeated DB calls. I'd like to
> create a hash at startup and make it available to
> root/lib/site/header. Is it possible to create a hash within
> lib/MyApp.pm that will be available throughout and how would my
> templates access it?
> TIA,
> Dp.
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100317/e4e2f=

More information about the Catalyst mailing list