You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2003/12/19 03:28:02 UTC

[mp2] not being able to shutdown 'redefined' warnings in PerlRun

When running:

modperl-2.0/ModPerl-Registry> t/TEST perlrun_require

I get

   Subroutine whatever redefined at .../t/cgi-bin/lib.pl line 2.

warnings. I know why do we get this warning, but I fail to shut it down by 
adding: no warnings 'redefine' in t/cgi-bin/perlrun_require.pl:

Index: t/cgi-bin/perlrun_require.pl
===================================================================
RCS file: /home/cvs/modperl-2.0/ModPerl-Registry/t/cgi-bin/perlrun_require.pl,v
retrieving revision 1.1
diff -u -r1.1 perlrun_require.pl
--- t/cgi-bin/perlrun_require.pl        6 Jan 2003 10:42:38 -0000       1.1
+++ t/cgi-bin/perlrun_require.pl        19 Dec 2003 02:12:08 -0000
@@ -6,7 +6,11 @@
  my $vars = Apache::Test::config()->{vars};
  my $require = catfile $vars->{serverroot}, 'cgi-bin', 'lib.pl';

-require $require;
+# ModPerl::PerlRun resets %INC, after compiling the script
+{
+    no warnings 'redefine';
+    require $require;
+}

  print "Content-type: text/plain\n\n";


it still warns. Only if I add this directive to the required file the warning 
disappears:

Index: t/cgi-bin/lib.pl
===================================================================
RCS file: /home/cvs/modperl-2.0/ModPerl-Registry/t/cgi-bin/lib.pl,v
retrieving revision 1.1
diff -u -r1.1 lib.pl
--- t/cgi-bin/lib.pl    6 Jan 2003 10:42:38 -0000       1.1
+++ t/cgi-bin/lib.pl    19 Dec 2003 02:13:58 -0000
@@ -1,2 +1,3 @@
-sub whatever { return 1;}
+no warnings 'redefine';
+sub whatever { return 1; }
  1;

something weird is going on.

I'd have thought that perl may have decided this is a constant sub, but it's 
not (no () proto) and warning doesn't say it's a constant... Hints?

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] not being able to shutdown 'redefined' warnings in PerlRun

Posted by Stas Bekman <st...@stason.org>.
Answering my own question:

Stas Bekman wrote:
> When running:
> 
> modperl-2.0/ModPerl-Registry> t/TEST perlrun_require
> 
> I get
> 
>   Subroutine whatever redefined at .../t/cgi-bin/lib.pl line 2.
> 
> warnings. I know why do we get this warning, but I fail to shut it down 
> by adding: no warnings 'redefine' in t/cgi-bin/perlrun_require.pl:
> 
> Index: t/cgi-bin/perlrun_require.pl
> ===================================================================
> RCS file: 
> /home/cvs/modperl-2.0/ModPerl-Registry/t/cgi-bin/perlrun_require.pl,v
> retrieving revision 1.1
> diff -u -r1.1 perlrun_require.pl
> --- t/cgi-bin/perlrun_require.pl        6 Jan 2003 10:42:38 -0000       1.1
> +++ t/cgi-bin/perlrun_require.pl        19 Dec 2003 02:12:08 -0000
> @@ -6,7 +6,11 @@
>  my $vars = Apache::Test::config()->{vars};
>  my $require = catfile $vars->{serverroot}, 'cgi-bin', 'lib.pl';
> 
> -require $require;
> +# ModPerl::PerlRun resets %INC, after compiling the script
> +{
> +    no warnings 'redefine';
> +    require $require;
> +}

the reason for 'redefining' warnings:

subs redefined inside the required file w/o a package declaration, were 
redefined inside the main:: package. so while perlrun was flushing the virtual 
(per-script) namespace it wasn't (and is not) flushing the main:: namespace.

the reason for not being able to shutdown those warnings, is that the 
'warnings' pragma doesn't affect required files. Could have used $^W, but then 
it'll affect the scripts which may have wanted to have warnings on, relying on 
the server global (PerlWarn On|-w). So users will have to shutdown those 
warnings themselves if they get any.

the only remaining problem is constants which you can't shutdown. But again, 
perlrun can't do much about it and probably shouldn't.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org