To clarify Dan's answer about state variables (mostly, for myself).

If you run separate apps in the same process like these.

my $app1 = Test::Mojo->new('MyApp')->app;

my $app2 = Test::Mojo->new('MyApp')->app;

# now $app1->sqlite and $app2->sqlite is the same state variable.

You got two apps in the same process and they share the same state variable.

On 09/05/2019 07:01, Dan Book wrote:
A lexical variable is still bound to a scope, even if it's the file scope. If that scope is run again (such as creating another instance of the same application) then that will have a separate instance of that lexical variable. State variables are initialized once and shared between any access for the rest of that process. It can't know what outer scope you might have wanted to store it in. It can still be useful but you have to make sure that's what you want.

-Dan

On Wed, May 8, 2019 at 11:45 PM Veesh Goldman <[email protected] <mailto:[email protected]>> wrote:



    On Wed, May 8, 2019, 5:55 PM Dan Book <[email protected]
    <mailto:[email protected]>> wrote:


        Alternatively you can use 'state $sqlite = ' inside the helper
        but this approach breaks the ability to run multiple separate
        apps in the same process, because it will make one $sqlite per
        whole process.

        -Dan



    Could you expound on this problem? I thought state is just a
    shortcut to closing over a lexical variable.
-- 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 [email protected]
    <mailto:[email protected]>.
    To post to this group, send email to [email protected]
    <mailto:[email protected]>.
    Visit this group at https://groups.google.com/group/mojolicious.
    To view this discussion on the web visit
    
https://groups.google.com/d/msgid/mojolicious/CAO-W_8CVM9NnBMXuyvHi_FCT7p8%2B11FxTn6it9%3D%3D2JpUr78nfw%40mail.gmail.com
    
<https://groups.google.com/d/msgid/mojolicious/CAO-W_8CVM9NnBMXuyvHi_FCT7p8%2B11FxTn6it9%3D%3D2JpUr78nfw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
    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 [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>.
Visit this group at https://groups.google.com/group/mojolicious.
To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/CABMkAVUWJc-rYw4DhThw9YGcp7OdCh3d0djXRoPLpRkq-vESZg%40mail.gmail.com <https://groups.google.com/d/msgid/mojolicious/CABMkAVUWJc-rYw4DhThw9YGcp7OdCh3d0djXRoPLpRkq-vESZg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/e9a40bd8-f099-b2b1-d578-41a22e2b7371%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to