Created
May 26, 2012 11:26
-
-
Save berekuk/2793574 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env perl | |
| use strict; | |
| use Guard; | |
| sub make_foo { | |
| my $foo = shift; | |
| my $guard = guard { | |
| print "DESTROY\n"; | |
| }; | |
| return sub { | |
| $guard; # will print warning, need to wrap in 'no warnings' or invent a smarter way to reference it from closure | |
| $foo += shift; | |
| print $foo, "\n"; | |
| } | |
| } | |
| { | |
| my $foo = make_foo(3); | |
| $foo->(1); | |
| $foo->(1); | |
| $foo->(2); | |
| $foo->(2); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment