Skip to content

Instantly share code, notes, and snippets.

@dgl
Created March 28, 2011 08:00
Show Gist options
  • Save dgl/890138 to your computer and use it in GitHub Desktop.
Save dgl/890138 to your computer and use it in GitHub Desktop.
package a;
sub foo {
warn "foo";
}
sub rebind {
no warnings "redefine";
eval q{delete $a::{foo}};
eval q{*foo = sub { warn "bar" }};
}
sub go {
foo();
rebind();
foo();
}
1;
$ perl -Ma -e'a::go(); a::foo(); eval q{a::foo()}'
foo at a.pm line 4.
foo at a.pm line 4.
foo at a.pm line 4.
bar at (eval 2) line 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment