After a long, painful session of dodging segfaults, I finally discovered the answer to my problem:
foreach my $method (@methods) {
no strict 'refs';
*$method = sub { shift->$method(@_) };
}
All tests pass and there are no recursion issues. Also, it turns out to be documented core behavior.
Just try and guess why I need this.
My only guess is that...
btilly on 2008-06-13T00:26:58
Somewhere, somehow, something is doing $object->foo::bar(@stuff) and you're needing to catch these calls in package foo and tell it that no, you really wanted to make those method calls on $object, not on package foo.
That situation would avoid all recursion problems with that code and is documented in the core. But I would need to know more about your code to guess why it might do something silly like call the method foo::bar.
However I suspect that you have lots of things that you want dispatched to package foo, and there were a few methods that got dispatched there that you didn't. I just don't know why.
Re:My only guess is that...
ChrisDolan on 2008-06-13T01:57:29
Or, the code is "print($object, ...)" (replace "print" with any other core or imported symbol) and Ovid wants the $object to control the behavior. The alternative is a solution like UNIVERSAL::isa.