Created
September 18, 2013 00:46
-
-
Save kraih/6602913 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This does not work for non-blocking operations and there is no solution for that.