Skip to content

Instantly share code, notes, and snippets.

@asergeyev
asergeyev / destroyer.pl
Created June 11, 2011 02:09
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(\@_) };";