Hi all,
   I want to send my Dancer2 TT page as an email and continue to generate a normal web response.

This forking discussion seems like an excellent approach.

I have:
1. Created a fork in 'hook before_layout_render' (based on a 'var want_email = 1;').
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')

(I'm doing this in before_layout_render so I can change the layout (app->template_engine->layout('email');) to a lighter, more email-friendly layout)

An additional benefit of this approach is that the email is sent asynchronously, since Gmail-dispatched emails seem to take 2-3s to send.

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.
I understand what it is intended to do, but if I put:
   my $guard = guard { info "I'm dying"; POSIX::_exit(0); };
in my code, the code immediately prints the "I'm dying" and exits.

Am I missing something in how to use Guard properly?

BTW, if someone has a better pattern for emailing a page, I'd welcome it.

cheers,
Nathan

On 3 April 2017 at 21:21, Andrew Beverley <andy@andybev.com> wrote:
On Mon, 3 Apr 2017 13:22:16 +0300 Shlomi Fish wrote:
> like "guard"s

You should consider a guard, to ensure that nothing in the grandchild
causes it to hang around. For example, if there is an exception which
is then caught before the _exit(), you can end up with the grandchild
hanging around serving web requests to nobody ;-)