New [PATCH] use 5.006; use 5.10.0
authorRobin Barker <RMBarker@cpan.org>
Fri, 5 Oct 2007 12:12:05 +0000 (13:12 +0100)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Fri, 5 Oct 2007 11:45:25 +0000 (11:45 +0000)
From: "Robin Barker" <Robin.Barker@npl.co.uk>
Message-ID: <2C2E01334A940D4792B3E115F95B7226016048DB@exchsvr1.npl.ad.local>

p4raw-id: //depot/perl@32031

pod/perldiag.pod
pod/perlfunc.pod
pp_ctl.c
t/lib/warnings/pp_ctl

index 1c5128a..5286fbe 100644 (file)
@@ -4943,6 +4943,9 @@ won't suddenly start understanding newer features, but at least
 they will show a sensible error message indicating the required
 minimum version.
 
+This warning is suppressed if the C<use 5.x.y> is preceded by a
+C<use 5.006> (see C<use VERSION> in L<perlfunc/use>).
+
 =item Warning: something's wrong
 
 (W) You passed warn() an empty string (the equivalent of C<warn "">) or
index e6f6cc4..f3454b4 100644 (file)
@@ -6853,9 +6853,15 @@ avoided, because it leads to misleading error messages under earlier
 versions of Perl that do not support this syntax.  The equivalent numeric
 version should be used instead.
 
+Alternatively, you can use a numeric version C<use 5.006> followed by a
+v-string version like C<use v5.10.1>, to avoid the unintuitive C<use
+5.010_001>. (older perl versions fail gracefully at the first C<use>,
+later perl versions understand the v-string syntax in the second).
+
     use v5.6.1;                # compile time version check
     use 5.6.1;         # ditto
     use 5.006_001;     # ditto; preferred for backwards compatibility
+    use 5.006; use 5.6.1;      # ditto, for compatibility and readability
 
 This is often useful if you need to check the current Perl version before
 C<use>ing library modules that have changed in incompatible ways from
index b512686..7f37b75 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3080,10 +3080,14 @@ PP(pp_require)
 
     sv = POPs;
     if ( (SvNIOKp(sv) || SvVOK(sv)) && PL_op->op_type != OP_DOFILE) {
-       if ( SvVOK(sv) && ckWARN(WARN_PORTABLE) )       /* require v5.6.1 */
+       if ( SvVOK(sv) && ckWARN(WARN_PORTABLE) ) {     /* require v5.6.1 */
+           HV * hinthv = GvHV(PL_hintgv);
+           SV ** ptr = NULL;
+           if (hinthv) ptr = hv_fetchs(hinthv, "v_string", FALSE);
+           if ( !(ptr && *ptr && SvIOK(*ptr) && SvIV(*ptr)) )
                Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
                         "v-string in use/require non-portable");
-
+       }
        sv = new_version(sv);
        if (!sv_derived_from(PL_patchlevel, "version"))
            upg_version(PL_patchlevel, TRUE);
@@ -3133,15 +3137,25 @@ PP(pp_require)
            }
        }
 
-       /* If we request a version >= 5.9.5, load feature.pm with the
-        * feature bundle that corresponds to the required version.
-        * We do this only with use, not require. */
-       if (PL_compcv && vcmp(sv, sv_2mortal(upg_version(newSVnv(5.009005), FALSE))) >= 0) {
+        /* We do this only with use, not require. */
+       if (PL_compcv &&
+         /* If we request a version >= 5.6.0, then v-string are OK
+            so set $^H{v_string} to suppress the v-string warning */
+           vcmp(sv, sv_2mortal(upg_version(newSVnv(5.006), FALSE))) >= 0) {
+         HV * hinthv = GvHV(PL_hintgv);
+         if( hinthv ) {
+           (void)hv_stores(hinthv, "v_string", newSViv(1));
+           PL_hints |= HINT_LOCALIZE_HH;
+         }
+         /* If we request a version >= 5.9.5, load feature.pm with the
+          * feature bundle that corresponds to the required version. */
+         if (vcmp(sv, sv_2mortal(upg_version(newSVnv(5.009005), FALSE))) >= 0) {
            SV *const importsv = vnormal(sv);
            *SvPVX_mutable(importsv) = ':';
            ENTER;
            Perl_load_module(aTHX_ 0, newSVpvs("feature"), NULL, importsv, NULL);
            LEAVE;
+         }
        }
 
        RETPUSHYES;
index d27e896..923d54c 100644 (file)
@@ -240,3 +240,20 @@ use warnings;
     eval 'print $foo';
 }
 EXPECT
+########
+# pp_ctl.c
+use warnings;
+eval 'use 5.006; use 5.10.0';
+EXPECT
+########
+# pp_ctl.c
+use warnings;
+eval '{use 5.006;} use 5.10.0';
+EXPECT
+v-string in use/require non-portable at (eval 1) line 2.
+########
+# pp_ctl.c
+use warnings;
+eval 'use vars; use 5.10.0';
+EXPECT
+v-string in use/require non-portable at (eval 1) line 2.