[Dancer-users] Using shared variables

David Precious davidp at preshweb.co.uk
Tue Jan 24 20:22:03 CET 2012

On Wed, 25 Jan 2012 00:37:12 +0530
Gurunandan Bhat <gbhat at pobox.com> wrote:

> Hi,
> I was wondering about the issues using a shared variable in a single
> App.pm file. Here is what I mean:
> I first call Route1 then when I call Route 2, I expect that I will
> have the modified value (by Route 1) of $var in route 2.
> Unfortunately I get an undefined value for $var.

That's a bad idea because, if you're running in anything other than
standalone mode, the process which receives the second request is not
necessarily the same one which handled the first request.

You should use the 'vars' keyword if you need to share stuff between a
single request, and use sessions (or e.g. memcached) to maintain state
between requests.

Even if you're only planning to run a standalone single-process app
now, this design choice would likely bite you in the ass later, when
you find you want to run under Starman or similar for performance.

More information about the Dancer-users mailing list