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 postderef => 'feature_postderef',
18 array_base => 'feature_arybase',
19 signatures => 'feature_signatures',
20 current_sub => 'feature___SUB__',
21 refaliasing => 'feature_refaliasing',
22 lexical_subs => 'feature_lexsubs',
23 postderef_qq => 'feature_postderef_qq',
24 unicode_eval => 'feature_unieval',
25 unicode_strings => 'feature_unicode',
28 our %feature_bundle = (
29 "5.10" => [qw(array_base say state switch)],
30 "5.11" => [qw(array_base say state switch unicode_strings)],
31 "5.15" => [qw(current_sub evalbytes fc say state switch unicode_eval unicode_strings)],
32 "5.23" => [qw(current_sub evalbytes fc postderef_qq say state switch unicode_eval unicode_strings)],
33 "all" => [qw(array_base bitwise current_sub evalbytes fc lexical_subs postderef postderef_qq refaliasing say signatures state switch unicode_eval unicode_strings)],
34 "default" => [qw(array_base)],
37 $feature_bundle{"5.12"} = $feature_bundle{"5.11"};
38 $feature_bundle{"5.13"} = $feature_bundle{"5.11"};
39 $feature_bundle{"5.14"} = $feature_bundle{"5.11"};
40 $feature_bundle{"5.16"} = $feature_bundle{"5.15"};
41 $feature_bundle{"5.17"} = $feature_bundle{"5.15"};
42 $feature_bundle{"5.18"} = $feature_bundle{"5.15"};
43 $feature_bundle{"5.19"} = $feature_bundle{"5.15"};
44 $feature_bundle{"5.20"} = $feature_bundle{"5.15"};
45 $feature_bundle{"5.21"} = $feature_bundle{"5.15"};
46 $feature_bundle{"5.22"} = $feature_bundle{"5.15"};
47 $feature_bundle{"5.24"} = $feature_bundle{"5.23"};
48 $feature_bundle{"5.9.5"} = $feature_bundle{"5.10"};
51 our $hint_mask = 0x1c000000;
52 our @hint_bundles = qw( default 5.10 5.11 5.15 5.23 );
54 # This gets set (for now) in $^H as well as in %^H,
55 # for runtime speed of the uc/lc/ucfirst/lcfirst functions.
56 # See HINT_UNI_8_BIT in perl.h.
57 our $hint_uni8bit = 0x00000800;
60 # - think about versioned features (use feature switch => 2)
64 feature - Perl pragma to enable new features
68 use feature qw(say switch);
70 when (1) { say "\$foo == 1" }
71 when ([2,3]) { say "\$foo == 2 || \$foo == 3" }
72 when (/^a[bc]d$/) { say "\$foo eq 'abd' || \$foo eq 'acd'" }
73 when ($_ > 100) { say "\$foo > 100" }
74 default { say "None of the above" }
77 use feature ':5.10'; # loads all features available in perl 5.10
79 use v5.10; # implicitly loads :5.10 feature bundle
83 It is usually impossible to add new syntax to Perl without breaking
84 some existing programs. This pragma provides a way to minimize that
85 risk. New syntactic constructs, or new semantic meanings to older
86 constructs, can be enabled by C<use feature 'foo'>, and will be parsed
87 only when the appropriate feature pragma is in scope. (Nevertheless, the
88 C<CORE::> prefix provides access to all Perl keywords, regardless of this
93 Like other pragmas (C<use strict>, for example), features have a lexical
94 effect. C<use feature qw(foo)> will only make the feature "foo" available
95 from that point to the end of the enclosing block.
99 say "say is available here";
101 print "But not here.\n";
105 Features can also be turned off by using C<no feature "foo">. This too
109 say "say is available here";
112 print "But not here.\n";
114 say "Yet it is here.";
116 C<no feature> with no features specified will reset to the default group. To
117 disable I<all> features (an unusual request!) use C<no feature ':all'>.
119 =head1 AVAILABLE FEATURES
121 =head2 The 'say' feature
123 C<use feature 'say'> tells the compiler to enable the Perl 6 style
126 See L<perlfunc/say> for details.
128 This feature is available starting with Perl 5.10.
130 =head2 The 'state' feature
132 C<use feature 'state'> tells the compiler to enable C<state>
135 See L<perlsub/"Persistent Private Variables"> for details.
137 This feature is available starting with Perl 5.10.
139 =head2 The 'switch' feature
141 B<WARNING>: Because the L<smartmatch operator|perlop/"Smartmatch Operator"> is
142 experimental, Perl will warn when you use this feature, unless you have
143 explicitly disabled the warning:
145 no warnings "experimental::smartmatch";
147 C<use feature 'switch'> tells the compiler to enable the Perl 6
148 given/when construct.
150 See L<perlsyn/"Switch Statements"> for details.
152 This feature is available starting with Perl 5.10.
154 =head2 The 'unicode_strings' feature
156 C<use feature 'unicode_strings'> tells the compiler to use Unicode rules
157 in all string operations executed within its scope (unless they are also
158 within the scope of either C<use locale> or C<use bytes>). The same applies
159 to all regular expressions compiled within the scope, even if executed outside
160 it. It does not change the internal representation of strings, but only how
161 they are interpreted.
163 C<no feature 'unicode_strings'> tells the compiler to use the traditional
164 Perl rules wherein the native character set rules is used unless it is
165 clear to Perl that Unicode is desired. This can lead to some surprises
166 when the behavior suddenly changes. (See
167 L<perlunicode/The "Unicode Bug"> for details.) For this reason, if you are
168 potentially using Unicode in your program, the
169 C<use feature 'unicode_strings'> subpragma is B<strongly> recommended.
171 This feature is available starting with Perl 5.12; was almost fully
172 implemented in Perl 5.14; and extended in Perl 5.16 to cover C<quotemeta>.
174 =head2 The 'unicode_eval' and 'evalbytes' features
176 Under the C<unicode_eval> feature, Perl's C<eval> function, when passed a
177 string, will evaluate it as a string of characters, ignoring any
178 C<use utf8> declarations. C<use utf8> exists to declare the encoding of
179 the script, which only makes sense for a stream of bytes, not a string of
180 characters. Source filters are forbidden, as they also really only make
181 sense on strings of bytes. Any attempt to activate a source filter will
184 The C<evalbytes> feature enables the C<evalbytes> keyword, which evaluates
185 the argument passed to it as a string of bytes. It dies if the string
186 contains any characters outside the 8-bit range. Source filters work
187 within C<evalbytes>: they apply to the contents of the string being
190 Together, these two features are intended to replace the historical C<eval>
191 function, which has (at least) two bugs in it, that cannot easily be fixed
192 without breaking existing programs:
198 C<eval> behaves differently depending on the internal encoding of the
199 string, sometimes treating its argument as a string of bytes, and sometimes
200 as a string of characters.
204 Source filters activated within C<eval> leak out into whichever I<file>
205 scope is currently being compiled. To give an example with the CPAN module
208 BEGIN { eval "use Semi::Semicolons; # not filtered here " }
211 C<evalbytes> fixes that to work the way one would expect:
213 use feature "evalbytes";
214 BEGIN { evalbytes "use Semi::Semicolons; # filtered " }
219 These two features are available starting with Perl 5.16.
221 =head2 The 'current_sub' feature
223 This provides the C<__SUB__> token that returns a reference to the current
224 subroutine or C<undef> outside of a subroutine.
226 This feature is available starting with Perl 5.16.
228 =head2 The 'array_base' feature
230 This feature supports the legacy C<$[> variable. See L<perlvar/$[> and
231 L<arybase>. It is on by default but disabled under C<use v5.16> (see
232 L</IMPLICIT LOADING>, below).
234 This feature is available under this name starting with Perl 5.16. In
235 previous versions, it was simply on all the time, and this pragma knew
238 =head2 The 'fc' feature
240 C<use feature 'fc'> tells the compiler to enable the C<fc> function,
241 which implements Unicode casefolding.
243 See L<perlfunc/fc> for details.
245 This feature is available from Perl 5.16 onwards.
247 =head2 The 'lexical_subs' feature
249 B<WARNING>: This feature is still experimental and the implementation may
250 change in future versions of Perl. For this reason, Perl will
251 warn when you use the feature, unless you have explicitly disabled the
254 no warnings "experimental::lexical_subs";
256 This enables declaration of subroutines via C<my sub foo>, C<state sub foo>
257 and C<our sub foo> syntax. See L<perlsub/Lexical Subroutines> for details.
259 This feature is available from Perl 5.18 onwards.
261 =head2 The 'postderef' and 'postderef_qq' features
263 The 'postderef_qq' feature extends the applicability of L<postfix
264 dereference syntax|perlref/Postfix Dereference Syntax> so that postfix array
265 and scalar dereference are available in double-quotish interpolations. For
266 example, it makes the following two statements equivalent:
268 my $s = "[@{ $h->{a} }]";
269 my $s = "[$h->{a}->@*]";
271 This feature is available from Perl 5.20 onwards. In Perl 5.20 and 5.22, it
272 was classed as experimental, and Perl emitted a warning for its
273 usage, except when explicitly disabled:
275 no warnings "experimental::postderef";
277 As of Perl 5.24, use of this feature no longer triggers a warning, though
278 the C<experimental::postderef> warning category still exists (for
279 compatibility with code that disables it).
281 The 'postderef' feature was used in Perl 5.20 and Perl 5.22 to enable
282 postfix dereference syntax outside double-quotish interpolations. In those
283 versions, using it triggered the C<experimental::postderef> warning in the
284 same way as the 'postderef_qq' feature did. As of Perl 5.24, this syntax is
285 not only no longer experimental, but it is enabled for all Perl code,
286 regardless of what feature declarations are in scope.
288 =head2 The 'signatures' feature
290 B<WARNING>: This feature is still experimental and the implementation may
291 change in future versions of Perl. For this reason, Perl will
292 warn when you use the feature, unless you have explicitly disabled the
295 no warnings "experimental::signatures";
297 This enables unpacking of subroutine arguments into lexical variables
300 sub foo ($left, $right) {
301 return $left + $right;
304 See L<perlsub/Signatures> for details.
306 This feature is available from Perl 5.20 onwards.
308 =head2 The 'refaliasing' feature
310 B<WARNING>: This feature is still experimental and the implementation may
311 change in future versions of Perl. For this reason, Perl will
312 warn when you use the feature, unless you have explicitly disabled the
315 no warnings "experimental::refaliasing";
317 This enables aliasing via assignment to references:
319 \$a = \$b; # $a and $b now point to the same scalar
320 \@a = \@b; # to the same array
323 foreach \%hash (@array_of_hash_refs) {
327 See L<perlref/Assigning to References> for details.
329 This feature is available from Perl 5.22 onwards.
331 =head2 The 'bitwise' feature
333 B<WARNING>: This feature is still experimental and the implementation may
334 change in future versions of Perl. For this reason, Perl will
335 warn when you use the feature, unless you have explicitly disabled the
338 no warnings "experimental::bitwise";
340 This makes the four standard bitwise operators (C<& | ^ ~>) treat their
341 operands consistently as numbers, and introduces four new dotted operators
342 (C<&. |. ^. ~.>) that treat their operands consistently as strings. The
343 same applies to the assignment variants (C<&= |= ^= &.= |.= ^.=>).
345 See L<perlop/Bitwise String Operators> for details.
347 This feature is available from Perl 5.22 onwards.
349 =head1 FEATURE BUNDLES
351 It's possible to load multiple features together, using
352 a I<feature bundle>. The name of a feature bundle is prefixed with
353 a colon, to distinguish it from an actual feature.
357 The following feature bundles are available:
359 bundle features included
360 --------- -----------------
363 :5.10 say state switch array_base
365 :5.12 say state switch unicode_strings array_base
367 :5.14 say state switch unicode_strings array_base
369 :5.16 say state switch unicode_strings
370 unicode_eval evalbytes current_sub fc
372 :5.18 say state switch unicode_strings
373 unicode_eval evalbytes current_sub fc
375 :5.20 say state switch unicode_strings
376 unicode_eval evalbytes current_sub fc
378 :5.22 say state switch unicode_strings
379 unicode_eval evalbytes current_sub fc
381 :5.24 say state switch unicode_strings
382 unicode_eval evalbytes current_sub fc
385 The C<:default> bundle represents the feature set that is enabled before
386 any C<use feature> or C<no feature> declaration.
388 Specifying sub-versions such as the C<0> in C<5.14.0> in feature bundles has
389 no effect. Feature bundles are guaranteed to be the same for all sub-versions.
391 use feature ":5.14.0"; # same as ":5.14"
392 use feature ":5.14.1"; # same as ":5.14"
394 =head1 IMPLICIT LOADING
396 Instead of loading feature bundles by name, it is easier to let Perl do
397 implicit loading of a feature bundle for you.
399 There are two ways to load the C<feature> pragma implicitly:
405 By using the C<-E> switch on the Perl command-line instead of C<-e>.
406 That will enable the feature bundle for that version of Perl in the
407 main compilation unit (that is, the one-liner that follows C<-E>).
411 By explicitly requiring a minimum Perl version number for your program, with
412 the C<use VERSION> construct. That is,
421 and so on. Note how the trailing sub-version
422 is automatically stripped from the
425 But to avoid portability warnings (see L<perlfunc/use>), you may prefer:
429 with the same effect.
431 If the required version is older than Perl 5.10, the ":default" feature
432 bundle is automatically loaded instead.
442 croak("No features specified");
451 # A bare C<no feature> should reset to the default bundle
453 $^H &= ~($hint_uni8bit|$hint_mask);
463 my $bundle_number = $^H & $hint_mask;
464 my $features = $bundle_number != $hint_mask
465 && $feature_bundle{$hint_bundles[$bundle_number >> $hint_shift]};
467 # Features are enabled implicitly via bundle hints.
468 # Delete any keys that may be left over from last time.
469 delete @^H{ values(%feature) };
472 $^H{$feature{$_}} = 1;
473 $^H |= $hint_uni8bit if $_ eq 'unicode_strings';
478 if (substr($name, 0, 1) eq ":") {
479 my $v = substr($name, 1);
480 if (!exists $feature_bundle{$v}) {
481 $v =~ s/^([0-9]+)\.([0-9]+).[0-9]+$/$1.$2/;
482 if (!exists $feature_bundle{$v}) {
483 unknown_feature_bundle(substr($name, 1));
486 unshift @_, @{$feature_bundle{$v}};
489 if (!exists $feature{$name}) {
490 unknown_feature($name);
493 $^H{$feature{$name}} = 1;
494 $^H |= $hint_uni8bit if $name eq 'unicode_strings';
496 delete $^H{$feature{$name}};
497 $^H &= ~ $hint_uni8bit if $name eq 'unicode_strings';
502 sub unknown_feature {
504 croak(sprintf('Feature "%s" is not supported by Perl %vd',
508 sub unknown_feature_bundle {
510 croak(sprintf('Feature bundle "%s" is not supported by Perl %vd',