Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Exported subroutine redefine

by ribasushi (Monk)
on Nov 11, 2007 at 13:25 UTC ( #650146=note: print w/ replies, xml ) Need Help??


in reply to Re: Exported subroutine redefine
in thread Exported subroutine redefine

I just ended up walking the entire symbol table, which turned out to be a trivial subroutine. Please let me know if I am doing something horribly wrong (the justification can be found in the big picture)

_redef(); sub _redef { my $parent = shift || '::'; for my $ns (grep /^\w+::/, keys %{$parent}) { $ns = $parent . $ns; _redef($ns) unless $ns eq '::main::'; for my $sub (keys %redef) { *{$ns . $sub} = $redef{$sub} if (exists ${$ns}{$sub}); } } }


Comment on Re^2: Exported subroutine redefine
Download Code
Replies are listed 'Best First'.
Re^3: Exported subroutine redefine
by joey (Initiate) on Oct 21, 2008 at 22:04 UTC
    This is really handy (and absolute evil of course). I find that it's a good idea to also check that the function you're replaceing not only has the same name, but is truely a pointer to the same function. Just a matter of comparing that \&{${$ns}{$sub}} == $origsub , where $origsub is a pointer to the function you want to replace.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://650146]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (16)
As of 2015-07-28 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls