t/lib/dprof/test8_v Perl code profiler tests
t/lib/dprof/V.pm Perl code profiler tests
t/lib/feature/err Tests for enabling/disabling err feature
+t/lib/feature/implicit Tests for implicit loading of feature.pm
t/lib/feature/nonesuch Tests for enabling/disabling nonexistent feature
t/lib/feature/say Tests for enabling/disabling say feature
t/lib/feature/switch Tests for enabling/disabling switch feature
$feature_bundle{"5.10"} = $feature_bundle{"5.10.0"};
#$feature_bundle{"5.10"} = $feature_bundle{sprintf("%vd",$^V)};
+$feature_bundle{"5.9.5"} = $feature_bundle{"5.10.0"};
+
# TODO:
# - think about versioned features (use feature switch => 2)
In the forthcoming 5.10.X perl releases, C<use feature ":5.10"> will be
equivalent to the latest C<use feature ":5.10.X">.
+=head1 IMPLICIT LOADING
+
+There are two ways to load the C<feature> pragma implicitly :
+
+=over 4
+
+=item *
+
+By using the C<-E> switch on the command-line instead of C<-e>. It enables
+all available features in the main compilation unit (that is, the one-liner.)
+
+=item *
+
+By requiring explicitly a minimal Perl version number for your program, with
+the C<use VERSION> construct, and when the version is higher than or equal to
+5.9.5. That is,
+
+ use 5.9.5;
+
+will do an implicit
+
+ use feature ':5.9.5';
+
+and so on.
+
+=back
+
=cut
sub import {
VERSION may be either a numeric argument such as 5.006, which will be
compared to C<$]>, or a literal of the form v5.6.1, which will be compared
-to C<$^V> (aka $PERL_VERSION. A fatal error is produced if VERSION is
+to C<$^V> (aka $PERL_VERSION). A fatal error is produced if VERSION is
greater than the version of the current Perl interpreter; Perl will not
attempt to parse the rest of the file. Compare with L</require>, which can
do a similar check at run time.
C<use>ing library modules that have changed in incompatible ways from
older versions of Perl. (We try not to do this more than we have to.)
+If the specified perl version is greater than or equal to 5.9.5, C<use
+VERSION> will also load the C<feature> pragma and enable all features
+available in the requested version. See L<feature>.
+
The C<BEGIN> forces the C<require> and C<import> to happen at compile time. The
C<require> makes sure the module is loaded into memory if it hasn't been
yet. The C<import> is not a builtin--it's just an ordinary static method
SVfARG(vnormal(sv)), SVfARG(vnormal(PL_patchlevel)));
}
- RETPUSHYES;
+ /* 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)))) >= 0) {
+ SV *const importsv = vnormal(sv);
+ *SvPVX_mutable(importsv) = ':';
+ ENTER;
+ Perl_load_module(aTHX_ 0, newSVpvs("feature"), NULL, importsv, NULL);
+ LEAVE;
+ }
+
+ RETPUSHYES;
}
name = SvPV_const(sv, len);
if (!(name && len > 0 && *name))
--- /dev/null
+Check implicit loading of features with use VERSION.
+
+__END__
+# Standard feature bundle
+use feature ":5.10";
+say "Hello", "world";
+EXPECT
+Helloworld
+########
+# VERSION requirement, dotted notation
+use 5.9.5;
+say "Hello", "world";
+EXPECT
+Helloworld
+########
+# VERSION requirement, v-dotted notation
+use v5.9.5;
+say "Hello", "world";
+EXPECT
+Helloworld
+########
+# VERSION requirement, decimal notation
+use 5.009005;
+say defined $INC{"feature.pm"} ? "Helloworld" : "Good bye";
+EXPECT
+Helloworld
+########
+# VERSION requirement, doesn't load anything for < 5.9.5
+use 5.8.8;
+print "<".$INC{"feature.pm"}.">\n";
+EXPECT
+<>
+########
+# VERSION requirement, doesn't load anything with require
+require 5.9.5;
+print "<".$INC{"feature.pm"}.">\n";
+EXPECT
+<>
+########
+# VERSION requirement in eval {}
+eval {
+ use 5.9.5;
+ say "Hello", "world";
+}
+EXPECT
+Helloworld
+########
+# VERSION requirement in eval ""
+eval q{
+ use 5.9.5;
+ say "Hello", "world";
+}
+EXPECT
+Helloworld
+########
+# VERSION requirement in BEGIN
+BEGIN {
+ use 5.9.5;
+ say "Hello", "world";
+}
+EXPECT
+Helloworld