Created
June 11, 2011 02:09
-
-
Save asergeyev/1020161 to your computer and use it in GitHub Desktop.
Destroy overload prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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