Hi,
I've tracked down a mod_perl problem to one of my class libraries
which defined operator overloading. Simplified a lot:
package MyClass;
use overload (
"+" => sub { $_[0]{val} + $_[1]{val} },
"<=>" => \&compare,
"cmp" => \&compare
);
sub compare {
...
}
The "+" operator, defined using an anonymous sub, works perfectly. The
comparison operators work fine _until_ MyClass.pm is changed; but they
then give errors like "Not a CODE reference at <calling module line>".
What I understand is happening is that Apache2::Reload is causing (as
designed) MyClass.pm to be recompiled, but perhaps into some fresh new
opaque package namespace and the old namespace is cleared out? But
somehow the overloaded comparison functions are left pointing at the
old &compare, which no longer exists.
A workaround obviously is just to avoid any direct symbol table
references in the overload table, and define everything via anonymous
subs.
This seems to fix the problem. But I don't fully understand why.
Grateful for any pointers to information about this. Also happy
to create a more proper test-case/bug report if that's useful -
however at the moment I suspect this is a known state of affairs.
FWIW, this is with modperl 2.0.2 on Solaris 8.
Regards
Anthony