Hi, Apache2::Reload relies on ModPerl::Util::unload_package_pp to disassemble a stash entry before importing the code again. I like how it does this with two exceptions.
First, prototypes. unload_package_pp() takes care to retain the prototype when redefining a code stash entry. That's a good thing because it (typically) avoids a warning. Then it removes the subroutine from the stash using undef(). That's not so hot because undef takes the liberty to explicitly undefine the prototype of that subroutine. In the case of Apache2::Reload, what happens next is we remake a prototyped subroutine - lets use try() from Error.pm for illustration - and get warnings about mismatched prototypes. perl believes the prototype for this subroutine is not defined, Error tries to define it as (&;$), and perl warns about "none vs. (&;$)" prototype mismatch. This can be avoided by explicitly deleting the CODE slot in the stash entry, like this: "delete ${$fullname}{CODE};" This will remove the body of the coderef but leave the prototype in tact. Second, constant redefinitions. In this case the assignment of an empty subroutine (with proper prototype) throws a warning, only in the case of constant subroutines. Take something created by "use constant" as an example, and combine that with Apache2::Reload. unload_package_pp() makes every attempt to turn off warnings but can't, for whatever reason, make it work for this one. The reason, I found through copious trial and error and a pairing session with Adam Foxson, is to turn off the warning directly in the eval, like this: *{$fullname} = eval "no warmings 'redefine'; sub ($p) {}"; I am not sure why the redefinition warning is thrown from this lexical scope. Nevertheless, a solution is found. Attached is a patch which accounts for these two problems. Please consider it. Cheers, -- Casey West
Index: xs/ModPerl/Util/Util_pm =================================================================== --- xs/ModPerl/Util/Util_pm (revision 711950) +++ xs/ModPerl/Util/Util_pm (working copy) @@ -39,12 +39,12 @@ no warnings; local $^W = 0; if (defined(my $p = prototype $fullname)) { - *{$fullname} = eval "sub ($p) {}"; + *{$fullname} = eval "no warnings 'redefine'; sub ($p) {}"; } else { *{$fullname} = sub {}; } - undef &$fullname; + delete ${$fullname}{CODE}; } if (*{$fullname}{IO}) { local $@;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]