Re: Dealing with exit in a Modulino
- From: "Yitzchak Scott-Thoennes" <sthoenna@xxxxxxx>
- Date: Sun, 6 Apr 2008 17:48:11 -0700 (PDT)
On Sat, Mar 29, 2008 at 04:44:28AM -0700, Marc Girod wrote:
The problem is then: how to return to the caller context
(when there is one, i.e. when I do not choose to exit),
instead of to the caller of my exit subroutine?
Some kind of exception mechanism.
Something like this (completely untested):
use Test::More tests => ...;
my $exitcode;
sub script_call(&) {
my $code_to_test = shift;
undef $exitcode;
return &$code_to_test();
EXIT_HOOK:
return;
}
BEGIN { *CORE::GLOBAL::exit = sub { $exitcode = shift; goto EXIT_HOOK } }
use Your::Script;
is(script_call { Your::Script::startup() }, "OK");
is($exitcode, undef, "didn't exit on startup);
script_call { Your::Script::shutdown() };
is($exitcode, 0, "exited on shutdown");
# calls to exit not laundered through script_code end up here
EXIT_HOOK: CORE::exit $exitcode;
.
- Follow-Ups:
- Re: Dealing with exit in a Modulino
- From: Ilya Zakharevich
- Re: Dealing with exit in a Modulino
- Prev by Date: Re: Strange perl 5.8.8 method lookup problem
- Next by Date: Re: Dealing with exit in a Modulino
- Previous by thread: Strange perl 5.8.8 method lookup problem
- Next by thread: Re: Dealing with exit in a Modulino
- Index(es):
Relevant Pages
|