Skip to content

Instantly share code, notes, and snippets.

@manchicken
Created August 31, 2013 21:11
Show Gist options
  • Save manchicken/6400657 to your computer and use it in GitHub Desktop.
Save manchicken/6400657 to your computer and use it in GitHub Desktop.
DestroyDetector class, helps us to detect when a variable is garbage-collected.
package DestroyDetector;
sub new {
my ($pkg, $val) = @_;
my $self = {value=>$val};
return bless $self, $pkg;
}
sub value {
my ($self) = @_;
return $self->{value};
}
sub announce {
my ($self, $msg) = @_;
$msg //= q{};
say "Announcing DestroyDetector \"$msg\" value: ".$self->value;
}
sub DESTROY {
my ($self) = @_;
say "Destroying DestroyDetector value: ".$self->value;
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment