From: Father Chrysostomos Date: Tue, 13 Apr 2010 15:20:19 +0000 (+0200) Subject: [perl #73712] ‘Variable is not imported’ cannot be suppressed X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=413ff9f68feafcc9f84f1fbb43e6d6aa91adce9d;p=p5sagit%2Fp5-mst-13.2.git [perl #73712] ‘Variable is not imported’ cannot be suppressed The message ‘Variable "%s" is not imported’ cannot be suppressed, even with -X (local $SIG{__WARN__}=sub{} is what I have to use): perl -Xle '$foo;use strict; eval q/$foo/ or die "---$@---"' Variable "$foo" is not imported at (eval 1) line 2. ---Global symbol "$foo" requires explicit package name at (eval 1) line 2. --- at -e line 1. This is because we have what appears to the user to be a multi-line error message. It is in fact a warning ‘Variable...’ followed by an error ‘Global symbol...’. The attached patch assigns a warning category to the warning. --- diff --git a/gv.c b/gv.c index 060d8e6..3412c9a 100644 --- a/gv.c +++ b/gv.c @@ -1061,12 +1061,17 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags, (sv_type == SVt_PVHV && !GvIMPORTED_HV(*gvp)) ) { /* diag_listed_as: Variable "%s" is not imported%s */ - Perl_warn(aTHX_ "Variable \"%c%s\" is not imported", + Perl_ck_warner_d( + aTHX_ packWARN(WARN_MISC), + "Variable \"%c%s\" is not imported", sv_type == SVt_PVAV ? '@' : sv_type == SVt_PVHV ? '%' : '$', name); if (GvCVu(*gvp)) - Perl_warn(aTHX_ "\t(Did you mean &%s instead?)\n", name); + Perl_ck_warner_d( + aTHX_ packWARN(WARN_MISC), + "\t(Did you mean &%s instead?)\n", name + ); stash = NULL; } } diff --git a/pod/perldiag.pod b/pod/perldiag.pod index f0695ea..4e9f04b 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -1500,8 +1500,8 @@ do. See L. =item (Did you mean &%s instead?) -(W) You probably referred to an imported subroutine &FOO as $FOO or some -such. +(W misc) You probably referred to an imported subroutine &FOO as $FOO or +some such. =item (Did you mean "local" instead of "our"?) @@ -5094,8 +5094,8 @@ executed, so its $a is not available for capture. =item Variable "%s" is not imported%s -(F) While "use strict" in effect, you referred to a global variable that -you apparently thought was imported from another module, because +(W misc) With "use strict" in effect, you referred to a global variable +that you apparently thought was imported from another module, because something else of the same name (usually a subroutine) is exported by that module. It usually means you put the wrong funny character on the front of your variable. diff --git a/t/lib/strict/vars b/t/lib/strict/vars index 16deab9..87f820f 100644 --- a/t/lib/strict/vars +++ b/t/lib/strict/vars @@ -439,3 +439,10 @@ qr/(?{$foo++})/; EXPECT Global symbol "$foo" requires explicit package name at (re_eval 1) line 1. Compilation failed in regexp at - line 3. +######## +# [perl #73712] 'Variable is not imported' should be suppressable +$dweck; +use strict 'vars'; +no warnings; +eval q/$dweck/; +EXPECT