On Apr 14, 2005, at 6:37 PM, Scott Lanning wrote:

On Thu, 14 Apr 2005, muppet wrote:
I have some ugly and non-open code at work that illustrates binding a C++
abstract class to perl and allowing perl code to override virtual methods.
[...]
If that would be interesting or helpful, i'll try to carve a useful example
out of that code this weekend.

I would find it very useful. What I'm doing has all virtual methods.

I've stripped my code down to the bare minimum needed to give an example, and changed the name to protect the guilty :-)


http://asofyet.org/muppet/software/Base-0.05.tar.gz

The basic technique is to use a proxy class to marshal virtual methods to perl as ALLCAPSMETHODS. The example shows two virtual methods -- one that is required, and one that has a fallback and allows chaining up, with an optimization that avoids the marshal to perl if no override is present. Nothing fancy, just error-prone.


(Interestingly, the test works on linux with both "make test" and "perl -Mblib test.pl", but on my darwin setup, "perl -Mblib test.pl" works perfectly, but "make test" fails with an inexplicable inability to find the constructor in the derived class. that is, i believe, unrelated to the virtual method examples ...)


--
I don't have a drinking problem,
'cept when i can't get drink.
  -- Tom Waits



Reply via email to