Skip to content

Instantly share code, notes, and snippets.

@kraih
Created September 18, 2013 00:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kraih/6602913 to your computer and use it in GitHub Desktop.
Save kraih/6602913 to your computer and use it in GitHub Desktop.
use Mojolicious::Lite;
# Catch magical detach exception and rethrow everything else
hook around_dispatch => sub {
my ($next, $c) = @_;
return if eval { $next->(); 1 };
die $@ unless $@ eq "MOJO_DETACH\n";
};
# Throw magical detach exception
helper detach => sub { die "MOJO_DETACH\n" };
helper some_helper => sub {
my $self = shift;
$self->render(text => 'I take over!');
$self->detach;
};
get '/' => sub {
my $self = shift;
$self->some_helper;
$self->render(text => 'I will never be reached!');
};
app->start;
@kraih
Copy link
Author

kraih commented Dec 30, 2014

This does not work for non-blocking operations and there is no solution for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment