Last active
August 29, 2015 14:17
-
-
Save calid/aeb939147fdd171cffe3 to your computer and use it in GitHub Desktop.
Perl DESTROY Scoping Semantics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local *Foo::c = sub { print "IN MY C\n" }; | |
my $f = Foo->new(); | |
Foo::c(); | |
Foo::d(); | |
e(); | |
undef $f; | |
__END__ | |
Output | |
------ | |
IN MY C | |
IN MY C | |
IN MY C | |
IN DESTROY | |
IN ORIG C <=== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local *Foo::c = sub { print "IN MY C\n" }; | |
my $f = Foo->new(); | |
Foo::c(); | |
Foo::d(); | |
e(); | |
undef $f; | |
print "DONE\n"; | |
__END__ | |
Output | |
------ | |
IN MY C | |
IN MY C | |
IN MY C | |
IN DESTROY | |
IN MY C <=== | |
DONE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
j <@> leave[1 ref] vKP/REFC ->(end) | |
1 <0> enter ->2 | |
2 <;> nextstate(main 11 local_destroy.pl:26) v:*,&,{,x*,x&,x$,$ ->3 | |
- <0> ex-const v ->- | |
- <0> null v ->3 | |
8 <2> sassign vKS/2 ->9 | |
5 <1> refgen sK/1 ->6 | |
- <1> ex-list lKRM ->5 | |
3 <0> pushmark sRM ->4 | |
4 <$> anoncode[CV ] lRM ->5 | |
7 <1> rv2gv sKRM*/LVINTRO,3 ->8 | |
6 <$> gv(*Foo::c) s ->7 | |
9 <;> nextstate(main 11 local_destroy.pl:27) v:*,&,{,x*,x&,x$,$ ->a | |
f <2> sassign vKS/2 ->g | |
d <1> entersub[t3] sKS/TARG,2 ->e | |
a <0> pushmark s ->b | |
b <$> const(PV "Foo") sM/BARE ->c | |
c <$> method_named(PV "new") s ->d | |
e <0> padsv[$f:11,12] sRM*/LVINTRO ->f | |
g <;> nextstate(main 12 local_destroy.pl:28) v:*,&,{,x*,x&,x$,$ ->h | |
i <1> undef vK/1 ->j | |
h <0> padsv[$f:11,12] sRM ->i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n <@> leave[1 ref] vKP/REFC ->(end) | |
1 <0> enter ->2 | |
2 <;> nextstate(main 11 local_destroy.pl:26) v:*,&,{,x*,x&,x$,$ ->3 | |
- <0> ex-const v ->- | |
- <0> null v ->3 | |
8 <2> sassign vKS/2 ->9 | |
5 <1> refgen sK/1 ->6 | |
- <1> ex-list lKRM ->5 | |
3 <0> pushmark sRM ->4 | |
4 <$> anoncode[CV ] lRM ->5 | |
7 <1> rv2gv sKRM*/LVINTRO,3 ->8 | |
6 <$> gv(*Foo::c) s ->7 | |
9 <;> nextstate(main 11 local_destroy.pl:27) v:*,&,{,x*,x&,x$,$ ->a | |
f <2> sassign vKS/2 ->g | |
d <1> entersub[t3] sKS/TARG,2 ->e | |
a <0> pushmark s ->b | |
b <$> const(PV "Foo") sM/BARE ->c | |
c <$> method_named(PV "new") s ->d | |
e <0> padsv[$f:11,12] sRM*/LVINTRO ->f | |
g <;> nextstate(main 12 local_destroy.pl:28) v:*,&,{,x*,x&,x$,$ ->h | |
i <1> undef vK/1 ->j | |
h <0> padsv[$f:11,12] sRM ->i | |
j <;> nextstate(main 12 local_destroy.pl:29) v:*,&,{,x*,x&,x$,$ ->k | |
m <@> print vK ->n | |
k <0> pushmark s ->l | |
l <$> const(PV "DONE") s ->m |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[✔]▶ diff /tmp/noprint.out /tmp/print.out | |
--- /tmp/noprint.out 2015-03-22 18:23:12.308776994 -0500 | |
+++ /tmp/print.out 2015-03-22 18:23:21.522110342 -0500 | |
@@ -1,4 +1,4 @@ | |
-j <@> leave[1 ref] vKP/REFC ->(end) | |
+n <@> leave[1 ref] vKP/REFC ->(end) | |
1 <0> enter ->2 | |
2 <;> nextstate(main 11 local_destroy.pl:26) v:*,&,{,x*,x&,x$,$ ->3 | |
- <0> ex-const v ->- | |
@@ -20,3 +20,7 @@ | |
g <;> nextstate(main 12 local_destroy.pl:28) v:*,&,{,x*,x&,x$,$ ->h | |
i <1> undef vK/1 ->j | |
h <0> padsv[$f:11,12] sRM ->i | |
+j <;> nextstate(main 12 local_destroy.pl:29) v:*,&,{,x*,x&,x$,$ ->k | |
+m <@> print vK ->n | |
+k <0> pushmark s ->l | |
+l <$> const(PV "DONE") s ->m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment