demonstrate self saving during DESTROY
[p5sagit/Mutually-Assured-Destruction.git] / notes / save-my-life-safely.pl
diff --git a/notes/save-my-life-safely.pl b/notes/save-my-life-safely.pl
new file mode 100644 (file)
index 0000000..c164daf
--- /dev/null
@@ -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);