Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Safer monkey-patching

by tobyink (Canon)
on Jan 19, 2012 at 08:58 UTC ( [id://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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://948717]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-03-19 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found