6 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7 print "1..0 # Skip -- Perl configured without B module\n";
16 my $tests = 30; # not counting those in the __DATA__ section
19 my $deparse = B::Deparse->new();
20 isa_ok($deparse, 'B::Deparse', 'instantiate a B::Deparse object');
27 # This code is pinched from the t/lib/common.pl for TODO.
28 # It's not clear how to avoid duplication
29 my %meta = (context => '');
30 foreach my $what (qw(skip todo context options)) {
31 s/^#\s*\U$what\E\s*(.*)\n//m and $meta{$what} = $1;
32 # If the SKIP reason starts ? then it's taken as a code snippet to
33 # evaluate. This provides the flexibility to have conditional SKIPs
34 if ($meta{$what} && $meta{$what} =~ s/^\?//) {
35 my $temp = eval $meta{$what};
37 die "# In \U$what\E code reason:\n# $meta{$what}\n$@";
45 die "Missing name in test $_" unless defined $desc;
48 SKIP: { skip($meta{skip}) };
52 my ($input, $expected);
53 if (/(.*)\n>>>>\n(.*)/s) {
54 ($input, $expected) = ($1, $2);
57 ($input, $expected) = ($_, $_);
60 # parse options if necessary
61 my $deparse = $meta{options}
62 ? $deparse{$meta{options}} ||=
63 new B::Deparse split /,/, $meta{options}
66 my $coderef = eval "$meta{context};\n" . <<'EOC' . "sub {$input\n}";
67 # Tell B::Deparse about our ambient pragmas
68 my ($hint_bits, $warning_bits, $hinthash);
70 ($hint_bits, $warning_bits, $hinthash) = ($^H, ${^WARNING_BITS}, \%^H);
72 $deparse->ambient_pragmas (
73 hint_bits => $hint_bits,
74 warning_bits => $warning_bits,
79 local $::TODO = $meta{todo};
81 is($@, "", "compilation of $desc");
84 my $deparsed = $deparse->coderef2text( $coderef );
85 my $regex = $expected;
86 $regex =~ s/(\S+)/\Q$1/g;
87 $regex =~ s/\s+/\\s+/g;
88 $regex = '^\{\s*' . $regex . '\s*\}$';
90 like($deparsed, qr/$regex/, $desc);
94 # Reset the ambient pragmas
98 ($b, $w, $h) = ($^H, ${^WARNING_BITS}, \%^H);
100 $deparse->ambient_pragmas (
107 use constant 'c', 'stuff';
108 is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff',
109 'the subroutine generated by use constant deparses');
112 is($deparse->coderef2text(sub{(-1) ** $a }), "{\n (-1) ** \$a;\n}",
113 'anon sub capturing an external lexical');
115 use constant cr => ['hello'];
116 my $string = "sub " . $deparse->coderef2text(\&cr);
117 my $val = (eval $string)->() or diag $string;
118 is(ref($val), 'ARRAY', 'constant array references deparse');
119 is($val->[0], 'hello', 'and return the correct value');
121 my $path = join " ", map { qq["-I$_"] } @INC;
123 $a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 2>&1`;
124 $a =~ s/-e syntax OK\n//g;
125 $a =~ s/.*possible typo.*\n//; # Remove warning line
126 $a =~ s/.*-i used with no filenames.*\n//; # Remove warning line
127 $b = quotemeta <<'EOF';
128 BEGIN { $^I = ".bak"; }
130 BEGIN { $/ = "\n"; $\ = "\n"; }
131 LINE: while (defined($_ = <ARGV>)) {
133 our(@F) = split(' ', $_, 0);
137 $b =~ s/our\\\(\\\@F\\\)/our[( ]\@F\\)?/; # accept both our @F and our(@F)
139 'command line flags deparse as BEGIN blocks setting control variables');
141 $a = `$^X $path "-MO=Deparse" -e "use constant PI => 4" 2>&1`;
142 $a =~ s/-e syntax OK\n//g;
143 is($a, "();\nuse constant ('PI', 4);\n",
144 "Proxy Constant Subroutines must not show up as (incorrect) prototypes");
146 #Re: perlbug #35857, patch #24505
147 #handle warnings::register-ed packages properly.
148 package B::Deparse::Wrapper;
151 use warnings::register;
153 my $deparser = B::Deparse->new();
154 return $deparser->coderef2text(shift);
158 use overload '0+' => sub { 42 };
163 use constant GLIPP => 'glipp';
164 use constant PI => 4;
165 use constant OVERLOADED_NUMIFICATION => bless({}, 'Moo');
166 use Fcntl qw/O_TRUNC O_APPEND O_EXCL/;
167 BEGIN { delete $::Fcntl::{O_APPEND}; }
168 use POSIX qw/O_CREAT/;
171 my $res = B::Deparse::Wrapper::getcode($val);
172 like($res, qr/use warnings/,
173 '[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly');
176 my $x=sub { ++$q,++$p };
178 eval <<EOFCODE and test($x);
182 use warnings::register;
187 # Exotic sub declarations
188 $a = `$^X $path "-MO=Deparse" -e "sub ::::{}sub ::::::{}" 2>&1`;
189 $a =~ s/-e syntax OK\n//g;
190 is($a, <<'EOCODG', "sub :::: and sub ::::::");
201 $a = `$^X $path "-MO=Deparse,-l" -e "map{ eval(0) }()" 2>&1`;
202 $a =~ s/-e syntax OK\n//g;
203 is($a, <<'EOCODH', "[perl #117311] [PATCH] -l option ('#line ...') does not emit ^Ls in the output");
212 my $code = <<"EOCODE";
214 our \$\x{1e1f}\x{14d}\x{14d};
218 = $deparse->coderef2text(eval "sub { our \$\x{1e1f}\x{14d}\x{14d} }" );
219 s/$ \n//x for $deparsed, $code;
220 is $deparsed, $code, 'our $funny_Unicode_chars';
225 `$^X $path "-MO=Deparse" -e "BEGIN{*CORE::GLOBAL::require=sub{1}}" 2>&1`;
226 $a =~ s/-e syntax OK\n//g;
227 is($a, <<'EOCODF', "CORE::GLOBAL::require override causing panick");
230 *CORE::GLOBAL::require = sub {
239 `$^X $path "-MO=Deparse" -e "BEGIN{*Acme::Acme:: = *Acme::}" 2>&1`;
240 like($a, qr/-e syntax OK/,
241 "Deparse does not hang when traversing stash circularities");
245 is($deparse->coderef2text(sub{ print "foo@{]}" }),
248 }>, 'curly around to interpolate "@{]}"');
249 is($deparse->coderef2text(sub{ print "foo@{-}" }),
252 }>, 'no need to curly around to interpolate "@-"');
254 # Strict hints in %^H are mercilessly suppressed
256 `$^X $path "-MO=Deparse" -e "use strict; print;" 2>&1`;
257 unlike($a, qr/BEGIN/,
258 "Deparse does not emit strict hh hints");
260 # ambient_pragmas should not mess with strict settings.
262 skip "requires 5.11", 1 unless $] >= 5.011;
265 # Clear out all hints
268 new B::Deparse -> ambient_pragmas(strict => 'all');
270 use 5.011; # should enable strict
271 ok !eval '$do_noT_create_a_variable_with_this_name = 1',
272 'ambient_pragmas do not mess with compiling scope';
276 # multiple statements on format lines
277 $a = `$^X $path "-MO=Deparse" -e "format =" -e "\@" -e "x();z()" -e. 2>&1`;
278 $a =~ s/-e syntax OK\n//g;
279 is($a, <<'EOCODH', 'multiple statements on format lines');
287 $a = readpipe qq`$^X $path "-MO=Deparse" -e "use feature q|:all|;`
288 .qq` my sub format; CORE::format =" -e. 2>&1`;
289 like($a, qr/CORE::format/, 'CORE::format when lex format sub is in scope');
291 # literal big chars under 'use utf8'
292 is($deparse->coderef2text(sub{ use utf8; /€/; }),
298 # STDERR when deparsing sub calls
299 # For a short while the output included 'While deparsing'
300 $a = `$^X $path "-MO=Deparse" -e "foo()" 2>&1`;
301 $a =~ s/-e syntax OK\n//g;
302 is($a, <<'EOCODI', 'no extra output when deparsing foo()');
307 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
308 .qq`"use feature q|:all|; my sub no; CORE::no less" 2>&1`;
309 like($a, qr/my sub no;\nCORE::no less;/,
310 'CORE::no after my sub no');
313 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
314 .qq`"use feature q|:all|; my sub use; CORE::use less" 2>&1`;
315 like($a, qr/my sub use;\nCORE::use less;/,
316 'CORE::use after my sub use');
319 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
320 .qq`"use feature q|:all|; my sub __DATA__; `
321 .qq`CORE::__DATA__" 2>&1`;
322 like($a, qr/my sub __DATA__;\n.*\nCORE::__DATA__/s,
323 'CORE::__DATA__ after my sub __DATA__');
326 $a = readpipe qq`$^X $path "-MO=Deparse" -e "sub foo{}" 2>&1`;
327 like($a, qr/sub foo\s*\{\s+\}/, 'sub declarations');
331 skip "BEGIN output is wrong on old perls", 1 if $] < 5.021006;
345 $a = readpipe qq`$^X $path "-MO=Deparse" -e "$prog" 2>&1`;
346 $a =~ s/-e syntax OK\n//g;
347 is($a, <<'EOCODJ', 'BEGIN blocks');
367 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ], prog => '
376 '), <<'EOCODL', 'BEGIN blocks at the end of their enclosing blocks';
394 my $prog = 'use constant FOO => do { 1 }; no overloading; die';
395 $a = readpipe qq`$^X $path "-MO=-qq,Deparse" -e "$prog" 2>&1`;
396 is($a, <<'EOCODK', '[perl #115066] use statements accidentally nested');
397 use constant ('FOO', do {
404 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
405 prog => 'use feature lexical_subs=>; my sub f;sub main::f{}'),
406 qr/^sub main::f \{/m,
407 'sub decl when lex sub is in scope';
409 done_testing($tests);
412 # TODO [perl #120950] This succeeds when run a 2nd time
416 # y/uni/code/ [perl #120950] This 2nd instance succeeds
422 # Constants in a block
423 # CONTEXT no warnings;
429 # Lexical and simple arithmetic
431 ++$test and $test /= 2;
434 $test /= 2 if ++$test;
439 # Assignment to list x
440 ((undef) x 3) = undef;
444 my $test = sub : lvalue {
452 my $test = sub : method {
458 # anonsub attrs at statement start
459 my $x = do { +sub : lvalue { my $y; } };
460 my $z = do { foo: +sub : method { my $a; } };
462 # block with continue
470 # lexical and package scalars
474 # lexical and package arrays
478 # lexical and package hashes
483 our($foo, $bar, $baz);
485 # CONTEXT { package Dog } use feature "state";
486 # variables with declared classes
496 my Dog ($foo, @bar, %baz);
497 our Dog ($phoo, @barr, %bazz);
498 state Dog ($fough, @barre, %bazze);
502 local our($rhu, $barb);
506 $_ .= <ARGV> . <$foo>;
509 my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
514 s/x/complex_expression();/e;
529 # 2 arguments in a 3 argument for
530 for (my $i = 0; $i < 2;) {
535 for (my $i = 0; $i < 2; ++$i) {
539 # 3 argument for again
540 for (my $i = 0; $i < 2; ++$i) {
544 # 3-argument for with inverted condition
545 for (my $i; not $i;) {
548 for (my $i; not $i; ++$i) {
551 for (my $a; not +($1 || 2) ** 2;) {
554 Something_to_put_the_loop_in_void_context();
558 while ($i) { my $z = 1; } continue { $i = 99; }
561 foreach my $i (1, 2) {
566 # foreach with my under -p
579 foreach my $i (1, 2) {
584 foreach our $i (1, 2) {
588 # foreach with my and our
590 foreach our $i (1, 2) {
595 # CONTEXT use feature "state";
596 foreach state $i (1, 2) {
602 print reverse sort(@x);
606 print((sort {$b cmp $a} @x));
608 # reverse sort with block
610 print((reverse sort {$b <=> $a} @x));
614 print $_ foreach (reverse @a);
616 # foreach reverse (not inplace)
618 print $_ foreach (reverse 1, 2..5);
622 @ary = split(' ', 'foo', 0);
625 our @array = split(//, 'foo', 0);
628 my @array = split(//, 'foo', 0);
634 do { my $x = 1; $x };
636 # <20061012113037.GJ25805@c4.convolution.nl>
655 sub foo {} foo & & & foo;
660 # variables as method names
663 'Foo'->$bar('orz') = 'a stranger stranger than before';
665 # constants as method names
668 # constants as method names without ()
671 # [perl #47359] "indirect" method call notation
675 foo{@bar}1 xor foo();
678 (foo { @bar } 1)->foo;
679 (foo { @bar } 1), foo();
680 foo { @bar } 1 xor foo();
682 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
683 # CONTEXT use feature ':5.10';
687 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
688 # CONTEXT use 5.10.0;
689 # say in the context of use 5.10.0
692 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
693 # say with use 5.10.0
701 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
702 # say with use feature ':5.10';
706 use feature 'say', 'state', 'switch';
709 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
710 # CONTEXT use feature ':5.10';
711 # say with use 5.10.0 in the context of use feature
719 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
720 # CONTEXT use 5.10.0;
721 # say with use feature ':5.10' in the context of use 5.10.0
727 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
728 # CONTEXT use feature ':5.15';
732 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
733 # CONTEXT use 5.15.0;
734 # __SUB__ in the context of use 5.15.0
737 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
738 # __SUB__ with use 5.15.0
746 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
747 # __SUB__ with use feature ':5.15';
751 use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval';
754 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
755 # CONTEXT use feature ':5.15';
756 # __SUB__ with use 5.15.0 in the context of use feature
764 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
765 # CONTEXT use 5.15.0;
766 # __SUB__ with use feature ':5.15' in the context of use 5.15.0
772 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
773 # CONTEXT use feature ':5.10';
777 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
778 # CONTEXT use feature ':5.10';
779 # state var assignment
781 my $y = (state $x = 42);
784 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
785 # CONTEXT use feature ':5.10';
786 # state vars in anonymous subroutines
793 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
798 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
799 # keys @array; values @array
800 keys @$a if keys @ARGV;
801 values @ARGV if values @$a;
803 # Anonymous arrays and hashes, and references to them
809 # SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
810 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
811 # implicit smartmatch in given/when
813 when ('bar') { continue; }
814 when ($_ ~~ 'quux') { continue; }
818 # conditions in elsifs (regression in change #33710 which fixed bug #37302)
821 elsif ($a and $b) { x(); }
822 elsif ($a or $b) { x(); }
825 # interpolation in regexps
829 # TODO new undocumented cpan-bug #33708
833 # TODO hash constants not yet fixed
835 use constant H => { "#" => 1 }; H->{"#"}
837 # TODO optimized away 0 not yet fixed
839 foreach my $i (@_) { 0 }
841 # tests with not, not optimized
844 x() if not $a and $b;
845 x() if $a and not $b;
846 x() unless not $a and $b;
847 x() unless $a and not $b;
850 x() unless not $a or $b;
851 x() unless $a or not $b;
852 x() if $a and not $b and $c;
853 x() if not $a and $b and not $c;
854 x() unless $a and not $b and $c;
855 x() unless not $a and $b and not $c;
856 x() if $a or not $b or $c;
857 x() if not $a or $b or not $c;
858 x() unless $a or not $b or $c;
859 x() unless not $a or $b or not $c;
861 # tests with not, optimized
865 x() if not $a and not $b;
866 x() unless not $a and not $b;
867 x() if not $a or not $b;
868 x() unless not $a or not $b;
869 x() if not $a and not $b and $c;
870 x() unless not $a and not $b and $c;
871 x() if not $a or not $b or $c;
872 x() unless not $a or not $b or $c;
873 x() if not $a and not $b and not $c;
874 x() unless not $a and not $b and not $c;
875 x() if not $a or not $b or not $c;
876 x() unless not $a or not $b or not $c;
877 x() unless not $a or not $b or not $c;
884 x() unless $a and $b;
886 x() if not $a || $b and $c;
887 x() unless not $a || $b and $c;
888 x() if not $a && $b or $c;
889 x() unless not $a && $b or $c;
890 x() unless $a or $b or $c;
891 x() if $a or $b or $c;
892 x() unless $a and $b and $c;
893 x() if $a and $b and $c;
894 x() unless not $a && $b && $c;
896 # tests that should be constant folded
900 x() if GLIPP && GLIPP;
901 x() if !GLIPP || GLIPP;
903 x() if do { no warnings 'void'; 5; GLIPP };
904 x() if do { !GLIPP };
905 if (GLIPP) { x() } else { z() }
906 if (!GLIPP) { x() } else { z() }
907 if (GLIPP) { x() } elsif (GLIPP) { z() }
908 if (!GLIPP) { x() } elsif (GLIPP) { z() }
909 if (GLIPP) { x() } elsif (!GLIPP) { z() }
910 if (!GLIPP) { x() } elsif (!GLIPP) { z() }
911 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (GLIPP) { t() }
912 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
913 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
947 # TODO constant deparsing has been backed out for 5.12
948 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
949 # tests that shouldn't be constant folded
950 # It might be fundamentally impossible to make this work on ithreads, in which
951 # case the TODO should become a SKIP
953 if ($a == 1) { x() } elsif ($b == 2) { z() }
954 if (do { foo(); GLIPP }) { x() }
955 if (do { $a++; GLIPP }) { x() }
958 if ($a == 1) { x(); } elsif ($b == 2) { z(); }
959 if (do { foo(); GLIPP }) { x(); }
960 if (do { ++$a; GLIPP }) { x(); }
962 # TODO constant deparsing has been backed out for 5.12
963 # tests for deparsing constants
966 # TODO constant deparsing has been backed out for 5.12
967 # tests for deparsing imported constants
970 # TODO constant deparsing has been backed out for 5.12
971 # tests for deparsing re-exported constants
974 # TODO constant deparsing has been backed out for 5.12
975 # tests for deparsing imported constants that got deleted from the original namespace
978 # TODO constant deparsing has been backed out for 5.12
979 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
980 # tests for deparsing constants which got turned into full typeglobs
981 # It might be fundamentally impossible to make this work on ithreads, in which
982 # case the TODO should become a SKIP
984 eval '@Fcntl::O_EXCL = qw/affe tiger/;';
987 # TODO constant deparsing has been backed out for 5.12
988 # tests for deparsing of blessed constant with overloaded numification
989 warn OVERLOADED_NUMIFICATION;
1003 # TODO Subsets of warnings could be encoded textually, rather than as bitflips.
1004 # subsets of warnings
1005 no warnings 'deprecated';
1008 # TODO Better test for CPAN #33708 - the deparsed code has different behaviour
1024 # SKIP ?$] > 5.013006 && ":= is now a syntax error"
1025 # := treated as an empty attribute list
1032 # : = empty attribute list
1051 # #71870 Use of uninitialized value in bitwise and B::Deparse
1053 @a = split(/foo/, $s, 0);
1055 @a = split(/$r/, $s, 0);
1058 # package declaration before label
1064 # shift optimisation
1069 # shift optimisation
1072 # shift optimisation
1077 # shift optimisation
1081 "foo" =~ (1 ? /foo/ : /bar/);
1082 "foo" =~ (1 ? y/foo// : /bar/);
1083 "foo" =~ (1 ? y/foo//r : /bar/);
1084 "foo" =~ (1 ? s/foo// : /bar/);
1086 'foo' =~ ($_ =~ /foo/);
1087 'foo' =~ ($_ =~ tr/fo//);
1088 'foo' =~ ($_ =~ tr/fo//r);
1089 'foo' =~ ($_ =~ s/foo//);
1091 # The fix for [perl #20444] broke this.
1094 # [perl #81424] match against aelemfast_lex
1105 # [perl #91318] /regexp/applaud
1106 print /a/a, s/b/c/a;
1107 print /a/aa, s/b/c/aa;
1108 print /a/p, s/b/c/p;
1109 print /a/l, s/b/c/l;
1110 print /a/u, s/b/c/u;
1112 use feature "unicode_strings";
1113 print /a/d, s/b/c/d;
1117 print /a/d, s/b/c/d;
1121 print /a/d, s/b/c/d;
1124 print /a/a, s/b/c/a;
1125 print /a/aa, s/b/c/aa;
1126 print /a/p, s/b/c/p;
1127 print /a/l, s/b/c/l;
1128 print /a/u, s/b/c/u;
1130 use feature 'unicode_strings';
1131 print /a/d, s/b/c/d;
1134 BEGIN { $^H{'reflags'} = '0';
1135 $^H{'reflags_charset'} = '2'; }
1136 print /a/d, s/b/c/d;
1140 use feature ':5.12';
1141 print /a/d, s/b/c/d;
1144 # [perl #119807] s//\(3)/ge should not warn when deparsed (\3 warns)
1148 "" =~ /a(?{ print q|
1151 '' =~ /a(?{ print "\n"; })/;
1154 $_ = qr/(??{<<END})/
1159 $_ = qr/(??{ "f.o\nb.r\n"; })/;
1161 # More regexp code block madness
1168 /a(??{ die $b; })a/;
1169 /$a(??{ die $b; })/;
1170 /@a(??{ die $b; })/;
1172 qr/a(?{ die $b; })a/;
1173 qr/$a(?{ die $b; })/;
1174 qr/@a(?{ die $b; })/;
1175 qr/(??{ die $b; })/;
1176 qr/a(??{ die $b; })a/;
1177 qr/$a(??{ die $b; })/;
1178 qr/@a(??{ die $b; })/;
1180 s/a(?{ die $b; })a//;
1181 s/$a(?{ die $b; })//;
1182 s/@a(?{ die $b; })//;
1183 s/(??{ die $b; })//;
1184 s/a(??{ die $b; })a//;
1185 s/$a(??{ die $b; })//;
1186 s/@a(??{ die $b; })//;
1189 tr/a/b/r + $a =~ tr/p/q/r;
1191 # y///d in list [perl #119815]
1198 # CONTEXT no warnings 'experimental::autoderef';
1203 # readpipe with complex expression
1209 # aelemfast for a lexical
1213 # feature features without feature
1214 # CONTEXT no warnings 'experimental::smartmatch';
1229 # feature features when feature has been disabled by use VERSION
1230 # CONTEXT no warnings 'experimental::smartmatch';
1231 use feature (sprintf(":%vd", $^V));
1259 # (the above test with CONTEXT, and the output is equivalent but different)
1260 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
1261 # feature features when feature has been disabled by use VERSION
1262 use feature (sprintf(":%vd", $^V));
1278 use feature ':default';
1292 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1293 # lexical subroutines and keywords of the same name
1294 # CONTEXT use feature 'lexical_subs', 'switch'; no warnings 'experimental';
1318 CORE::default { die; }
1319 CORE::if ($1) { die; }
1320 CORE::if ($1) { die; }
1321 CORE::elsif ($1) { die; }
1323 CORE::for (die; $1; die) { die; }
1324 CORE::foreach $_ (1 .. 10) { die; }
1325 die CORE::foreach (1);
1326 CORE::given ($1) { die; }
1331 () = (CORE::q['], CORE::qq["$_], CORE::qr//, CORE::qx[`]);
1334 () = CORE::sub { die; } ;
1336 CORE::unless ($1) { die; }
1337 CORE::until ($1) { die; }
1340 CORE::when ($1 ~~ $2) { die; }
1341 CORE::while ($1) { die; }
1345 use feature 'current_sub', 'evalbytes';
1351 no feature 'unicode_strings';
1354 use feature 'current_sub', 'evalbytes';
1357 use feature ':default';
1360 use feature ':5.12';
1362 no feature 'unicode_strings';
1365 # $#- $#+ $#{%} etc.
1367 @x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
1368 @x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
1369 @x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
1370 @x = ($#{;}, $#{:});
1373 # It's a known TODO that warnings are deparsed as bits, not textually.
1377 # [perl #86060] $( $| $) in regexps need braces
1387 # sort(foo(bar)) is interpreted as sort &foo(bar)
1388 # sort foo(bar) is interpreted as sort foo bar
1389 # parentheses are not optional in this case
1390 print sort(foo('bar'));
1392 print sort(foo('bar'));
1395 substr(my $a, 0, 0) = (foo(), bar());
1398 # This following line works around an unfixed bug that we are not trying to
1400 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1402 BEGIN { $^H{'foo'} = undef; }
1404 BEGIN { $^H{'bar'} = undef; }
1406 BEGIN { $^H{'baz'} = undef; }
1414 BEGIN { $^H{q[']} = '('; }
1417 # This following line works around an unfixed bug that we are not trying to
1419 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1420 # hint hash changes that serialise the same way with sort %hh
1421 BEGIN { $^H{'a'} = 'b'; }
1423 BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
1428 # [perl #47361] do({}) and do +{} (variants of do-file)
1442 # [perl #77096] functions that do not follow the llafr
1443 () = (return 1) + time;
1444 () = (return ($1 + $2) * $3) + time;
1445 () = (return ($a xor $b)) + time;
1446 () = (do 'file') + time;
1447 () = (do ($1 + $2) * $3) + time;
1448 () = (do ($1 xor $2)) + time;
1450 () = (require 'foo') + 3;
1451 () = (require foo) + 3;
1452 () = (CORE::dump 1) + 3;
1463 # [perl #97476] not() *does* follow the llafr
1464 $_ = ($a xor not +($1 || 2) ** 2);
1466 # Precedence conundrums with argument-less function calls
1474 # loopexes have assignment prec
1475 () = (CORE::dump a) | 'b';
1476 () = (goto a) | 'b';
1477 () = (last a) | 'b';
1478 () = (next a) | 'b';
1479 () = (redo a) | 'b';
1481 # [perl #63558] open local(*FH)
1483 pipe local *FH, local *FH;
1485 # [perl #91416] open "string"
1498 () = 'open'->[0]; #aelemfast
1503 () = 'open'->[$_]; #aelem
1508 () = 'open'->{0}; #helem
1529 () = 'a::]b'->{'0'};
1531 # [perl #74740] -(f()) vs -f()
1537 #[perl #30504] foreach-my postfix/prefix difference
1538 $_ = 'foo' foreach my ($foo1, $bar1, $baz1);
1539 foreach (my ($foo2, $bar2, $baz2)) { $_ = 'foo' }
1540 foreach my $i (my ($foo3, $bar3, $baz3)) { $i = 'foo' }
1542 $_ = 'foo' foreach (my($foo1, $bar1, $baz1));
1543 foreach $_ (my($foo2, $bar2, $baz2)) {
1546 foreach my $i (my($foo3, $bar3, $baz3)) {
1550 #[perl #108224] foreach with continue block
1551 foreach (1 .. 3) { print } continue { print "\n" }
1552 foreach (1 .. 3) { } continue { }
1553 foreach my $i (1 .. 3) { print $i } continue { print "\n" }
1554 foreach my $i (1 .. 3) { } continue { }
1556 foreach $_ (1 .. 3) {
1562 foreach $_ (1 .. 3) {
1568 foreach my $i (1 .. 3) {
1574 foreach my $i (1 .. 3) {
1595 # 'my' works with padrange op
1602 ($m3, $m4) = (1, 2);
1604 my($m5, $m6) = (1, 2);
1605 my($m7, undef, $m8) = (1, 2, 3);
1606 @z = ($m7, undef, $m8);
1607 ($m7, undef, $m8) = (1, 2, 3);
1609 # 'our/local' works with padrange op
1620 ($o3, $o4) = (1, 2);
1621 local($o3, $o4) = (1, 2);
1623 @z = local($o3, $o4);
1624 our($o5, $o6) = (1, 2);
1625 our($o7, undef, $o8) = (1, 2, 3);
1626 @z = ($o7, undef, $o8);
1627 @z = local($o7, undef, $o8);
1628 ($o7, undef, $o8) = (1, 2, 3);
1629 local($o7, undef, $o8) = (1, 2, 3);
1631 # 'state' works with padrange op
1632 # CONTEXT no strict; use feature 'state';
1639 ($s3, $s4) = (1, 2);
1641 # assignment of state lists isn't implemented yet
1642 #state($s5, $s6) = (1, 2);
1643 #state($s7, undef, $s8) = (1, 2, 3);
1644 #@z = ($s7, undef, $s8);
1645 ($s7, undef, $s8) = (1, 2, 3);
1647 # anon arrays with padrange
1652 # slices with padrange
1658 # binops with padrange
1672 my($a, $b, $c, $d, @e);
1677 @e = ($a, $b, $c) x $d;
1681 my($a, $b, $c) = @_;
1683 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1684 # lexical subroutine
1685 use feature 'lexical_subs';
1686 no warnings "experimental::lexical_subs";
1690 use feature 'lexical_subs';
1691 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUUU\005"}
1693 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUU\005"}
1696 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUU\005"}
1699 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1700 # lexical "state" subroutine
1701 use feature 'state', 'lexical_subs';
1702 no warnings 'experimental::lexical_subs';
1706 use feature 'lexical_subs';
1707 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUUU\005"}
1709 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUU\005"}
1710 use feature 'state';
1713 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUU\005"}
1714 use feature 'state';
1717 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1718 # lexical subroutine scoping
1719 # CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
1737 # Elements of %# should not be confused with $#{ array }
1740 # [perl #121050] Prototypes with whitespace
1741 sub _121050(\$ \$) { }
1743 sub _121050empty( ) {}
1744 () = _121050empty() + 1;
1747 () = _121050empty + 1;
1749 # ensure aelemfast works in the range -128..127 and that there's no
1753 $x = $a[-256] + $a[-255] + $a[-129] + $a[-128] + $a[-127] + $a[-1] + $a[0];
1754 $x = $a[1] + $a[126] + $a[127] + $a[128] + $a[255] + $a[256];
1756 $x = $b[-256] + $b[-255] + $b[-129] + $b[-128] + $b[-127] + $b[-1] + $b[0];
1757 $x = $b[1] + $b[126] + $b[127] + $b[128] + $b[255] + $b[256];
1759 # 'm' must be preserved in m??
1762 # \(@array) and \(..., (@array), ...)
1763 my(@array, %hash, @a, @b, %c, %d);
1766 () = \(@a, (@b), (%c), %d);
1767 () = \(@Foo::array);
1769 () = \(@Foo::a, (@Foo::b), (%Foo::c), %Foo::d);
1771 # subs synonymous with keywords
1775 use feature 'state';
1779 # CONTEXT use feature "state", 'refaliasing', 'lexical_subs'; no warnings 'experimental';
1791 \($x, my $a) = @{[\$x, \$x]};
1792 (\$x, \my $b) = @{[\$x, \$x]};
1804 \local($a[1]) = foo();
1807 \local @a[0,1] = (\$a)x2;
1814 \local($h{b}) = \$x;
1815 \@h{'a','b'} = foo();
1817 \local @h{'a','b'} = (\$x)x2;
1853 (\$_, $_) = \(1, 2);
1854 $_ == 3 ? \$_ : $_ = \3;
1855 $_ == 3 ? \$_ : \$x = \3;
1856 \($_ == 3 ? $_ : $x) = \3;
1857 for \my $topic (\$1, \$2) {
1860 for \state $topic (\$1, \$2) {
1863 for \our $topic (\$1, \$2) {
1866 for \$_ (\$1, \$2) {
1869 for \my @a ([1,2], [3,4]) {
1872 for \state @a ([1,2], [3,4]) {
1875 for \our @a ([1,2], [3,4]) {
1878 for \@_ ([1,2], [3,4]) {
1881 for \my %a ({5,6}, {7,8}) {
1884 for \our %a ({5,6}, {7,8}) {
1887 for \state %a ({5,6}, {7,8}) {
1890 for \%_ ({5,6}, {7,8}) {
1895 for \&a (sub { 9; }, sub { 10; }) {
1899 for \&a (sub { 9; }, sub { 10; }) {
1914 (\$x, \my $a) = @{[\$x, \$x];};
1915 (\$x, \my $b) = @{[\$x, \$x];};
1927 (\local $a[1]) = foo();
1928 (\@a[0, 1]) = foo();
1929 (\@a[2, 3]) = foo();
1930 (\local @a[0, 1]) = (\$a) x 2;
1936 \local $h{'a'} = \$x;
1937 (\local $h{'b'}) = \$x;
1938 (\@h{'a', 'b'}) = foo();
1939 (\@h{2, 3}) = foo();
1940 (\local @h{'a', 'b'}) = (\$x) x 2;
1966 (\our %zz) = {1, 2};
1976 (\$_, $_) = \(1, 2);
1977 $_ == 3 ? \$_ : $_ = \3;
1978 $_ == 3 ? \$_ : \$x = \3;
1979 ($_ == 3 ? \$_ : \$x) = \3;
1980 foreach \my $topic (\$1, \$2) {
1983 foreach \state $topic (\$1, \$2) {
1986 foreach \our $topic (\$1, \$2) {
1989 foreach \$_ (\$1, \$2) {
1992 foreach \my @a ([1, 2], [3, 4]) {
1995 foreach \state @a ([1, 2], [3, 4]) {
1998 foreach \our @a ([1, 2], [3, 4]) {
2001 foreach \@_ ([1, 2], [3, 4]) {
2004 foreach \my %a ({5, 6}, {7, 8}) {
2007 foreach \our %a ({5, 6}, {7, 8}) {
2010 foreach \state %a ({5, 6}, {7, 8}) {
2013 foreach \%_ ({5, 6}, {7, 8}) {
2018 foreach \&a (sub { 9; } , sub { 10; } ) {
2022 foreach \&a (sub { 9; } , sub { 10; } ) {
2031 $_ = join('???', pos $_);