3 # Regenerate (overwriting only if changed):
8 # from information hardcoded into this script and from two #defines
11 # This script is normally invoked from regen.pl.
14 require './regen/regen_lib.pl';
21 ###########################################################################
24 # (feature name) => (internal name, used in %^H and macro names)
30 evalbytes => 'evalbytes',
31 current_sub => '__SUB__',
32 refaliasing => 'refaliasing',
33 postderef_qq => 'postderef_qq',
34 unicode_eval => 'unieval',
35 declared_refs => 'myref',
36 unicode_strings => 'unicode',
38 signatures => 'signatures',
40 indirect => 'indirect',
41 multidimensional => 'multidimensional',
42 bareword_filehandles => 'bareword_filehandles',
46 # NOTE: If a feature is ever enabled in a non-contiguous range of Perl
47 # versions, any code below that uses %BundleRanges will have to
48 # be changed to account.
50 # 5.odd implies the next 5.even, but an explicit 5.even can override it.
53 use constant V5_9_5 => sort qw{say state switch indirect multidimensional bareword_filehandles};
54 use constant V5_11 => sort ( +V5_9_5, qw{unicode_strings} );
55 use constant V5_15 => sort ( +V5_11, qw{unicode_eval evalbytes current_sub fc} );
56 use constant V5_23 => sort ( +V5_15, qw{postderef_qq} );
57 use constant V5_27 => sort ( +V5_23, qw{bitwise} );
58 use constant V5_35 => sort ( grep {; $_ ne 'switch' } +V5_27);
60 my %feature_bundle = (
61 all => [ sort keys %feature ],
62 default => [ qw{indirect multidimensional bareword_filehandles} ],
63 # using 5.9.5 features bundle
64 "5.9.5" => [ +V5_9_5 ],
65 "5.10" => [ +V5_9_5 ],
66 # using 5.11 features bundle
69 # using 5.15 features bundle
74 # using 5.23 features bundle
77 # using 5.27 features bundle
82 # using 5.35 features bundle
86 my @noops = qw( postderef lexical_subs );
87 my @removed = qw( array_base );
90 ###########################################################################
91 # More data generated from the above
93 if (keys %feature > 32) {
94 die "cop_features only has room for 32 features";
99 for my $feature (sort keys %feature) {
100 $feature_bits{$feature} = $mask;
104 for (keys %feature_bundle) {
105 next unless /^5\.(\d*[13579])\z/;
106 $feature_bundle{"5.".($1+1)} ||= $feature_bundle{$_};
109 my %UniqueBundles; # "say state switch" => 5.10
110 my %Aliases; # 5.12 => 5.11
111 for( sort keys %feature_bundle ) {
112 my $value = join(' ', sort @{$feature_bundle{$_}});
113 if (exists $UniqueBundles{$value}) {
114 $Aliases{$_} = $UniqueBundles{$value};
117 $UniqueBundles{$value} = $_;
121 my %BundleRanges; # say => ['5.10', '5.15'] # unique bundles for values
123 sort { $a eq 'default' ? -1 : $b eq 'default' ? 1 : $a cmp $b }
124 values %UniqueBundles
126 next if $bund =~ /[^\d.]/ and $bund ne 'default';
127 for (@{$feature_bundle{$bund}}) {
128 if (@{$BundleRanges{$_} ||= []} == 2) {
129 $BundleRanges{$_}[1] = $bund
132 push @{$BundleRanges{$_}}, $bund;
141 open "perl.h", "<", "perl.h" or die "$0 cannot open perl.h: $!";
142 while (readline "perl.h") {
143 next unless /#\s*define\s+(HINT_FEATURE_MASK|HINT_UNI_8_BIT)/;
144 my $is_u8b = $1 =~ 8;
145 /(0x[A-Fa-f0-9]+)/ or die "No hex number in:\n\n$_\n ";
150 my $hex = $HintMask = $1;
151 my $bits = sprintf "%b", oct $1;
152 $bits =~ /^0*1+(0*)\z/
153 or die "Non-contiguous bits in $bits (binary for $hex):\n\n$_\n ";
154 $HintShift = length $1;
156 length sprintf "%b", scalar keys %UniqueBundles;
157 $bits =~ /1{$bits_needed}/
158 or die "Not enough bits (need $bits_needed)"
159 . " in $bits (binary for $hex):\n\n$_\n ";
161 if ($Uni8Bit && $HintMask) { last }
163 die "No HINT_FEATURE_MASK defined in perl.h" unless $HintMask;
164 die "No HINT_UNI_8_BIT defined in perl.h" unless $Uni8Bit;
169 ('default', grep !/[^\d.]/, sort values %UniqueBundles);
172 ###########################################################################
173 # Open files to be generated
176 open_new($_, '>', { by => 'regen/feature.pl' });
177 } 'lib/feature.pm', 'feature.h';
180 ###########################################################################
181 # Generate lib/feature.pm
184 last if /^FEATURES$/ ;
191 if (!defined $long or length $long < length) {
198 print $pm "our %feature = (\n";
199 my $width = length longest keys %feature;
200 for(sort { length $a <=> length $b || $a cmp $b } keys %feature) {
201 print $pm " $_" . " "x($width-length)
202 . " => 'feature_$feature{$_}',\n";
206 print $pm "our %feature_bundle = (\n";
207 my $bund_width = length longest values %UniqueBundles;
208 for( sort { $UniqueBundles{$a} cmp $UniqueBundles{$b} }
209 keys %UniqueBundles ) {
210 my $bund = $UniqueBundles{$_};
211 print $pm qq' "$bund"' . " "x($bund_width-length $bund)
212 . qq' => [qw($_)],\n';
216 for (sort keys %Aliases) {
218 qq'\$feature_bundle{"$_"} = \$feature_bundle{"$Aliases{$_}"};\n';
221 print $pm "my \%noops = (\n";
222 print $pm " $_ => 1,\n", for @noops;
225 print $pm "my \%removed = (\n";
226 print $pm " $_ => 1,\n", for @removed;
231 our \$hint_shift = $HintShift;
232 our \$hint_mask = $HintMask;
233 our \@hint_bundles = qw( @HintedBundles );
235 # This gets set (for now) in \$^H as well as in %^H,
236 # for runtime speed of the uc/lc/ucfirst/lcfirst functions.
237 # See HINT_UNI_8_BIT in perl.h.
238 our \$hint_uni8bit = $Uni8Bit;
243 last if /^PODTURES$/ ;
247 select +(select($pm), $~ = 'PODTURES')[0];
249 ^<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
250 $::bundle, $::feature
253 for ('default', sort grep /\.\d[02468]/, keys %feature_bundle) {
255 $::feature = join ' ', @{$feature_bundle{$_}};
264 read_only_bottom_close_and_rename($pm);
267 ###########################################################################
272 #ifndef PERL_FEATURE_H_
273 #define PERL_FEATURE_H_
275 #if defined(PERL_CORE) || defined (PERL_EXT)
277 #define HINT_FEATURE_SHIFT $HintShift
281 for (sort keys %feature_bits) {
282 printf $h "#define FEATURE_%s_BIT%*s %#06x\n", uc($feature{$_}),
283 $width-length($feature{$_}), "", $feature_bits{$_};
288 for (@HintedBundles) {
289 (my $key = uc) =~ y/.//d;
290 print $h "#define FEATURE_BUNDLE_$key ", $count++, "\n";
294 #define FEATURE_BUNDLE_CUSTOM (HINT_FEATURE_MASK >> HINT_FEATURE_SHIFT)
296 #define CURRENT_HINTS \
297 (PL_curcop == &PL_compiling ? PL_hints : PL_curcop->cop_hints)
298 #define CURRENT_FEATURE_BUNDLE \
299 ((CURRENT_HINTS & HINT_FEATURE_MASK) >> HINT_FEATURE_SHIFT)
301 #define FEATURE_IS_ENABLED_MASK(mask) \
302 ((CURRENT_HINTS & HINT_LOCALIZE_HH) \
303 ? (PL_curcop->cop_features & (mask)) : FALSE)
305 /* The longest string we pass in. */
308 my $longest_internal_feature_name = longest values %feature;
310 #define MAX_FEATURE_LEN (sizeof("$longest_internal_feature_name")-1)
315 sort { length $a <=> length $b || $a cmp $b } keys %feature
318 map { (my $__ = uc) =~ y/.//d; $__ } @{$BundleRanges{$_}};
319 my $name = $feature{$_};
321 if ($last && $first eq 'DEFAULT') { # '>= DEFAULT' warns
323 #define FEATURE_${NAME}_IS_ENABLED \\
325 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_$last \\
326 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \\
327 FEATURE_IS_ENABLED_MASK(FEATURE_${NAME}_BIT)) \\
334 #define FEATURE_${NAME}_IS_ENABLED \\
336 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_$first && \\
337 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_$last) \\
338 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \\
339 FEATURE_IS_ENABLED_MASK(FEATURE_${NAME}_BIT)) \\
346 #define FEATURE_${NAME}_IS_ENABLED \\
348 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_$first \\
349 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \\
350 FEATURE_IS_ENABLED_MASK(FEATURE_${NAME}_BIT)) \\
357 #define FEATURE_${NAME}_IS_ENABLED \\
359 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \\
360 FEATURE_IS_ENABLED_MASK(FEATURE_${NAME}_BIT) \\
369 #define SAVEFEATUREBITS() SAVEI32(PL_compiling.cop_features)
371 #define CLEARFEATUREBITS() (PL_compiling.cop_features = 0)
373 #define STOREFEATUREBITSHH(hh) \\
374 (hv_stores((hh), "feature/bits", newSVuv(PL_compiling.cop_features)))
376 #define FETCHFEATUREBITSHH(hh) \\
378 SV **fbsv = hv_fetchs((hh), "feature/bits", FALSE); \\
379 PL_compiling.cop_features = fbsv ? SvUV(*fbsv) : 0; \\
382 #endif /* PERL_CORE or PERL_EXT */
385 PERL_STATIC_INLINE void
386 S_enable_feature_bundle(pTHX_ SV *ver)
388 SV *comp_ver = sv_newmortal();
389 PL_hints = (PL_hints &~ HINT_FEATURE_MASK)
393 for (reverse @HintedBundles[1..$#HintedBundles]) { # skip default
395 if ($numver eq '5.10') { $numver = '5.009005' } # special case
396 else { $numver =~ s/\./.0/ } # 5.11 => 5.011
397 (my $macrover = $_) =~ y/.//d;
399 (sv_setnv(comp_ver, $numver),
400 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
401 ? FEATURE_BUNDLE_$macrover :
406 FEATURE_BUNDLE_DEFAULT
407 ) << HINT_FEATURE_SHIFT;
409 assert(PL_curcop == &PL_compiling);
410 if (FEATURE_UNICODE_IS_ENABLED) PL_hints |= HINT_UNI_8_BIT;
411 else PL_hints &= ~HINT_UNI_8_BIT;
413 #endif /* PERL_IN_OP_C */
417 #define magic_sethint_feature(keysv, keypv, keylen, valsv, valbool) \\
418 S_magic_sethint_feature(aTHX_ (keysv), (keypv), (keylen), (valsv), (valbool))
419 PERL_STATIC_INLINE void
420 S_magic_sethint_feature(pTHX_ SV *keysv, const char *keypv, STRLEN keylen,
421 SV *valsv, bool valbool) {
423 keypv = SvPV_const(keysv, keylen);
425 if (memBEGINs(keypv, keylen, "feature_")) {
426 const char *subf = keypv + (sizeof("feature_")-1);
432 for my $key (sort values %feature) {
433 push @{$pref{substr($key, 0, 1)}}, $key;
436 for my $pref (sort keys %pref) {
441 for my $subkey (@{$pref{$pref}}) {
442 my $rest = substr($subkey, 1);
443 my $if = $first ? "if" : "else if";
445 $if (keylen == sizeof("feature_$subkey")-1
446 && memcmp(subf+1, "$rest", keylen - sizeof("feature_")) == 0) {
447 mask = FEATURE_\U${subkey}\E_BIT;
464 if (valsv ? SvTRUE(valsv) : valbool)
465 PL_compiling.cop_features |= mask;
467 PL_compiling.cop_features &= ~mask;
470 #endif /* PERL_IN_MG_C */
472 #endif /* PERL_FEATURE_H_ */
475 read_only_bottom_close_and_rename($h);
478 ###########################################################################
479 # Template for feature.pm
484 our $VERSION = '1.67';
489 # - think about versioned features (use feature switch => 2)
493 feature - Perl pragma to enable new features
497 use feature qw(fc say);
499 # Without the "use feature" above, this code would not be able to find
500 # the built-ins "say" or "fc":
501 say "The case-folded version of $x is: " . fc $x;
504 # set features to match the :5.10 bundle, which may turn off or on
505 # multiple features (see below)
509 # implicitly loads :5.10 feature bundle
514 It is usually impossible to add new syntax to Perl without breaking
515 some existing programs. This pragma provides a way to minimize that
516 risk. New syntactic constructs, or new semantic meanings to older
517 constructs, can be enabled by C<use feature 'foo'>, and will be parsed
518 only when the appropriate feature pragma is in scope. (Nevertheless, the
519 C<CORE::> prefix provides access to all Perl keywords, regardless of this
522 =head2 Lexical effect
524 Like other pragmas (C<use strict>, for example), features have a lexical
525 effect. C<use feature qw(foo)> will only make the feature "foo" available
526 from that point to the end of the enclosing block.
530 say "say is available here";
532 print "But not here.\n";
536 Features can also be turned off by using C<no feature "foo">. This too
540 say "say is available here";
543 print "But not here.\n";
545 say "Yet it is here.";
547 C<no feature> with no features specified will reset to the default group. To
548 disable I<all> features (an unusual request!) use C<no feature ':all'>.
550 =head1 AVAILABLE FEATURES
552 =head2 The 'say' feature
554 C<use feature 'say'> tells the compiler to enable the Raku-inspired
557 See L<perlfunc/say> for details.
559 This feature is available starting with Perl 5.10.
561 =head2 The 'state' feature
563 C<use feature 'state'> tells the compiler to enable C<state>
566 See L<perlsub/"Persistent Private Variables"> for details.
568 This feature is available starting with Perl 5.10.
570 =head2 The 'switch' feature
572 B<WARNING>: This feature is still experimental and the implementation may
573 change or be removed in future versions of Perl. For this reason, Perl will
574 warn when you use the feature, unless you have explicitly disabled the warning:
576 no warnings "experimental::smartmatch";
578 C<use feature 'switch'> tells the compiler to enable the Raku
579 given/when construct.
581 See L<perlsyn/"Switch Statements"> for details.
583 This feature is available starting with Perl 5.10.
585 =head2 The 'unicode_strings' feature
587 C<use feature 'unicode_strings'> tells the compiler to use Unicode rules
588 in all string operations executed within its scope (unless they are also
589 within the scope of either C<use locale> or C<use bytes>). The same applies
590 to all regular expressions compiled within the scope, even if executed outside
591 it. It does not change the internal representation of strings, but only how
592 they are interpreted.
594 C<no feature 'unicode_strings'> tells the compiler to use the traditional
595 Perl rules wherein the native character set rules is used unless it is
596 clear to Perl that Unicode is desired. This can lead to some surprises
597 when the behavior suddenly changes. (See
598 L<perlunicode/The "Unicode Bug"> for details.) For this reason, if you are
599 potentially using Unicode in your program, the
600 C<use feature 'unicode_strings'> subpragma is B<strongly> recommended.
602 This feature is available starting with Perl 5.12; was almost fully
603 implemented in Perl 5.14; and extended in Perl 5.16 to cover C<quotemeta>;
604 was extended further in Perl 5.26 to cover L<the range
605 operator|perlop/Range Operators>; and was extended again in Perl 5.28 to
606 cover L<special-cased whitespace splitting|perlfunc/split>.
608 =head2 The 'unicode_eval' and 'evalbytes' features
610 Together, these two features are intended to replace the legacy string
611 C<eval> function, which behaves problematically in some instances. They are
612 available starting with Perl 5.16, and are enabled by default by a
613 S<C<use 5.16>> or higher declaration.
615 C<unicode_eval> changes the behavior of plain string C<eval> to work more
616 consistently, especially in the Unicode world. Certain (mis)behaviors
617 couldn't be changed without breaking some things that had come to rely on
618 them, so the feature can be enabled and disabled. Details are at
619 L<perlfunc/Under the "unicode_eval" feature>.
621 C<evalbytes> is like string C<eval>, but it treats its argument as a byte
622 string. Details are at L<perlfunc/evalbytes EXPR>. Without a
623 S<C<use feature 'evalbytes'>> nor a S<C<use v5.16>> (or higher) declaration in
624 the current scope, you can still access it by instead writing
627 =head2 The 'current_sub' feature
629 This provides the C<__SUB__> token that returns a reference to the current
630 subroutine or C<undef> outside of a subroutine.
632 This feature is available starting with Perl 5.16.
634 =head2 The 'array_base' feature
636 This feature supported the legacy C<$[> variable. See L<perlvar/$[>.
637 It was on by default but disabled under C<use v5.16> (see
638 L</IMPLICIT LOADING>, below) and unavailable since perl 5.30.
640 This feature is available under this name starting with Perl 5.16. In
641 previous versions, it was simply on all the time, and this pragma knew
644 =head2 The 'fc' feature
646 C<use feature 'fc'> tells the compiler to enable the C<fc> function,
647 which implements Unicode casefolding.
649 See L<perlfunc/fc> for details.
651 This feature is available from Perl 5.16 onwards.
653 =head2 The 'lexical_subs' feature
655 In Perl versions prior to 5.26, this feature enabled
656 declaration of subroutines via C<my sub foo>, C<state sub foo>
657 and C<our sub foo> syntax. See L<perlsub/Lexical Subroutines> for details.
659 This feature is available from Perl 5.18 onwards. From Perl 5.18 to 5.24,
660 it was classed as experimental, and Perl emitted a warning for its
661 usage, except when explicitly disabled:
663 no warnings "experimental::lexical_subs";
665 As of Perl 5.26, use of this feature no longer triggers a warning, though
666 the C<experimental::lexical_subs> warning category still exists (for
667 compatibility with code that disables it). In addition, this syntax is
668 not only no longer experimental, but it is enabled for all Perl code,
669 regardless of what feature declarations are in scope.
671 =head2 The 'postderef' and 'postderef_qq' features
673 The 'postderef_qq' feature extends the applicability of L<postfix
674 dereference syntax|perlref/Postfix Dereference Syntax> so that postfix array
675 and scalar dereference are available in double-quotish interpolations. For
676 example, it makes the following two statements equivalent:
678 my $s = "[@{ $h->{a} }]";
679 my $s = "[$h->{a}->@*]";
681 This feature is available from Perl 5.20 onwards. In Perl 5.20 and 5.22, it
682 was classed as experimental, and Perl emitted a warning for its
683 usage, except when explicitly disabled:
685 no warnings "experimental::postderef";
687 As of Perl 5.24, use of this feature no longer triggers a warning, though
688 the C<experimental::postderef> warning category still exists (for
689 compatibility with code that disables it).
691 The 'postderef' feature was used in Perl 5.20 and Perl 5.22 to enable
692 postfix dereference syntax outside double-quotish interpolations. In those
693 versions, using it triggered the C<experimental::postderef> warning in the
694 same way as the 'postderef_qq' feature did. As of Perl 5.24, this syntax is
695 not only no longer experimental, but it is enabled for all Perl code,
696 regardless of what feature declarations are in scope.
698 =head2 The 'signatures' feature
700 B<WARNING>: This feature is still experimental and the implementation may
701 change or be removed in future versions of Perl. For this reason, Perl will
702 warn when you use the feature, unless you have explicitly disabled the warning:
704 no warnings "experimental::signatures";
706 This enables unpacking of subroutine arguments into lexical variables
709 sub foo ($left, $right) {
710 return $left + $right;
713 See L<perlsub/Signatures> for details.
715 This feature is available from Perl 5.20 onwards.
717 =head2 The 'refaliasing' feature
719 B<WARNING>: This feature is still experimental and the implementation may
720 change or be removed in future versions of Perl. For this reason, Perl will
721 warn when you use the feature, unless you have explicitly disabled the warning:
723 no warnings "experimental::refaliasing";
725 This enables aliasing via assignment to references:
727 \$a = \$b; # $a and $b now point to the same scalar
728 \@a = \@b; # to the same array
731 foreach \%hash (@array_of_hash_refs) {
735 See L<perlref/Assigning to References> for details.
737 This feature is available from Perl 5.22 onwards.
739 =head2 The 'bitwise' feature
741 This makes the four standard bitwise operators (C<& | ^ ~>) treat their
742 operands consistently as numbers, and introduces four new dotted operators
743 (C<&. |. ^. ~.>) that treat their operands consistently as strings. The
744 same applies to the assignment variants (C<&= |= ^= &.= |.= ^.=>).
746 See L<perlop/Bitwise String Operators> for details.
748 This feature is available from Perl 5.22 onwards. Starting in Perl 5.28,
749 C<use v5.28> will enable the feature. Before 5.28, it was still
750 experimental and would emit a warning in the "experimental::bitwise"
753 =head2 The 'declared_refs' feature
755 B<WARNING>: This feature is still experimental and the implementation may
756 change or be removed in future versions of Perl. For this reason, Perl will
757 warn when you use the feature, unless you have explicitly disabled the warning:
759 no warnings "experimental::declared_refs";
761 This allows a reference to a variable to be declared with C<my>, C<state>,
762 our C<our>, or localized with C<local>. It is intended mainly for use in
763 conjunction with the "refaliasing" feature. See L<perlref/Declaring a
764 Reference to a Variable> for examples.
766 This feature is available from Perl 5.26 onwards.
768 =head2 The 'isa' feature
770 B<WARNING>: This feature is still experimental and the implementation may
771 change or be removed in future versions of Perl. For this reason, Perl will
772 warn when you use the feature, unless you have explicitly disabled the warning:
774 no warnings "experimental::isa";
776 This allows the use of the C<isa> infix operator, which tests whether the
777 scalar given by the left operand is an object of the class given by the
778 right operand. See L<perlop/Class Instance Operator> for more details.
780 This feature is available from Perl 5.32 onwards.
782 =head2 The 'indirect' feature
784 This feature allows the use of L<indirect object
785 syntax|perlobj/Indirect Object Syntax> for method calls, e.g. C<new
786 Foo 1, 2;>. It is enabled by default, but can be turned off to
787 disallow indirect object syntax.
789 This feature is available under this name from Perl 5.32 onwards. In
790 previous versions, it was simply on all the time. To disallow (or
791 warn on) indirect object syntax on older Perls, see the L<indirect>
794 =head2 The 'multidimensional' feature
796 This feature enables multidimensional array emulation, a perl 4 (or
797 earlier) feature that was used to emulate multidimensional arrays with
798 hashes. This works by converting code like C<< $foo{$x, $y} >> into
799 C<< $foo{join($;, $x, $y)} >>. It is enabled by default, but can be
800 turned off to disable multidimensional array emulation.
802 When this feature is disabled the syntax that is normally replaced
803 will report a compilation error.
805 This feature is available under this name from Perl 5.34 onwards. In
806 previous versions, it was simply on all the time.
808 You can use the L<multidimensional> module on CPAN to disable
809 multidimensional array emulation for older versions of Perl.
811 =head2 The 'bareword_filehandles' feature.
813 This feature enables bareword filehandles for builtin functions
814 operations, a generally discouraged practice. It is enabled by
815 default, but can be turned off to disable bareword filehandles, except
816 for the exceptions listed below.
818 The perl built-in filehandles C<STDIN>, C<STDOUT>, C<STDERR>, C<DATA>,
819 C<ARGV>, C<ARGVOUT> and the special C<_> are always enabled.
821 This feature is enabled under this name from Perl 5.34 onwards. In
822 previous versions it was simply on all the time.
824 You can use the L<bareword::filehandles> module on CPAN to disable
825 bareword filehandles for older versions of perl.
827 =head2 The 'try' feature.
829 B<WARNING>: This feature is still experimental and the implementation may
830 change or be removed in future versions of Perl. For this reason, Perl will
831 warn when you use the feature, unless you have explicitly disabled the warning:
833 no warnings "experimental::try";
835 This feature enables the C<try> and C<catch> syntax, which allows exception
836 handling, where exceptions thrown from the body of the block introduced with
837 C<try> are caught by executing the body of the C<catch> block.
839 For more information, see L<perlsyn/"Try Catch Exception Handling">.
841 =head1 FEATURE BUNDLES
843 It's possible to load multiple features together, using
844 a I<feature bundle>. The name of a feature bundle is prefixed with
845 a colon, to distinguish it from an actual feature.
849 The following feature bundles are available:
851 bundle features included
852 --------- -----------------
854 The C<:default> bundle represents the feature set that is enabled before
855 any C<use feature> or C<no feature> declaration.
857 Specifying sub-versions such as the C<0> in C<5.14.0> in feature bundles has
858 no effect. Feature bundles are guaranteed to be the same for all sub-versions.
860 use feature ":5.14.0"; # same as ":5.14"
861 use feature ":5.14.1"; # same as ":5.14"
863 =head1 IMPLICIT LOADING
865 Instead of loading feature bundles by name, it is easier to let Perl do
866 implicit loading of a feature bundle for you.
868 There are two ways to load the C<feature> pragma implicitly:
874 By using the C<-E> switch on the Perl command-line instead of C<-e>.
875 That will enable the feature bundle for that version of Perl in the
876 main compilation unit (that is, the one-liner that follows C<-E>).
880 By explicitly requiring a minimum Perl version number for your program, with
881 the C<use VERSION> construct. That is,
890 and so on. Note how the trailing sub-version
891 is automatically stripped from the
894 But to avoid portability warnings (see L<perlfunc/use>), you may prefer:
898 with the same effect.
900 If the required version is older than Perl 5.10, the ":default" feature
901 bundle is automatically loaded instead.
903 Unlike C<use feature ":5.12">, saying C<use v5.12> (or any higher version)
904 also does the equivalent of C<use strict>; see L<perlfunc/use> for details.
914 croak("No features specified");
923 # A bare C<no feature> should reset to the default bundle
925 $^H &= ~($hint_uni8bit|$hint_mask);
935 my $bundle_number = $^H & $hint_mask;
936 my $features = $bundle_number != $hint_mask
937 && $feature_bundle{$hint_bundles[$bundle_number >> $hint_shift]};
939 # Features are enabled implicitly via bundle hints.
940 # Delete any keys that may be left over from last time.
941 delete @^H{ values(%feature) };
944 $^H{$feature{$_}} = 1;
945 $^H |= $hint_uni8bit if $_ eq 'unicode_strings';
950 if (substr($name, 0, 1) eq ":") {
951 my $v = substr($name, 1);
952 if (!exists $feature_bundle{$v}) {
953 $v =~ s/^([0-9]+)\.([0-9]+).[0-9]+$/$1.$2/;
954 if (!exists $feature_bundle{$v}) {
955 unknown_feature_bundle(substr($name, 1));
958 unshift @_, @{$feature_bundle{$v}};
961 if (!exists $feature{$name}) {
962 if (exists $noops{$name}) {
965 if (!$import && exists $removed{$name}) {
968 unknown_feature($name);
971 $^H{$feature{$name}} = 1;
972 $^H |= $hint_uni8bit if $name eq 'unicode_strings';
974 delete $^H{$feature{$name}};
975 $^H &= ~ $hint_uni8bit if $name eq 'unicode_strings';
980 sub unknown_feature {
982 croak(sprintf('Feature "%s" is not supported by Perl %vd',
986 sub unknown_feature_bundle {
988 croak(sprintf('Feature bundle "%s" is not supported by Perl %vd',