From: Matt S Trout Date: Mon, 15 Jun 2009 18:48:46 +0000 (+0100) Subject: demonstrating how shit gets destroyed X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9a254f60195ed3c9618b84f88edcb50d9e178218;p=p5sagit%2FMutually-Assured-Destruction.git demonstrating how shit gets destroyed --- diff --git a/notes/destruction-order.pl b/notes/destruction-order.pl new file mode 100644 index 0000000..6d465f8 --- /dev/null +++ b/notes/destruction-order.pl @@ -0,0 +1,43 @@ +#!/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"; }; + +{ + warn "Stanza 1\n"; + + my %foo; + + my $foo = \%foo; + + bless($foo, 'Foo'); + + cast $foo, $wiz, '$foo'; + cast %foo, $wiz, '%foo'; + +} + +{ + warn "Stanza 2\n"; + + my $foo = do { + my %foo; + cast %foo, $wiz, '%foo'; + \%foo; + }; + + bless($foo, 'Foo'); + + cast $foo, $wiz, '$foo'; + + undef($foo); + + warn "End of block\n"; + +}