Skip to content

Instantly share code, notes, and snippets.

@asergeyev
Created June 11, 2011 02:09
Show Gist options
  • Save asergeyev/1020161 to your computer and use it in GitHub Desktop.
Save asergeyev/1020161 to your computer and use it in GitHub Desktop.
Destroy overload prototype
sub destroy_warning { warn ref($_[0]) . " destroyed\n" };
my %SAVED_DESTROYS;
for my $class (keys %INC) {
$class =~ s/\.pm$//; $class =~ s/\//::/sg;
if (my $destroy_ref = $class->can('DESTROY')) {
$SAVED_DESTROYS{$class} = $destroy_ref;
eval "no warnings 'redefine'; *${class}::DESTROY = sub { destroy_warning(\@_); \$SAVED_DESTROYS{'$class'}->(\@_) };";
} else {
eval "*${class}::DESTROY = sub { destroy_warning(\@_) };";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment