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!
13 state => 'feature_state',
14 switch => 'feature_switch',
15 bitwise => 'feature_bitwise',
16 evalbytes => 'feature_evalbytes',
17 array_base => 'feature_arybase',
18 signatures => 'feature_signatures',
19 current_sub => 'feature___SUB__',
20 refaliasing => 'feature_refaliasing',
21 postderef_qq => 'feature_postderef_qq',
22 unicode_eval => 'feature_unieval',
23 declared_refs => 'feature_myref',
24 unicode_strings => 'feature_unicode',
27 our %feature_bundle = (
28 "5.10" => [qw(array_base say state switch)],
29 "5.11" => [qw(array_base say state switch unicode_strings)],
30 "5.15" => [qw(current_sub evalbytes fc say state switch unicode_eval unicode_strings)],
31 "5.23" => [qw(current_sub evalbytes fc postderef_qq say state switch unicode_eval unicode_strings)],
32 "all" => [qw(array_base bitwise current_sub declared_refs evalbytes fc postderef_qq refaliasing say signatures state switch unicode_eval unicode_strings)],
33 "default" => [qw(array_base)],
36 $feature_bundle{"5.12"} = $feature_bundle{"5.11"};
37 $feature_bundle{"5.13"} = $feature_bundle{"5.11"};
38 $feature_bundle{"5.14"} = $feature_bundle{"5.11"};
39 $feature_bundle{"5.16"} = $feature_bundle{"5.15"};
40 $feature_bundle{"5.17"} = $feature_bundle{"5.15"};
41 $feature_bundle{"5.18"} = $feature_bundle{"5.15"};
42 $feature_bundle{"5.19"} = $feature_bundle{"5.15"};
43 $feature_bundle{"5.20"} = $feature_bundle{"5.15"};
44 $feature_bundle{"5.21"} = $feature_bundle{"5.15"};
45 $feature_bundle{"5.22"} = $feature_bundle{"5.15"};
46 $feature_bundle{"5.24"} = $feature_bundle{"5.23"};
47 $feature_bundle{"5.25"} = $feature_bundle{"5.23"};
48 $feature_bundle{"5.26"} = $feature_bundle{"5.23"};
49 $feature_bundle{"5.9.5"} = $feature_bundle{"5.10"};
56 our $hint_mask = 0x1c000000;
57 our @hint_bundles = qw( default 5.10 5.11 5.15 5.23 );
59 # This gets set (for now) in $^H as well as in %^H,
60 # for runtime speed of the uc/lc/ucfirst/lcfirst functions.
61 # See HINT_UNI_8_BIT in perl.h.
62 our $hint_uni8bit = 0x00000800;
65 # - think about versioned features (use feature switch => 2)
69 feature - Perl pragma to enable new features
73 use feature qw(say switch);
75 when (1) { say "\$foo == 1" }
76 when ([2,3]) { say "\$foo == 2 || \$foo == 3" }
77 when (/^a[bc]d$/) { say "\$foo eq 'abd' || \$foo eq 'acd'" }
78 when ($_ > 100) { say "\$foo > 100" }
79 default { say "None of the above" }
82 use feature ':5.10'; # loads all features available in perl 5.10
84 use v5.10; # implicitly loads :5.10 feature bundle
88 It is usually impossible to add new syntax to Perl without breaking
89 some existing programs. This pragma provides a way to minimize that
90 risk. New syntactic constructs, or new semantic meanings to older
91 constructs, can be enabled by C<use feature 'foo'>, and will be parsed
92 only when the appropriate feature pragma is in scope. (Nevertheless, the
93 C<CORE::> prefix provides access to all Perl keywords, regardless of this
98 Like other pragmas (C<use strict>, for example), features have a lexical
99 effect. C<use feature qw(foo)> will only make the feature "foo" available
100 from that point to the end of the enclosing block.
104 say "say is available here";
106 print "But not here.\n";
110 Features can also be turned off by using C<no feature "foo">. This too
114 say "say is available here";
117 print "But not here.\n";
119 say "Yet it is here.";
121 C<no feature> with no features specified will reset to the default group. To
122 disable I<all> features (an unusual request!) use C<no feature ':all'>.
124 =head1 AVAILABLE FEATURES
126 =head2 The 'say' feature
128 C<use feature 'say'> tells the compiler to enable the Perl 6 style
131 See L<perlfunc/say> for details.
133 This feature is available starting with Perl 5.10.
135 =head2 The 'state' feature
137 C<use feature 'state'> tells the compiler to enable C<state>
140 See L<perlsub/"Persistent Private Variables"> for details.
142 This feature is available starting with Perl 5.10.
144 =head2 The 'switch' feature
146 B<WARNING>: Because the L<smartmatch operator|perlop/"Smartmatch Operator"> is
147 experimental, Perl will warn when you use this feature, unless you have
148 explicitly disabled the warning:
150 no warnings "experimental::smartmatch";
152 C<use feature 'switch'> tells the compiler to enable the Perl 6
153 given/when construct.
155 See L<perlsyn/"Switch Statements"> for details.
157 This feature is available starting with Perl 5.10.
159 =head2 The 'unicode_strings' feature
161 C<use feature 'unicode_strings'> tells the compiler to use Unicode rules
162 in all string operations executed within its scope (unless they are also
163 within the scope of either C<use locale> or C<use bytes>). The same applies
164 to all regular expressions compiled within the scope, even if executed outside
165 it. It does not change the internal representation of strings, but only how
166 they are interpreted.
168 C<no feature 'unicode_strings'> tells the compiler to use the traditional
169 Perl rules wherein the native character set rules is used unless it is
170 clear to Perl that Unicode is desired. This can lead to some surprises
171 when the behavior suddenly changes. (See
172 L<perlunicode/The "Unicode Bug"> for details.) For this reason, if you are
173 potentially using Unicode in your program, the
174 C<use feature 'unicode_strings'> subpragma is B<strongly> recommended.
176 This feature is available starting with Perl 5.12; was almost fully
177 implemented in Perl 5.14; and extended in Perl 5.16 to cover C<quotemeta>.
179 =head2 The 'unicode_eval' and 'evalbytes' features
181 Under the C<unicode_eval> feature, Perl's C<eval> function, when passed a
182 string, will evaluate it as a string of characters, ignoring any
183 C<use utf8> declarations. C<use utf8> exists to declare the encoding of
184 the script, which only makes sense for a stream of bytes, not a string of
185 characters. Source filters are forbidden, as they also really only make
186 sense on strings of bytes. Any attempt to activate a source filter will
189 The C<evalbytes> feature enables the C<evalbytes> keyword, which evaluates
190 the argument passed to it as a string of bytes. It dies if the string
191 contains any characters outside the 8-bit range. Source filters work
192 within C<evalbytes>: they apply to the contents of the string being
195 Together, these two features are intended to replace the historical C<eval>
196 function, which has (at least) two bugs in it, that cannot easily be fixed
197 without breaking existing programs:
203 C<eval> behaves differently depending on the internal encoding of the
204 string, sometimes treating its argument as a string of bytes, and sometimes
205 as a string of characters.
209 Source filters activated within C<eval> leak out into whichever I<file>
210 scope is currently being compiled. To give an example with the CPAN module
213 BEGIN { eval "use Semi::Semicolons; # not filtered here " }
216 C<evalbytes> fixes that to work the way one would expect:
218 use feature "evalbytes";
219 BEGIN { evalbytes "use Semi::Semicolons; # filtered " }
224 These two features are available starting with Perl 5.16.
226 =head2 The 'current_sub' feature
228 This provides the C<__SUB__> token that returns a reference to the current
229 subroutine or C<undef> outside of a subroutine.
231 This feature is available starting with Perl 5.16.
233 =head2 The 'array_base' feature
235 This feature supports the legacy C<$[> variable. See L<perlvar/$[> and
236 L<arybase>. It is on by default but disabled under C<use v5.16> (see
237 L</IMPLICIT LOADING>, below).
239 This feature is available under this name starting with Perl 5.16. In
240 previous versions, it was simply on all the time, and this pragma knew
243 =head2 The 'fc' feature
245 C<use feature 'fc'> tells the compiler to enable the C<fc> function,
246 which implements Unicode casefolding.
248 See L<perlfunc/fc> for details.
250 This feature is available from Perl 5.16 onwards.
252 =head2 The 'lexical_subs' feature
254 In Perl versions prior to 5.26, this feature enabled
255 declaration of subroutines via C<my sub foo>, C<state sub foo>
256 and C<our sub foo> syntax. See L<perlsub/Lexical Subroutines> for details.
258 This feature is available from Perl 5.18 onwards. From Perl 5.18 to 5.24,
259 it was classed as experimental, and Perl emitted a warning for its
260 usage, except when explicitly disabled:
262 no warnings "experimental::lexical_subs";
264 As of Perl 5.26, use of this feature no longer triggers a warning, though
265 the C<experimental::lexical_subs> warning category still exists (for
266 compatibility with code that disables it). In addition, this syntax is
267 not only no longer experimental, but it is enabled for all Perl code,
268 regardless of what feature declarations are in scope.
270 =head2 The 'postderef' and 'postderef_qq' features
272 The 'postderef_qq' feature extends the applicability of L<postfix
273 dereference syntax|perlref/Postfix Dereference Syntax> so that postfix array
274 and scalar dereference are available in double-quotish interpolations. For
275 example, it makes the following two statements equivalent:
277 my $s = "[@{ $h->{a} }]";
278 my $s = "[$h->{a}->@*]";
280 This feature is available from Perl 5.20 onwards. In Perl 5.20 and 5.22, it
281 was classed as experimental, and Perl emitted a warning for its
282 usage, except when explicitly disabled:
284 no warnings "experimental::postderef";
286 As of Perl 5.24, use of this feature no longer triggers a warning, though
287 the C<experimental::postderef> warning category still exists (for
288 compatibility with code that disables it).
290 The 'postderef' feature was used in Perl 5.20 and Perl 5.22 to enable
291 postfix dereference syntax outside double-quotish interpolations. In those
292 versions, using it triggered the C<experimental::postderef> warning in the
293 same way as the 'postderef_qq' feature did. As of Perl 5.24, this syntax is
294 not only no longer experimental, but it is enabled for all Perl code,
295 regardless of what feature declarations are in scope.
297 =head2 The 'signatures' feature
299 B<WARNING>: This feature is still experimental and the implementation may
300 change in future versions of Perl. For this reason, Perl will
301 warn when you use the feature, unless you have explicitly disabled the
304 no warnings "experimental::signatures";
306 This enables unpacking of subroutine arguments into lexical variables
309 sub foo ($left, $right) {
310 return $left + $right;
313 See L<perlsub/Signatures> for details.
315 This feature is available from Perl 5.20 onwards.
317 =head2 The 'refaliasing' feature
319 B<WARNING>: This feature is still experimental and the implementation may
320 change in future versions of Perl. For this reason, Perl will
321 warn when you use the feature, unless you have explicitly disabled the
324 no warnings "experimental::refaliasing";
326 This enables aliasing via assignment to references:
328 \$a = \$b; # $a and $b now point to the same scalar
329 \@a = \@b; # to the same array
332 foreach \%hash (@array_of_hash_refs) {
336 See L<perlref/Assigning to References> for details.
338 This feature is available from Perl 5.22 onwards.
340 =head2 The 'bitwise' feature
342 B<WARNING>: This feature is still experimental and the implementation may
343 change in future versions of Perl. For this reason, Perl will
344 warn when you use the feature, unless you have explicitly disabled the
347 no warnings "experimental::bitwise";
349 This makes the four standard bitwise operators (C<& | ^ ~>) treat their
350 operands consistently as numbers, and introduces four new dotted operators
351 (C<&. |. ^. ~.>) that treat their operands consistently as strings. The
352 same applies to the assignment variants (C<&= |= ^= &.= |.= ^.=>).
354 See L<perlop/Bitwise String Operators> for details.
356 This feature is available from Perl 5.22 onwards.
358 =head2 The 'declared_refs' feature
360 B<WARNING>: This feature is still experimental and the implementation may
361 change in future versions of Perl. For this reason, Perl will
362 warn when you use the feature, unless you have explicitly disabled the
365 no warnings "experimental::declared_refs";
367 This allows a reference to a variable to be declared with C<my>, C<state>,
368 our C<our>, or localized with C<local>. It is intended mainly for use in
369 conjunction with the "refaliasing" feature. See L<perlref/Declaring a
370 Reference to a Variable> for examples.
372 This feature is available from Perl 5.26 onwards.
374 =head1 FEATURE BUNDLES
376 It's possible to load multiple features together, using
377 a I<feature bundle>. The name of a feature bundle is prefixed with
378 a colon, to distinguish it from an actual feature.
382 The following feature bundles are available:
384 bundle features included
385 --------- -----------------
388 :5.10 say state switch array_base
390 :5.12 say state switch unicode_strings array_base
392 :5.14 say state switch unicode_strings array_base
394 :5.16 say state switch unicode_strings
395 unicode_eval evalbytes current_sub fc
397 :5.18 say state switch unicode_strings
398 unicode_eval evalbytes current_sub fc
400 :5.20 say state switch unicode_strings
401 unicode_eval evalbytes current_sub fc
403 :5.22 say state switch unicode_strings
404 unicode_eval evalbytes current_sub fc
406 :5.24 say state switch unicode_strings
407 unicode_eval evalbytes current_sub fc
410 :5.26 say state switch unicode_strings
411 unicode_eval evalbytes current_sub fc
414 The C<:default> bundle represents the feature set that is enabled before
415 any C<use feature> or C<no feature> declaration.
417 Specifying sub-versions such as the C<0> in C<5.14.0> in feature bundles has
418 no effect. Feature bundles are guaranteed to be the same for all sub-versions.
420 use feature ":5.14.0"; # same as ":5.14"
421 use feature ":5.14.1"; # same as ":5.14"
423 =head1 IMPLICIT LOADING
425 Instead of loading feature bundles by name, it is easier to let Perl do
426 implicit loading of a feature bundle for you.
428 There are two ways to load the C<feature> pragma implicitly:
434 By using the C<-E> switch on the Perl command-line instead of C<-e>.
435 That will enable the feature bundle for that version of Perl in the
436 main compilation unit (that is, the one-liner that follows C<-E>).
440 By explicitly requiring a minimum Perl version number for your program, with
441 the C<use VERSION> construct. That is,
450 and so on. Note how the trailing sub-version
451 is automatically stripped from the
454 But to avoid portability warnings (see L<perlfunc/use>), you may prefer:
458 with the same effect.
460 If the required version is older than Perl 5.10, the ":default" feature
461 bundle is automatically loaded instead.
471 croak("No features specified");
480 # A bare C<no feature> should reset to the default bundle
482 $^H &= ~($hint_uni8bit|$hint_mask);
492 my $bundle_number = $^H & $hint_mask;
493 my $features = $bundle_number != $hint_mask
494 && $feature_bundle{$hint_bundles[$bundle_number >> $hint_shift]};
496 # Features are enabled implicitly via bundle hints.
497 # Delete any keys that may be left over from last time.
498 delete @^H{ values(%feature) };
501 $^H{$feature{$_}} = 1;
502 $^H |= $hint_uni8bit if $_ eq 'unicode_strings';
507 if (substr($name, 0, 1) eq ":") {
508 my $v = substr($name, 1);
509 if (!exists $feature_bundle{$v}) {
510 $v =~ s/^([0-9]+)\.([0-9]+).[0-9]+$/$1.$2/;
511 if (!exists $feature_bundle{$v}) {
512 unknown_feature_bundle(substr($name, 1));
515 unshift @_, @{$feature_bundle{$v}};
518 if (!exists $feature{$name}) {
519 if (exists $noops{$name}) {
522 unknown_feature($name);
525 $^H{$feature{$name}} = 1;
526 $^H |= $hint_uni8bit if $name eq 'unicode_strings';
528 delete $^H{$feature{$name}};
529 $^H &= ~ $hint_uni8bit if $name eq 'unicode_strings';
534 sub unknown_feature {
536 croak(sprintf('Feature "%s" is not supported by Perl %vd',
540 sub unknown_feature_bundle {
542 croak(sprintf('Feature bundle "%s" is not supported by Perl %vd',