Use a module for detecting when we're in global destruction mode

Prompted by an RT ticket: https://rt.cpan.org/Ticket/Display.html?id=76865