Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Safer monkey-patching

by tobyink (Abbot)
on Jan 19, 2012 at 08:58 UTC ( #948717=note: print w/ replies, xml ) Need Help??


in reply to Re: Safer monkey-patching
in thread Safer monkey-patching

Method lookup caching doesn't happen until a method has actually been called. Because the @ISA manipulation happens in a BEGIN block, this should occur before any method calls, thus before any method lookups have been cached.

Also, according to perlobj any changes to @ISA should invalidate the cache. There may be bugs lurking somewhere in perl's method lookup caching mechanism, but none that seem to be triggered by the technique I've discussed.

After all, the situation where package $X manipulates package $Y's <c>@ISA at BEGIN-time is really common. (Consider the case where $X eq "base" or $X eq "parent". Sure, this is happening at package $Y's request, but from Perl's perspective the same thing is happening.)

With Moose it happens at run-time, and this doesn't seem to cause any problems.


Comment on Re^2: Safer monkey-patching
Select or Download Code
Re^3: Safer monkey-patching
by Anonymous Monk on Jan 19, 2012 at 10:42 UTC

    ... BEGIN ... perlobj ... parent ... perspective ..

    By the time you load Data::Dumper or whatever, resolution method could have happened

    But yeah, I did say I vaguely recall, esp because I didn't feel like digging up history or pinning down the details :)

    As for parent... perspective is exactly the point. If you're bothering to write a module to share, you might as well do it right, which is not dickering around with other peoples class data :) delegate (AUTOLOAD or ...)

    At least if you monkey patch, warnings will issue "Subroutine %s redefined"

    With Moose it happens at run-time, and this doesn't seem to cause any problems.

    Sure it does :) Moose Cookbook - Meta Recipe 5 Won't Run

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2014-09-01 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (17 votes), past polls