A 'state' variable lasts for the rest of that process, but is only available to the scope it's declared in. If you want per-connection (or more precisely per request), I recommend storing it in the stash, like:
helper foo => sub { my $c = shift; return $c->stash->{'myapp.foo'} //= ...; }; -Dan On Mon, Nov 19, 2018 at 8:18 PM Viktor Nacht <viktor.na...@gmail.com> wrote: > Does using state inside a helper last for the duration of the connection, > or something longer lasting like a process, worker, etc? > > I want to create (and return) a current DateTime object and make it > accessible to multiple helpers and templates during a connection. > > I saw this Gist, but I'm not sure it pertains to per-connection: > > https://gist.github.com/s1037989/179d53b86e46ae788f62 > > V > > -- > You received this message because you are subscribed to the Google Groups > "Mojolicious" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to mojolicious+unsubscr...@googlegroups.com. > To post to this group, send email to mojolicious@googlegroups.com. > Visit this group at https://groups.google.com/group/mojolicious. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.