1 # -*- buffer-read-only: t -*-
2 # !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
3 # This file is built by regen/feature.pl.
4 # Any changes made here will be lost!
14 state => 'feature_state',
15 switch => 'feature_switch',
16 bitwise => 'feature_bitwise',
17 indirect => 'feature_indirect',
18 evalbytes => 'feature_evalbytes',
19 signatures => 'feature_signatures',
20 current_sub => 'feature___SUB__',
21 refaliasing => 'feature_refaliasing',
22 postderef_qq => 'feature_postderef_qq',
23 unicode_eval => 'feature_unieval',
24 declared_refs => 'feature_myref',
25 unicode_strings => 'feature_unicode',
28 our %feature_bundle = (
29 "5.10" => [qw(indirect say state switch)],
30 "5.11" => [qw(indirect say state switch unicode_strings)],
31 "5.15" => [qw(current_sub evalbytes fc indirect say state switch unicode_eval unicode_strings)],
32 "5.23" => [qw(current_sub evalbytes fc indirect postderef_qq say state switch unicode_eval unicode_strings)],
33 "5.27" => [qw(bitwise current_sub evalbytes fc indirect postderef_qq say state switch unicode_eval unicode_strings)],
34 "all" => [qw(bitwise current_sub declared_refs evalbytes fc indirect isa postderef_qq refaliasing say signatures state switch unicode_eval unicode_strings)],
35 "default" => [qw(indirect)],
38 $feature_bundle{"5.12"} = $feature_bundle{"5.11"};
39 $feature_bundle{"5.13"} = $feature_bundle{"5.11"};
40 $feature_bundle{"5.14"} = $feature_bundle{"5.11"};
41 $feature_bundle{"5.16"} = $feature_bundle{"5.15"};
42 $feature_bundle{"5.17"} = $feature_bundle{"5.15"};
43 $feature_bundle{"5.18"} = $feature_bundle{"5.15"};
44 $feature_bundle{"5.19"} = $feature_bundle{"5.15"};
45 $feature_bundle{"5.20"} = $feature_bundle{"5.15"};
46 $feature_bundle{"5.21"} = $feature_bundle{"5.15"};
47 $feature_bundle{"5.22"} = $feature_bundle{"5.15"};
48 $feature_bundle{"5.24"} = $feature_bundle{"5.23"};
49 $feature_bundle{"5.25"} = $feature_bundle{"5.23"};
50 $feature_bundle{"5.26"} = $feature_bundle{"5.23"};
51 $feature_bundle{"5.28"} = $feature_bundle{"5.27"};
52 $feature_bundle{"5.29"} = $feature_bundle{"5.27"};
53 $feature_bundle{"5.30"} = $feature_bundle{"5.27"};
54 $feature_bundle{"5.31"} = $feature_bundle{"5.27"};
55 $feature_bundle{"5.32"} = $feature_bundle{"5.27"};
56 $feature_bundle{"5.33"} = $feature_bundle{"5.27"};
57 $feature_bundle{"5.34"} = $feature_bundle{"5.27"};
58 $feature_bundle{"5.9.5"} = $feature_bundle{"5.10"};
68 our $hint_mask = 0x1c000000;
69 our @hint_bundles = qw( default 5.10 5.11 5.15 5.23 5.27 );
71 # This gets set (for now) in $^H as well as in %^H,
72 # for runtime speed of the uc/lc/ucfirst/lcfirst functions.
73 # See HINT_UNI_8_BIT in perl.h.
74 our $hint_uni8bit = 0x00000800;
77 # - think about versioned features (use feature switch => 2)
81 feature - Perl pragma to enable new features
85 use feature qw(say switch);
87 when (1) { say "\$foo == 1" }
88 when ([2,3]) { say "\$foo == 2 || \$foo == 3" }
89 when (/^a[bc]d$/) { say "\$foo eq 'abd' || \$foo eq 'acd'" }
90 when ($_ > 100) { say "\$foo > 100" }
91 default { say "None of the above" }
94 use feature ':5.10'; # loads all features available in perl 5.10
96 use v5.10; # implicitly loads :5.10 feature bundle
100 It is usually impossible to add new syntax to Perl without breaking
101 some existing programs. This pragma provides a way to minimize that
102 risk. New syntactic constructs, or new semantic meanings to older
103 constructs, can be enabled by C<use feature 'foo'>, and will be parsed
104 only when the appropriate feature pragma is in scope. (Nevertheless, the
105 C<CORE::> prefix provides access to all Perl keywords, regardless of this
108 =head2 Lexical effect
110 Like other pragmas (C<use strict>, for example), features have a lexical
111 effect. C<use feature qw(foo)> will only make the feature "foo" available
112 from that point to the end of the enclosing block.
116 say "say is available here";
118 print "But not here.\n";
122 Features can also be turned off by using C<no feature "foo">. This too
126 say "say is available here";
129 print "But not here.\n";
131 say "Yet it is here.";
133 C<no feature> with no features specified will reset to the default group. To
134 disable I<all> features (an unusual request!) use C<no feature ':all'>.
136 =head1 AVAILABLE FEATURES
138 =head2 The 'say' feature
140 C<use feature 'say'> tells the compiler to enable the Perl 6 style
143 See L<perlfunc/say> for details.
145 This feature is available starting with Perl 5.10.
147 =head2 The 'state' feature
149 C<use feature 'state'> tells the compiler to enable C<state>
152 See L<perlsub/"Persistent Private Variables"> for details.
154 This feature is available starting with Perl 5.10.
156 =head2 The 'switch' feature
158 B<WARNING>: Because the L<smartmatch operator|perlop/"Smartmatch Operator"> is
159 experimental, Perl will warn when you use this feature, unless you have
160 explicitly disabled the warning:
162 no warnings "experimental::smartmatch";
164 C<use feature 'switch'> tells the compiler to enable the Perl 6
165 given/when construct.
167 See L<perlsyn/"Switch Statements"> for details.
169 This feature is available starting with Perl 5.10.
171 =head2 The 'unicode_strings' feature
173 C<use feature 'unicode_strings'> tells the compiler to use Unicode rules
174 in all string operations executed within its scope (unless they are also
175 within the scope of either C<use locale> or C<use bytes>). The same applies
176 to all regular expressions compiled within the scope, even if executed outside
177 it. It does not change the internal representation of strings, but only how
178 they are interpreted.
180 C<no feature 'unicode_strings'> tells the compiler to use the traditional
181 Perl rules wherein the native character set rules is used unless it is
182 clear to Perl that Unicode is desired. This can lead to some surprises
183 when the behavior suddenly changes. (See
184 L<perlunicode/The "Unicode Bug"> for details.) For this reason, if you are
185 potentially using Unicode in your program, the
186 C<use feature 'unicode_strings'> subpragma is B<strongly> recommended.
188 This feature is available starting with Perl 5.12; was almost fully
189 implemented in Perl 5.14; and extended in Perl 5.16 to cover C<quotemeta>;
190 was extended further in Perl 5.26 to cover L<the range
191 operator|perlop/Range Operators>; and was extended again in Perl 5.28 to
192 cover L<special-cased whitespace splitting|perlfunc/split>.
194 =head2 The 'unicode_eval' and 'evalbytes' features
196 Together, these two features are intended to replace the legacy string
197 C<eval> function, which behaves problematically in some instances. They are
198 available starting with Perl 5.16, and are enabled by default by a
199 S<C<use 5.16>> or higher declaration.
201 C<unicode_eval> changes the behavior of plain string C<eval> to work more
202 consistently, especially in the Unicode world. Certain (mis)behaviors
203 couldn't be changed without breaking some things that had come to rely on
204 them, so the feature can be enabled and disabled. Details are at
205 L<perlfunc/Under the "unicode_eval" feature>.
207 C<evalbytes> is like string C<eval>, but operating on a byte stream that is
208 not UTF-8 encoded. Details are at L<perlfunc/evalbytes EXPR>. Without a
209 S<C<use feature 'evalbytes'>> nor a S<C<use v5.16>> (or higher) declaration in
210 the current scope, you can still access it by instead writing
213 =head2 The 'current_sub' feature
215 This provides the C<__SUB__> token that returns a reference to the current
216 subroutine or C<undef> outside of a subroutine.
218 This feature is available starting with Perl 5.16.
220 =head2 The 'array_base' feature
222 This feature supported the legacy C<$[> variable. See L<perlvar/$[>.
223 It was on by default but disabled under C<use v5.16> (see
224 L</IMPLICIT LOADING>, below) and unavailable since perl 5.30.
226 This feature is available under this name starting with Perl 5.16. In
227 previous versions, it was simply on all the time, and this pragma knew
230 =head2 The 'fc' feature
232 C<use feature 'fc'> tells the compiler to enable the C<fc> function,
233 which implements Unicode casefolding.
235 See L<perlfunc/fc> for details.
237 This feature is available from Perl 5.16 onwards.
239 =head2 The 'lexical_subs' feature
241 In Perl versions prior to 5.26, this feature enabled
242 declaration of subroutines via C<my sub foo>, C<state sub foo>
243 and C<our sub foo> syntax. See L<perlsub/Lexical Subroutines> for details.
245 This feature is available from Perl 5.18 onwards. From Perl 5.18 to 5.24,
246 it was classed as experimental, and Perl emitted a warning for its
247 usage, except when explicitly disabled:
249 no warnings "experimental::lexical_subs";
251 As of Perl 5.26, use of this feature no longer triggers a warning, though
252 the C<experimental::lexical_subs> warning category still exists (for
253 compatibility with code that disables it). In addition, this syntax is
254 not only no longer experimental, but it is enabled for all Perl code,
255 regardless of what feature declarations are in scope.
257 =head2 The 'postderef' and 'postderef_qq' features
259 The 'postderef_qq' feature extends the applicability of L<postfix
260 dereference syntax|perlref/Postfix Dereference Syntax> so that postfix array
261 and scalar dereference are available in double-quotish interpolations. For
262 example, it makes the following two statements equivalent:
264 my $s = "[@{ $h->{a} }]";
265 my $s = "[$h->{a}->@*]";
267 This feature is available from Perl 5.20 onwards. In Perl 5.20 and 5.22, it
268 was classed as experimental, and Perl emitted a warning for its
269 usage, except when explicitly disabled:
271 no warnings "experimental::postderef";
273 As of Perl 5.24, use of this feature no longer triggers a warning, though
274 the C<experimental::postderef> warning category still exists (for
275 compatibility with code that disables it).
277 The 'postderef' feature was used in Perl 5.20 and Perl 5.22 to enable
278 postfix dereference syntax outside double-quotish interpolations. In those
279 versions, using it triggered the C<experimental::postderef> warning in the
280 same way as the 'postderef_qq' feature did. As of Perl 5.24, this syntax is
281 not only no longer experimental, but it is enabled for all Perl code,
282 regardless of what feature declarations are in scope.
284 =head2 The 'signatures' feature
286 B<WARNING>: This feature is still experimental and the implementation may
287 change in future versions of Perl. For this reason, Perl will
288 warn when you use the feature, unless you have explicitly disabled the
291 no warnings "experimental::signatures";
293 This enables unpacking of subroutine arguments into lexical variables
296 sub foo ($left, $right) {
297 return $left + $right;
300 See L<perlsub/Signatures> for details.
302 This feature is available from Perl 5.20 onwards.
304 =head2 The 'refaliasing' feature
306 B<WARNING>: This feature is still experimental and the implementation may
307 change in future versions of Perl. For this reason, Perl will
308 warn when you use the feature, unless you have explicitly disabled the
311 no warnings "experimental::refaliasing";
313 This enables aliasing via assignment to references:
315 \$a = \$b; # $a and $b now point to the same scalar
316 \@a = \@b; # to the same array
319 foreach \%hash (@array_of_hash_refs) {
323 See L<perlref/Assigning to References> for details.
325 This feature is available from Perl 5.22 onwards.
327 =head2 The 'bitwise' feature
329 This makes the four standard bitwise operators (C<& | ^ ~>) treat their
330 operands consistently as numbers, and introduces four new dotted operators
331 (C<&. |. ^. ~.>) that treat their operands consistently as strings. The
332 same applies to the assignment variants (C<&= |= ^= &.= |.= ^.=>).
334 See L<perlop/Bitwise String Operators> for details.
336 This feature is available from Perl 5.22 onwards. Starting in Perl 5.28,
337 C<use v5.28> will enable the feature. Before 5.28, it was still
338 experimental and would emit a warning in the "experimental::bitwise"
341 =head2 The 'declared_refs' feature
343 B<WARNING>: This feature is still experimental and the implementation may
344 change in future versions of Perl. For this reason, Perl will
345 warn when you use the feature, unless you have explicitly disabled the
348 no warnings "experimental::declared_refs";
350 This allows a reference to a variable to be declared with C<my>, C<state>,
351 our C<our>, or localized with C<local>. It is intended mainly for use in
352 conjunction with the "refaliasing" feature. See L<perlref/Declaring a
353 Reference to a Variable> for examples.
355 This feature is available from Perl 5.26 onwards.
357 =head2 The 'isa' feature
359 This allows the use of the C<isa> infix operator, which tests whether the
360 scalar given by the left operand is an object of the class given by the
361 right operand. See L<perlop/Class Instance Operator> for more details.
363 This feature is available from Perl 5.32 onwards.
365 =head2 The 'indirect' feature
367 This feature allows the use of L<indirect object
368 syntax|perlobj/Indirect Object Syntax> for method calls, e.g. C<new
369 Foo 1, 2;>. It is enabled by default, but can be turned off to
370 disallow indirect object syntax.
372 This feature is available under this name from Perl 5.32 onwards. In
373 previous versions, it was simply on all the time. To disallow (or
374 warn on) indirect object syntax on older Perls, see the L<indirect>
377 =head1 FEATURE BUNDLES
379 It's possible to load multiple features together, using
380 a I<feature bundle>. The name of a feature bundle is prefixed with
381 a colon, to distinguish it from an actual feature.
385 The following feature bundles are available:
387 bundle features included
388 --------- -----------------
391 :5.10 indirect say state switch
393 :5.12 indirect say state switch unicode_strings
395 :5.14 indirect say state switch unicode_strings
397 :5.16 current_sub evalbytes fc indirect say state
398 switch unicode_eval unicode_strings
400 :5.18 current_sub evalbytes fc indirect say state
401 switch unicode_eval unicode_strings
403 :5.20 current_sub evalbytes fc indirect say state
404 switch unicode_eval unicode_strings
406 :5.22 current_sub evalbytes fc indirect say state
407 switch unicode_eval unicode_strings
409 :5.24 current_sub evalbytes fc indirect
410 postderef_qq say state switch unicode_eval
413 :5.26 current_sub evalbytes fc indirect
414 postderef_qq say state switch unicode_eval
417 :5.28 bitwise current_sub evalbytes fc indirect
418 postderef_qq say state switch unicode_eval
421 :5.30 bitwise current_sub evalbytes fc indirect
422 postderef_qq say state switch unicode_eval
425 :5.32 bitwise current_sub evalbytes fc indirect
426 postderef_qq say state switch unicode_eval
429 :5.34 bitwise current_sub evalbytes fc indirect
430 postderef_qq say state switch unicode_eval
433 The C<:default> bundle represents the feature set that is enabled before
434 any C<use feature> or C<no feature> declaration.
436 Specifying sub-versions such as the C<0> in C<5.14.0> in feature bundles has
437 no effect. Feature bundles are guaranteed to be the same for all sub-versions.
439 use feature ":5.14.0"; # same as ":5.14"
440 use feature ":5.14.1"; # same as ":5.14"
442 =head1 IMPLICIT LOADING
444 Instead of loading feature bundles by name, it is easier to let Perl do
445 implicit loading of a feature bundle for you.
447 There are two ways to load the C<feature> pragma implicitly:
453 By using the C<-E> switch on the Perl command-line instead of C<-e>.
454 That will enable the feature bundle for that version of Perl in the
455 main compilation unit (that is, the one-liner that follows C<-E>).
459 By explicitly requiring a minimum Perl version number for your program, with
460 the C<use VERSION> construct. That is,
469 and so on. Note how the trailing sub-version
470 is automatically stripped from the
473 But to avoid portability warnings (see L<perlfunc/use>), you may prefer:
477 with the same effect.
479 If the required version is older than Perl 5.10, the ":default" feature
480 bundle is automatically loaded instead.
482 Unlike C<use feature ":5.12">, saying C<use v5.12> (or any higher version)
483 also does the equivalent of C<use strict>; see L<perlfunc/use> for details.
493 croak("No features specified");
502 # A bare C<no feature> should reset to the default bundle
504 $^H &= ~($hint_uni8bit|$hint_mask);
514 my $bundle_number = $^H & $hint_mask;
515 my $features = $bundle_number != $hint_mask
516 && $feature_bundle{$hint_bundles[$bundle_number >> $hint_shift]};
518 # Features are enabled implicitly via bundle hints.
519 # Delete any keys that may be left over from last time.
520 delete @^H{ values(%feature) };
523 $^H{$feature{$_}} = 1;
524 $^H |= $hint_uni8bit if $_ eq 'unicode_strings';
529 if (substr($name, 0, 1) eq ":") {
530 my $v = substr($name, 1);
531 if (!exists $feature_bundle{$v}) {
532 $v =~ s/^([0-9]+)\.([0-9]+).[0-9]+$/$1.$2/;
533 if (!exists $feature_bundle{$v}) {
534 unknown_feature_bundle(substr($name, 1));
537 unshift @_, @{$feature_bundle{$v}};
540 if (!exists $feature{$name}) {
541 if (exists $noops{$name}) {
544 if (!$import && exists $removed{$name}) {
547 unknown_feature($name);
550 $^H{$feature{$name}} = 1;
551 $^H |= $hint_uni8bit if $name eq 'unicode_strings';
553 delete $^H{$feature{$name}};
554 $^H &= ~ $hint_uni8bit if $name eq 'unicode_strings';
559 sub unknown_feature {
561 croak(sprintf('Feature "%s" is not supported by Perl %vd',
565 sub unknown_feature_bundle {
567 croak(sprintf('Feature bundle "%s" is not supported by Perl %vd',