Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: change perl function in runtime

by LanX (Saint)
on Dec 03, 2012 at 15:19 UTC ( [id://1006894]=note: print w/replies, xml ) Need Help??


in reply to change perl function in runtime

You need *globs to manipulate symbol table entries like package functions! ( see perlmod and perlsub)

Something like this should do

{ package A; local *x = sub { die "aaa" }; #run tests ... } # &x reset after leaving block

if you want to explicitly reset &x try to store the old coderef before.

$old_coderef = \&x; # run tests ... # do what you want ... # (but think about the omen ;-) *x = $old_coderef;

Cheers Rolf

Replies are listed 'Best First'.
Re^2: change perl function in runtime
by david2008 (Scribe) on Dec 03, 2012 at 15:41 UTC
    It works very well. This is real perl alchemy :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-29 13:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found