Return-Path: Delivered-To: apmail-perl-dev-archive@perl.apache.org Received: (qmail 93682 invoked by uid 500); 19 Jun 2003 08:14:52 -0000 Mailing-List: contact dev-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Delivered-To: mailing list dev@perl.apache.org Received: (qmail 93668 invoked from network); 19 Jun 2003 08:14:51 -0000 Received: from cerberus.radan.com (HELO radan.com) (195.166.67.75) by daedalus.apache.org with SMTP; 19 Jun 2003 08:14:51 -0000 Received: by radan.com; id JAA06709; Thu, 19 Jun 2003 09:15:05 +0100 (BST) Received: from sonicwall.radan.com(195.166.67.78) by cerberus.radan.com via csmap (V4.1) id srcAAATIaGgn; Thu, 19 Jun 03 09:15:04 +0100 Organisation: Radan Computational Ltd., Bath, UK. Phone: +44 1225 320320 Fax: +44 1225 320311 Web: http://www.radan.com/ Received: from uk.radan.com (dhcp-a-33 [172.16.50.33]) by uk.radan.com (8.9.1b+Sun/8.9.1) with ESMTP id JAA18616; Thu, 19 Jun 2003 09:14:55 +0100 (BST) Message-ID: <3EF1715A.6010102@uk.radan.com> Date: Thu, 19 Jun 2003 09:16:26 +0100 From: Steve Hay User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 X-Accept-Language: en-gb, en, en-us MIME-Version: 1.0 To: Stas Bekman CC: dev@perl.apache.org Subject: Re: [Fwd: Apache::Reload Module] References: <3EE8B036.9090801@uk.radan.com> <3EE90696.4050206@stason.org> <3EE98521.2080901@uk.radan.com> <3EEABE4C.7080007@stason.org> <3EED7B4B.6050900@uk.radan.com> <3EED8DF4.7010003@stason.org> <3EED96D1.3070307@uk.radan.com> <3EEE5945.3020704@stason.org> <3EEEDF2F.9020205@uk.radan.com> <3EF150F5.9020001@stason.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Hi Stas, Stas Bekman wrote: >>> Look at ModPerl::RegistryCooker::flush_namespace_normal, which does >>> the necessary undef'ing. You really need just a chunk of it. >> >> >> >> I've had a look at this, and can't get it to work properly. I've >> combined the subroutine undef'ing from that function with the >> constant subroutine mandatory warning handling from the mp2 version >> of Apache::Reload, but when I try it out I find that (a) all the >> constant subroutines produce warnings about prototype mismatches, and >> (b) all the other subroutines still produce warnings about being >> redefined! >> >> The following short test script reproduces both of these problems: >> >> ### START >> >> use strict; >> use warnings; >> >> use constant FOO => 1; >> sub bar { 1; } >> >> BEGIN { >> $SIG{__WARN__} = sub { >> return if $_[0] =~ /^Constant subroutine [\w:]+ redefined at/; >> CORE::warn(@_); >> }; >> foreach my $fullname ('main::FOO', 'main::bar') { >> if (defined &$fullname) { >> if (defined(my $p = prototype $fullname)) { >> no strict 'refs'; >> no warnings 'redefine'; >> *{$fullname} = eval "sub ($p) {}"; >> } >> else { >> no strict 'refs'; >> no warnings 'redefine'; >> *{$fullname} = sub {}; >> } >> undef &$fullname; >> } >> } >> } >> >> use constant FOO => 2; >> sub bar { 2; } >> >> ### END >> >> This program produces the following warnings: >> >> Prototype mismatch: sub main::FOO vs () at C:/perl5/lib/constant.pm >> line 108. >> Subroutine bar redefined at C:\Temp\test.pl line 30. >> >> By contrast, the solution that I was originally working towards, >> using Apache::Symbol::undef(), looks much simpler: >> >> ### START >> >> use strict; >> use warnings; >> >> use constant FOO => 1; >> sub bar { 1; } >> >> BEGIN { >> require Apache::Symbol; >> foreach my $fullname ('main::FOO', 'main::bar') { >> no strict 'refs'; >> Apache::Symbol::undef(*{$fullname}{CODE}); >> } >> } >> >> use constant FOO => 2; >> sub bar { 2; } >> >> ### END >> >> and produces no warnings. >> >> Unless I'm missing something, this suggests to me that we do still >> need (or least, could greatly benefit from having) Apache::Symbol in >> mp2. I would like to see it put back so that I can produce an >> Apache::Reload patch that uses it. >> >> There are three options here: >> >> 1. Put back Apache::Symbol and use it's undef() function. >> 2. Copy the Apache::Symbol::undef() function into Apache::Reload. >> 3. Explain why the first test script above doesn't work and fix it! >> >> I favour option 1. What's your vote? > > > We should certainly fix the problems you have mentioned. Thanks for > raising that issue. Is this still the same list after Philippe has > posted his patch? I guess the three options still stand, but now Philippe has proposed a fourth option -- copy the Apache::Symbol::undef() function into ModPerl::Util for mp2, and just use Apache::Symbol for mp1. As for fixing the problems shown up by the first test script above, maybe the best thing to do is "option five": put the remove_package() function that my last patch proposed for Apache::Reload (based on Philippe's code) into some other module (maybe ModPerl::Util) so that it can be used instead of ModPerl::RegistryCooker::flush_namespace_normal()? In fact, the Symbol module already contains a function called delete_package() which does a similar job again, though even less well still! (It doesn't appear to have any magic to circumvent those mandatory warnings about constant subroutines, or to avoid undef'ing stuff imported from other packages.) The "best" solution, I suppose, would be "option six": get Symbol::delete_package() updated using Philippe's code and the undef() function from Apache::Symbol, and then have both Apache::Reload and ModPerl::RegistryCooker use Symbol::delete_package() instead of having their own versions of what is basically a "core" (as opposed to mod_perl-specific) function. However, nothing's perfect in this world. Option six would make Apache::Reload dependent on whatever version of Perl the fixed Symbol module appeared in (5.8.1 at the earliest) because Symbol isn't distributed separately on CPAN. So maybe option five is the most practical. Steve --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org For additional commands, e-mail: dev-help@perl.apache.org