in reply to Rebinding closures, possible?
Note that coderef2text will preserve the original coderef's lexical warnings and strict 'refs' state. See B::Deparse doc for ways to change this.... # some scope # pass coderef, returns coderef rebound to this scope *rebind_here = sub { use B::Deparse (); ref $_[0] eq "CODE" or die "expected coderef"; eval("sub ".B::Deparse->new->coderef2text($_[0])); } ... # some other scope $new_coderef = &rebind_here($old_coderef);
Also note that closed lexicals in the original sub may become globals and vice versa if the lexical environment isn't the same.
Update: hmm. negative votes. Perhaps it would help if I noted that you may wish to make sure certain lexicals are still available by adding ($x,$y,$z) if 0; after the use B::Deparse line.
|
|---|