Re: [Camelbones-devel] [PATCH] Make NSObject::AUTOLOAD cache
Brought to you by:
shermpendley
From: Sherm P. <she...@gm...> - 2010-11-12 01:25:24
|
On Thu, Nov 11, 2010 at 4:26 PM, Matt Sergeant <ma...@se...> wrote: > > my $class = ref($self) || $self; > my $isSuperMethod = exists(&{ "${class}::${subName}" }) ? undef : 1; You're still missing the point of $isSuperMethod. I'll accept some blame for that - a more accurate name for it would be $isSuperInvocation; it's not a property of the method, it's a property of the current invocation of the method. A subtle distinction, to be sure - but a critical difference just the same. That's the key point that I think you're missing. There is no value of $isSuperMethod that will always apply to a given method every time it's called. Sometimes we need to call it with objc_msgSend(), sometimes with objc_msgSendSuper(). It depends on the context of the current invocation, which can and does vary from one invocation to another. It has nothing to do with the method itself, or with any past invocations; it's solely a function of how the method is currently being called. You said earlier "surely Objective-C knows how to climb its inheritance tree," and you're right, but for efficiency's sake that knowledge is built into the compiler rather than the runtime library. The compiler simply generates a call to objc_msgSend() when it sees [self foo], and a call to objc_msgSendSuper() when it sees [super foo]. But we're not using the Objective-C compiler to generate the calls to these functions; we're calling them manually, which means that now *we* need to decide which messenger function to call. What we need for this is a reliable means of determining, each time a Perl method is called and *independently of any past or future calls to the same method*, whether it's currently being called as $obj->foo() or $obj->SUPER::foo(). Let's forget about *why* we need that info for the moment, and focus on *how* to get it - that's a question that can be explored independently of CamelBones and method caching, which simplifies the problem domain by a lot. Autoload may be slow, but it's easy and 100% reliable by virtue of the fact that it includes the "SUPER::" string in the method name is passes to the autoload function. In Perl 5.10+, caller()[8] can tell us, but we need a solution that works with the various Perl 5.8.* versions provided by Apple in previous Mac OS X releases. Are there any other possibilities? If not, what we have is good enough; it isn't 100% reliable, but it's easy to disable, and let's face it, calling SUPER::foo() just isn't that common anyway. sherm-- -- Cocoa programming in Perl: http://camelbones.sourceforge.net |