tie *STDOUT, 'Bugzilla::App::Stdout', controller => $c; ## no critic (tie)
# the finally block calls cleanup.
- $c->stash->{cleanup_guard}->dismiss;
+ $Bugzilla::App::Plugin::Glue::cleanup_guard->dismiss if $Bugzilla::App::Plugin::Glue::cleanup_guard;
Bugzilla->usage_mode(USAGE_MODE_BROWSER);
try {
Bugzilla->init_page();
use Scalar::Util qw(blessed);
use Scope::Guard;
+our $cleanup_guard;
+
sub register {
my ($self, $app, $conf) = @_;
}
$app->hook(
- before_dispatch => sub {
- my ($c) = @_;
+ around_dispatch => sub {
+ my ($next, $c) = @_;
Log::Log4perl::MDC->put(request_id => $c->req->request_id);
- $c->stash->{cleanup_guard} = Scope::Guard->new(\&Bugzilla::cleanup);
+
+ # Below we localize a package scoped variable, and put a scope guard in it
+ # this means the cleanup routine will be called when this around_dispatch
+ # hook returns. We do this to avoid having to handle any exceptions.
+ # Think of this as like a "defer cleanup()" in the Go language.
+ local $cleanup_guard = Scope::Guard->new(\&Bugzilla::cleanup);
# Ensure the request_cache is always cleared prior to every request,
# regardless of routing or Bugzilla::App wrapping.
# We also need to clear CGI's globals.
CGI::initialize_globals();
Bugzilla->usage_mode(USAGE_MODE_MOJO);
+ $next->();
}
);