more notes - hash key destruction happens at the right point but still won't work
[p5sagit/Mutually-Assured-Destruction.git] / notes / hash-key-destruction.pl
diff --git a/notes/hash-key-destruction.pl b/notes/hash-key-destruction.pl
new file mode 100644 (file)
index 0000000..30ca719
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Variable::Magic qw(wizard cast);
+
+BEGIN { package Foo; sub DESTROY { warn "in DESTROY\n"; } }
+
+my $wiz = wizard data => sub { $_[1] },
+                 free => sub { warn "destroyed $_[1]!\n"; };
+
+my %objs;
+
+$objs{foo} = bless({}, 'Foo');
+
+cast $objs{foo}, $wiz, '$objs{foo}';
+
+delete $objs{foo};