Re: [Camelbones-devel] [PATCH] Make NSObject::AUTOLOAD cache
Brought to you by:
shermpendley
From: Sherm P. <she...@gm...> - 2010-11-10 15:21:58
|
On Sat, Nov 6, 2010 at 2:44 PM, Matt Sergeant <ma...@se...> wrote: > > my $isSuperMethod = undef; > > - if ($selString =~ /^SUPER::/) { > - $selString =~ s/^SUPER:://; > + # will this work? The $selString =~ s/^\w+::// seems to break it? > + # use subName instead? > + if ($selString =~ s/^SUPER:://) { > $isSuperMethod = 1; > } > > - # Strip away the class name from the selector > - $selString =~ s/^.*::(.*)/$1/; > + # Strip away the class name from the selector and subName > + $selString =~ s/.*:://; > + $subName =~ s/.*:://; > > - my $self = shift; > - $returnObject = CamelBones::CBCallNativeMethod( > + no strict 'refs'; > + *{$NSObject::AUTOLOAD} = sub { > + my $self = shift; > + > + my $returnObject = CamelBones::CBCallNativeMethod( > $self, $selString, \@_, $isSuperMethod); Thinking about this some more... Since $selString and $isSuperMethod are lexical, won't they both keep the values they had when the closure was created? Not a big deal for $selString. but getting the wrong value for $isSuperMethod may cause things to fail in interesting ways. What happens if I create a Perl subclass that doesn't override a method, so the first time the method is called, $isSuper==undef. But then it's called from another subclass that *does* override it, and calls the original through SUPER. If the second call is made through a closure that kept the negative value for $isSuper, it will be dispatched with objc_msgSend() instead of objc_msgSendSuper(), so the second subclass' implementation of the method would end up calling itself in an endless loop. sherm-- -- Cocoa programming in Perl: http://camelbones.sourceforge.net |