Created
August 31, 2013 21:11
-
-
Save manchicken/6400657 to your computer and use it in GitHub Desktop.
DestroyDetector class, helps us to detect when a variable is garbage-collected.
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
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