Test::More uses last similarly.
SKIP: {
skip "Unix-specific tests skipped on Windows", 2 if $^O eq 'Win32';
is(...);
is(...);
};
I've used the same trick in an overridden exit in FastCGI daemon that executes CGI scripts.
chdir(dirname($script_qfn));
local $0 = $script_qfn;
FindBin::again();
local @ENV{ keys(%$env) } = values(%$env);
my ($rv, $e);
FCGI_DAEMON_EXEC_BLOCK: {
package scripts::fcgi_daemon::root;
# Hide a spurious warning.
{ no warnings 'void'; *CORE::GLOBAL::exit; }
local *CORE::GLOBAL::exit = sub {
no warnings 'exiting';
last FCGI_DAEMON_EXEC_BLOCK;
};
$rv = do($0);
$e = $@;
}
...
delete $scripts::fcgi_daemon::{'root::'};
CGI::_reset_globals() if $INC{"CGI.pm"};