<div dir="ltr"><div>Hi Nathan</div><div><div><br></div></div><div>It might be helpful to address this problem through a separation of concerns. You've got the Dancer app's job which is to serve web pages. Then there's another job - to send emails - and from this viewpoint it makes sense to implement that as a separate piece of software.<br></div><div> </div><div>On a large scale this can be done using a queuing service where the Dancer app puts a message onto the message queue (managed by a broker like RabbitMQ or ActiveMQ....) and your email sending software pulls the message off the queue and sends the email.</div><div><br></div><div>On a smaller scale I've done this without a message broker by treating a table in a database as a message queue - the Dancer app writes a line to the table with details of the message to send. A separate script - a daemon based on this <a href="https://metacpan.org/pod/Daemon::Control">https://metacpan.org/pod/Daemon::Control</a> checks for any new records in the table, sends the appropriate message and marks the row as 'sent'.</div><div><br></div><div><div><div>There's more than one way to skin a cat so that's just another approach to consider. Good luck!</div></div></div><div><br></div><div>Andrew</div><div><br></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On 29 Jun 2017 06:56, "Nathan Bailey" <<a href="mailto:web@polynate.net" target="_blank">web@polynate.net</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi all,</div>   I want to send my Dancer2 TT page as an email <i>and</i> continue to generate a normal web response.<div><br></div><div>This forking discussion seems like an excellent approach.</div><div><br></div><div>I have:</div><div>1. Created a fork in 'hook before_layout_render' (based on a '<font face="monospace, monospace">var want_email = 1;</font>').</div><div>2. The parent continues to serve the webpage (as normal, after undef'ing want_email), the grandchild sends the email (in 'hook after_layout_render')</div><div><i><br></i></div><div><i>(I'm doing this in before_layout_render so I can change the layout (<font face="monospace, monospace">app->template_engine->layout(<wbr>'email');</font>) to a lighter, more email-friendly layout)</i><br></div><div><br></div><div>An additional benefit of this approach is that the email is sent asynchronously, since Gmail-dispatched emails seem to take 2-3s to send.</div><div><br></div><div>This all works well and I am grateful for this discussion and Andy's example code, but I am unclear about the guard, per below.</div><div>I understand what it is intended to do, but if I put:</div><div><font face="monospace, monospace">   my $guard = guard { info "I'm dying"; POSIX::_exit(0); };</font></div><div>in my code, the code immediately prints the "I'm dying" and exits.</div><div><br></div><div class="gmail_extra">Am I missing something in how to use Guard properly?</div><div class="gmail_extra"><br></div><div class="gmail_extra">BTW, if someone has a better pattern for emailing a page, I'd welcome it.</div><div class="gmail_extra"><br></div><div class="gmail_extra">cheers,</div><div class="gmail_extra">Nathan</div><div class="gmail_extra"><br><div class="gmail_quote">On 3 April 2017 at 21:21, Andrew Beverley <span dir="ltr"><<a href="mailto:andy@andybev.com" target="_blank">andy@andybev.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>On Mon, 3 Apr 2017 13:22:16 +0300 Shlomi Fish wrote:</span><br>
> like "guard"s<br>
<br>
You should consider a guard, to ensure that nothing in the grandchild<br>
causes it to hang around. For example, if there is an exception which<br>
is then caught before the _exit(), you can end up with the grandchild<br>
hanging around serving web requests to nobody ;-)<br></blockquote></div></div></div>
<br>______________________________<wbr>_________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/ma<wbr>ilman/listinfo/dancer-users</a><br>
<br></blockquote></div></div>
</div>