Skip to content

Instantly share code, notes, and snippets.

@powerman powerman/gist:5456484
Last active Dec 16, 2015

Embed
What would you like to do?
Support for non-blocking Mojolicious app in CGI mode
use AnyEvent;
sub allow_non_blocking_cgi {
my ($module) = @_;
eval "require $module;" or die $@; ## no critic (ProhibitStringyEval)
my $startup = \&{$module.'::startup'};
my $wrapper = sub {
my ($app) = @_;
&{$startup};
my $done = AnyEvent->condvar;
$app->hook(after_dispatch => sub {
$done->send;
});
$app->hook(around_dispatch => sub {
shift->();
$done->recv;
});
};
no strict 'refs';
no warnings 'redefine'; ## no critic (ProhibitNoWarnings)
*{$module.'::startup'} = $wrapper;
return;
}
require Mojolicious::Commands;
if (Mojolicious::Commands->detect(q{}) eq 'cgi') {
allow_non_blocking_cgi('WebSite');
}
Mojolicious::Commands->start_app('WebSite');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.