[Mojolicious] Re: Need help with stashing data and retrieving it in the template

2019-02-07 Thread Ron Bergin
Thank you Dan. I will work on adjusting the error handling as suggested. This is the first time I've done any async and for me it's a bit confusing and has a stepper learning curve than the Dancer apps that I've done. -- You received this message because you are subscribed to the Google

Re: [Mojolicious] Re: Need help with stashing data and retrieving it in the template

2019-02-07 Thread Dan Book
For error handling in this case, keep in mind that there are multiple kinds of errors. Transport errors (connection failure, etc) will result in the promise being rejected, which for `all` will cause the whole promise to be rejected and the `catch` callback to be called, rendering an exception

[Mojolicious] Re: Need help with stashing data and retrieving it in the template

2019-02-07 Thread Ron Bergin
Stefan, Thanks for the link. I've previously read that post but will need to read it again. Dan, I figured out what was causing that last error. I forgot to load use Mojo::Util 'trim'; The script is now working correctly. Now I need to work on adding error checking/handling for cases where

Re: [Mojolicious] Re: Need help with stashing data and retrieving it in the template

2019-02-07 Thread Dan Book
Regarding delays, promises actually came later and are now considered the preferred approach as they are much more composable, error handling is easier, and they are the same concept used in many other languages. -Dan On Thu, Feb 7, 2019 at 2:24 PM Ron Bergin wrote: > Dan, thank you for your

Re: [Mojolicious] Re: Need help with stashing data and retrieving it in the template

2019-02-07 Thread Dan Book
I used trim(), this needs to be imported from Mojo::Util. -Dan On Thu, Feb 7, 2019 at 2:24 PM Ron Bergin wrote: > Dan, thank you for your input. I haven't looked at promises much but I > was under the impression (based on some of Joel Berger's examples as well > as one or two other key

[Mojolicious] Re: Need help with stashing data and retrieving it in the template

2019-02-07 Thread Ron Bergin
Dan, thank you for your input. I haven't looked at promises much but I was under the impression (based on some of Joel Berger's examples as well as one or two other key mojolicious developers) that delays were supposed to be cleaner and more desirable. I knew about the issue with the for loop

Re: [Mojolicious] Re: Need help with stashing data and retrieving it in the template

2019-02-07 Thread Dan Book
One more thing: you need to keep a strong reference to the Mojo::UserAgent object until it completes, so you should define $ua outside of the action method which will end before the async code occurs. -Dan On Thu, Feb 7, 2019 at 1:23 PM Dan Book wrote: > Your commented 'for' loop is correct;

Re: [Mojolicious] Re: Need help with stashing data and retrieving it in the template

2019-02-07 Thread Dan Book
Your commented 'for' loop is correct; you need to dereference stash('titles') to pass the list of hashrefs to the loop. The other problem is that you need to prevent auto-rendering until your async code has completed. You can do this by calling `$c->render_later` at the beginning of the action

Re: [Mojolicious] Re: Need help with stashing data and retrieving it in the template

2019-02-07 Thread Stefan Adams
Take a look at this Advent Calendar blog post . Specifically, "Web Apps" at the bottom. On Thu, Feb 7, 2019 at 11:57 AM Ron Bergin wrote: > Note: I cross posted this question on perlmonks > https://perlmonks.org/?node_id=1229558