package OnDestroy; BEGIN { our @EXPORT = qw( on_destroy ); require Exporter; *import = \&Exporter::import; } sub on_destroy(&) { my ($action) = @_; return bless(\$action); } sub cancel { my ($self) = @_; undef $$self; } sub DESTROY { my ($self) = @_; my $action = $$self; $action->() if $action; } 1;