From: Matt S Trout Date: Mon, 15 Jun 2009 19:47:22 +0000 (+0100) Subject: demonstrate self saving during DESTROY X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=68d6f889e0de19fe2d53e0036c1f94a82f94e55b;p=p5sagit%2FMutually-Assured-Destruction.git demonstrate self saving during DESTROY --- diff --git a/notes/save-my-life-safely.pl b/notes/save-my-life-safely.pl new file mode 100644 index 0000000..c164daf --- /dev/null +++ b/notes/save-my-life-safely.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Devel::GlobalDestruction (); + +my %objs; + +BEGIN { + package Foo; + + sub DESTROY { + warn "DESTROY\n"; + return if Devel::GlobalDestruction::in_global_destruction(); + $objs{$_[0]} = $_[0]; + } +} + +{ + bless({}, 'Foo'); +} + +warn join(', ', %objs); diff --git a/notes/save-my-life.pl b/notes/save-my-life.pl new file mode 100644 index 0000000..2e1e748 --- /dev/null +++ b/notes/save-my-life.pl @@ -0,0 +1,18 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +my %objs; + +BEGIN { + package Foo; + + sub DESTROY { warn "DESTROY\n"; $objs{$_[0]} = $_[0]; } +} + +{ + bless({}, 'Foo'); +} + +warn join(', ', %objs);