X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FMutually-Assured-Destruction.git;a=blobdiff_plain;f=notes%2Fhash-key-destruction.pl;fp=notes%2Fhash-key-destruction.pl;h=30ca719660767a983be1625b5ca8ae2b7bdf0e95;hp=0000000000000000000000000000000000000000;hb=f7926535e963d2b6c3272cdf60e757d5151d5321;hpb=9a254f60195ed3c9618b84f88edcb50d9e178218 diff --git a/notes/hash-key-destruction.pl b/notes/hash-key-destruction.pl new file mode 100644 index 0000000..30ca719 --- /dev/null +++ b/notes/hash-key-destruction.pl @@ -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};