in reply to Re^2: is there a way to ensure some code is the last thing that is run?
in thread is there a way to ensure some code is the last thing that is run?
orpackage Logger; our $default_logger = __PACKAGE__->new(); sub new { my $this = bless {}; } sub DESTROY { print "DESTROY\n"; } package MAIN; END { print "END\n"; }
package Logger; my $default_logger = __PACKAGE__->new(); sub new { my $this = bless {}; } sub log { $default_logger->foo(); } sub DESTROY { print "DESTROY\n"; } package MAIN; END { print "END\n"; }
In both cases, a package variable ($Logger::default_logger in the first snippet, &Logger::log in the second snippet) keep the object alive until global destruction (where package variables are destroyed).
|
|---|