4 $feature::hint_bits = 0x04020000; # HINT_LOCALIZE_HH | HINT_HH_FOR_EVAL
6 # (feature name) => (internal name, used in %^H)
8 switch => 'feature_switch',
14 # Here are some notes that probably shouldn't be in the public
15 # documentation, but which it's useful to have somewhere.
17 # One side-effect of the change is that C<prototype("CORE::continue")>
18 # no longer throws the error C<Can't find an opnumber for "continue">.
19 # One of the tests in t/op/cproto.t had to be changed to accommodate
20 # this, but it really shouldn't affect real-world code.
23 # - sort out the smartmatch semantics
24 # - think about versioned features (use switch => 2)
30 feature - Perl pragma to enable new syntactic features
36 when (1) { print "\$foo == 1\n" }
37 when ([2,3]) { print "\$foo == 2 || \$foo == 3\n" }
38 when (/^a[bc]d$/) { print "\$foo eq 'abd' || \$foo eq 'acd'\n" }
39 when ($_ > 100) { print "\$foo > 100\n" }
40 default { print "None of the above\n" }
45 It is usually impossible to add new syntax to Perl without breaking
46 some existing programs. This pragma provides a way to minimize that
47 risk. New syntactic constructs can be enabled by C<use feature 'foo'>,
48 and will be parsed only when the appropriate feature pragma is in
51 =head2 The 'switch' feature
53 C<use feature 'switch'> tells the compiler to enable the Perl 6
54 given/when construct from here to the end of the enclosing BLOCK.
56 See L<perlsyn/"Switch statements"> for details.
58 =head2 The '~~' feature
60 C<use feature '~~'> tells the compiler to enable the Perl 6
61 smart match C<~~> operator from here to the end of the enclosing BLOCK.
63 See L<perlsyn/"Smart Matching in Detail"> for details.
65 =head2 The 'say' feature
67 C<use feature 'say'> tells the compiler to enable the Perl 6
68 C<say> function from here to the end of the enclosing BLOCK.
70 See L<perlfunc/say> for details.
75 $^H |= $feature::hint_bits; # Need this or %^H won't work
80 Carp->import("croak");
81 croak("No features specified");
85 if (!exists $feature{$name}) {
87 Carp->import("croak");
88 croak(sprintf('Feature "%s" is not supported by Perl %vd',
91 $^H{$feature{$name}} = 1;
98 # A bare C<no feature> should disable *all* features
100 if (!exists($feature{$name})) {
102 Carp->import("croak");
103 croak(sprintf('Feature "%s" is not supported by Perl %vd',
107 delete $^H{$feature{$name}};
112 delete @^H{ values(%feature) };