Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: changing object's methods at runtime

by Zaxo (Archbishop)
on May 22, 2003 at 01:32 UTC ( [id://259961]=note: print w/replies, xml ) Need Help??


in reply to changing object's methods at runtime

You can change a method at runtime with a scoped application of { local *Apache::FakeRequest::lookup_uri = sub { '127.0.0.1' } ...}

Here's an example using CGI.pm:

use CGI; my $q = CGI->new({foo=>'bar'}); print $q->param('foo'),$/; { local *CGI::param = sub {}; print "Empty", $/ unless defined $q->param('foo'); } print $q->param('foo'),$/;
That does not change the behavior for just a single object, but for all objects of the class within the local dynamic scope. As othermonks said, subclass for specializing a single instance.

After Compline,
Zaxo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-20 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found