6 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7 print "1..0 # Skip -- Perl configured without B module\n";
16 my $tests = 25; # 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 # Like this to avoid needing a label SKIP:
49 Test::More->builder->skip($meta{skip});
53 my ($input, $expected);
54 if (/(.*)\n>>>>\n(.*)/s) {
55 ($input, $expected) = ($1, $2);
58 ($input, $expected) = ($_, $_);
61 # parse options if necessary
62 my $deparse = $meta{options}
63 ? $deparse{$meta{options}} ||=
64 new B::Deparse split /,/, $meta{options}
67 my $coderef = eval "$meta{context};\n" . <<'EOC' . "sub {$input}";
68 # Tell B::Deparse about our ambient pragmas
69 my ($hint_bits, $warning_bits, $hinthash);
71 ($hint_bits, $warning_bits, $hinthash) = ($^H, ${^WARNING_BITS}, \%^H);
73 $deparse->ambient_pragmas (
74 hint_bits => $hint_bits,
75 warning_bits => $warning_bits,
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 local $::TODO = $meta{todo};
91 like($deparsed, qr/$regex/, $desc);
95 # Reset the ambient pragmas
99 ($b, $w, $h) = ($^H, ${^WARNING_BITS}, \%^H);
101 $deparse->ambient_pragmas (
108 use constant 'c', 'stuff';
109 is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff',
110 'the subroutine generated by use constant deparses');
113 is($deparse->coderef2text(sub{(-1) ** $a }), "{\n (-1) ** \$a;\n}",
114 'anon sub capturing an external lexical');
116 use constant cr => ['hello'];
117 my $string = "sub " . $deparse->coderef2text(\&cr);
118 my $val = (eval $string)->() or diag $string;
119 is(ref($val), 'ARRAY', 'constant array references deparse');
120 is($val->[0], 'hello', 'and return the correct value');
122 my $path = join " ", map { qq["-I$_"] } @INC;
124 $a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 2>&1`;
125 $a =~ s/-e syntax OK\n//g;
126 $a =~ s/.*possible typo.*\n//; # Remove warning line
127 $a =~ s/.*-i used with no filenames.*\n//; # Remove warning line
128 $a =~ s{\\340\\242}{\\s} if (ord("\\") == 224); # EBCDIC, cp 1047 or 037
129 $a =~ s{\\274\\242}{\\s} if (ord("\\") == 188); # $^O eq 'posix-bc'
130 $b = quotemeta <<'EOF';
131 BEGIN { $^I = ".bak"; }
133 BEGIN { $/ = "\n"; $\ = "\n"; }
134 LINE: while (defined($_ = <ARGV>)) {
136 our(@F) = split(' ', $_, 0);
140 $b =~ s/our\\\(\\\@F\\\)/our[( ]\@F\\)?/; # accept both our @F and our(@F)
142 'command line flags deparse as BEGIN blocks setting control variables');
144 $a = `$^X $path "-MO=Deparse" -e "use constant PI => 4" 2>&1`;
145 $a =~ s/-e syntax OK\n//g;
146 is($a, "use constant ('PI', 4);\n",
147 "Proxy Constant Subroutines must not show up as (incorrect) prototypes");
149 #Re: perlbug #35857, patch #24505
150 #handle warnings::register-ed packages properly.
151 package B::Deparse::Wrapper;
154 use warnings::register;
156 my $deparser = B::Deparse->new();
157 return $deparser->coderef2text(shift);
161 use overload '0+' => sub { 42 };
166 use constant GLIPP => 'glipp';
167 use constant PI => 4;
168 use constant OVERLOADED_NUMIFICATION => bless({}, 'Moo');
169 use Fcntl qw/O_TRUNC O_APPEND O_EXCL/;
170 BEGIN { delete $::Fcntl::{O_APPEND}; }
171 use POSIX qw/O_CREAT/;
174 my $res = B::Deparse::Wrapper::getcode($val);
175 like($res, qr/use warnings/,
176 '[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly');
179 my $x=sub { ++$q,++$p };
181 eval <<EOFCODE and test($x);
185 use warnings::register;
190 # Exotic sub declarations
191 $a = `$^X $path "-MO=Deparse" -e "sub ::::{}sub ::::::{}" 2>&1`;
192 $a =~ s/-e syntax OK\n//g;
193 is($a, <<'EOCODG', "sub :::: and sub ::::::");
203 $a = `$^X $path "-MO=Deparse,-l" -e "map{ eval(0) }()" 2>&1`;
204 $a =~ s/-e syntax OK\n//g;
205 is($a, <<'EOCODH', "[perl #117311] [PATCH] -l option ('#line ...') does not emit ^Ls in the output");
214 my $code = <<"EOCODE";
216 our \$\x{1e1f}\x{14d}\x{14d};
220 = $deparse->coderef2text(eval "sub { our \$\x{1e1f}\x{14d}\x{14d} }" );
221 s/$ \n//x for $deparsed, $code;
222 is $deparsed, $code, 'our $funny_Unicode_chars';
227 `$^X $path "-MO=Deparse" -e "BEGIN{*CORE::GLOBAL::require=sub{1}}" 2>&1`;
228 $a =~ s/-e syntax OK\n//g;
229 is($a, <<'EOCODF', "CORE::GLOBAL::require override causing panick");
231 *CORE::GLOBAL::require = sub {
240 `$^X $path "-MO=Deparse" -e "BEGIN{*Acme::Acme:: = *Acme::}" 2>&1`;
241 like($a, qr/-e syntax OK/,
242 "Deparse does not hang when traversing stash circularities");
246 is($deparse->coderef2text(sub{ print "foo@{]}" }),
249 }>, 'curly around to interpolate "@{]}"');
250 is($deparse->coderef2text(sub{ print "foo@{-}" }),
253 }>, 'no need to curly around to interpolate "@-"');
255 # Strict hints in %^H are mercilessly suppressed
257 `$^X $path "-MO=Deparse" -e "use strict; print;" 2>&1`;
258 unlike($a, qr/BEGIN/,
259 "Deparse does not emit strict hh hints");
261 # ambient_pragmas should not mess with strict settings.
263 skip "requires 5.11", 1 unless $] >= 5.011;
266 # Clear out all hints
269 new B::Deparse -> ambient_pragmas(strict => 'all');
271 use 5.011; # should enable strict
272 ok !eval '$do_noT_create_a_variable_with_this_name = 1',
273 'ambient_pragmas do not mess with compiling scope';
277 # multiple statements on format lines
278 $a = `$^X $path "-MO=Deparse" -e "format =" -e "\@" -e "x();z()" -e. 2>&1`;
279 $a =~ s/-e syntax OK\n//g;
280 is($a, <<'EOCODH', 'multiple statements on format lines');
288 $a = readpipe qq`$^X $path "-MO=Deparse" -e "use feature q|:all|;`
289 .qq` my sub format; CORE::format =" -e. 2>&1`;
290 like($a, qr/CORE::format/, 'CORE::format when lex format sub is in scope');
292 # literal big chars under 'use utf8'
293 is($deparse->coderef2text(sub{ use utf8; /€/; }),
299 # STDERR when deparsing sub calls
300 # For a short while the output included 'While deparsing'
301 $a = `$^X $path "-MO=Deparse" -e "foo()" 2>&1`;
302 $a =~ s/-e syntax OK\n//g;
303 is($a, <<'EOCODI', 'no extra output when deparsing foo()');
308 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
309 .qq`"use feature q|:all|; my sub no; CORE::no less" 2>&1`;
310 like($a, qr/my sub no;\n\(\);\nCORE::no less;/,
311 'CORE::no after my sub no');
314 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
315 .qq`"use feature q|:all|; my sub use; CORE::use less" 2>&1`;
316 like($a, qr/my sub use;\n\(\);\nCORE::use less;/,
317 'CORE::use after my sub use');
320 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
321 .qq`"use feature q|:all|; my sub __DATA__; `
322 .qq`CORE::__DATA__" 2>&1`;
323 like($a, qr/my sub __DATA__;\n\(\);\nCORE::__DATA__/,
324 'CORE::__DATA__ after my sub __DATA__');
327 done_testing($tests);
330 # TODO [perl #120950] This succeeds when run a 2nd time
334 # y/uni/code/ [perl #120950] This 2nd instance succeeds
340 # Constants in a block
341 # CONTEXT no warnings;
347 # Lexical and simple arithmetic
349 ++$test and $test /= 2;
352 $test /= 2 if ++$test;
359 my $test = sub : lvalue {
367 my $test = sub : method {
373 # block with continue
381 # lexical and package scalars
385 # lexical and package arrays
389 # lexical and package hashes
394 our($foo, $bar, $baz);
396 # CONTEXT { package Dog } use feature "state";
397 # variables with declared classes
407 my Dog ($foo, @bar, %baz);
408 our Dog ($phoo, @barr, %bazz);
409 state Dog ($fough, @barre, %bazze);
413 local our($rhu, $barb);
417 $_ .= <ARGV> . <$foo>;
420 my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
425 s/x/complex_expression();/e;
440 # 2 arguments in a 3 argument for
441 for (my $i = 0; $i < 2;) {
446 for (my $i = 0; $i < 2; ++$i) {
450 # 3 argument for again
451 for (my $i = 0; $i < 2; ++$i) {
455 # 3-argument for with inverted condition
456 for (my $i; not $i;) {
459 for (my $i; not $i; ++$i) {
462 for (my $a; not +($1 || 2) ** 2;) {
465 Something_to_put_the_loop_in_void_context();
469 while ($i) { my $z = 1; } continue { $i = 99; }
472 foreach my $i (1, 2) {
477 # foreach with my under -p
490 foreach my $i (1, 2) {
495 foreach our $i (1, 2) {
499 # foreach with my and our
501 foreach our $i (1, 2) {
506 # CONTEXT use feature "state";
507 foreach state $i (1, 2) {
513 print reverse sort(@x);
517 print((sort {$b cmp $a} @x));
519 # reverse sort with block
521 print((reverse sort {$b <=> $a} @x));
525 print $_ foreach (reverse @a);
527 # foreach reverse (not inplace)
529 print $_ foreach (reverse 1, 2..5);
533 @ary = split(' ', 'foo', 0);
536 our @array = split(//, 'foo', 0);
539 my @array = split(//, 'foo', 0);
545 do { my $x = 1; $x };
547 # <20061012113037.GJ25805@c4.convolution.nl>
566 sub foo {} foo & & & foo;
571 # variables as method names
574 'Foo'->$bar('orz') = 'a stranger stranger than before';
576 # constants as method names
579 # constants as method names without ()
582 # [perl #47359] "indirect" method call notation
586 foo{@bar}1 xor foo();
589 (foo { @bar } 1)->foo;
590 (foo { @bar } 1), foo();
591 foo { @bar } 1 xor foo();
593 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
594 # CONTEXT use feature ':5.10';
598 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
599 # CONTEXT use 5.10.0;
600 # say in the context of use 5.10.0
603 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
604 # say with use 5.10.0
612 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
613 # say with use feature ':5.10';
617 use feature 'say', 'state', 'switch';
620 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
621 # CONTEXT use feature ':5.10';
622 # say with use 5.10.0 in the context of use feature
630 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
631 # CONTEXT use 5.10.0;
632 # say with use feature ':5.10' in the context of use 5.10.0
638 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
639 # CONTEXT use feature ':5.15';
643 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
644 # CONTEXT use 5.15.0;
645 # __SUB__ in the context of use 5.15.0
648 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
649 # __SUB__ with use 5.15.0
657 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
658 # __SUB__ with use feature ':5.15';
662 use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval';
665 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
666 # CONTEXT use feature ':5.15';
667 # __SUB__ with use 5.15.0 in the context of use feature
675 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
676 # CONTEXT use 5.15.0;
677 # __SUB__ with use feature ':5.15' in the context of use 5.15.0
683 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
684 # CONTEXT use feature ':5.10';
688 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
689 # CONTEXT use feature ':5.10';
690 # state var assignment
692 my $y = (state $x = 42);
695 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
696 # CONTEXT use feature ':5.10';
697 # state vars in anonymous subroutines
704 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
709 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
710 # keys @array; values @array
711 keys @$a if keys @ARGV;
712 values @ARGV if values @$a;
714 # Anonymous arrays and hashes, and references to them
720 # SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
721 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
722 # implicit smartmatch in given/when
724 when ('bar') { continue; }
725 when ($_ ~~ 'quux') { continue; }
729 # conditions in elsifs (regression in change #33710 which fixed bug #37302)
732 elsif ($a and $b) { x(); }
733 elsif ($a or $b) { x(); }
736 # interpolation in regexps
740 # TODO new undocumented cpan-bug #33708
744 # TODO hash constants not yet fixed
746 use constant H => { "#" => 1 }; H->{"#"}
748 # TODO optimized away 0 not yet fixed
750 foreach my $i (@_) { 0 }
752 # tests with not, not optimized
755 x() if not $a and $b;
756 x() if $a and not $b;
757 x() unless not $a and $b;
758 x() unless $a and not $b;
761 x() unless not $a or $b;
762 x() unless $a or not $b;
763 x() if $a and not $b and $c;
764 x() if not $a and $b and not $c;
765 x() unless $a and not $b and $c;
766 x() unless not $a and $b and not $c;
767 x() if $a or not $b or $c;
768 x() if not $a or $b or not $c;
769 x() unless $a or not $b or $c;
770 x() unless not $a or $b or not $c;
772 # tests with not, optimized
776 x() if not $a and not $b;
777 x() unless not $a and not $b;
778 x() if not $a or not $b;
779 x() unless not $a or not $b;
780 x() if not $a and not $b and $c;
781 x() unless not $a and not $b and $c;
782 x() if not $a or not $b or $c;
783 x() unless not $a or not $b or $c;
784 x() if not $a and not $b and not $c;
785 x() unless not $a and not $b and not $c;
786 x() if not $a or not $b or not $c;
787 x() unless not $a or not $b or not $c;
788 x() unless not $a or not $b or not $c;
795 x() unless $a and $b;
797 x() if not $a || $b and $c;
798 x() unless not $a || $b and $c;
799 x() if not $a && $b or $c;
800 x() unless not $a && $b or $c;
801 x() unless $a or $b or $c;
802 x() if $a or $b or $c;
803 x() unless $a and $b and $c;
804 x() if $a and $b and $c;
805 x() unless not $a && $b && $c;
807 # tests that should be constant folded
811 x() if GLIPP && GLIPP;
812 x() if !GLIPP || GLIPP;
814 x() if do { no warnings 'void'; 5; GLIPP };
815 x() if do { !GLIPP };
816 if (GLIPP) { x() } else { z() }
817 if (!GLIPP) { x() } else { z() }
818 if (GLIPP) { x() } elsif (GLIPP) { z() }
819 if (!GLIPP) { x() } elsif (GLIPP) { z() }
820 if (GLIPP) { x() } elsif (!GLIPP) { z() }
821 if (!GLIPP) { x() } elsif (!GLIPP) { z() }
822 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (GLIPP) { t() }
823 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
824 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
858 # TODO constant deparsing has been backed out for 5.12
859 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
860 # tests that shouldn't be constant folded
861 # It might be fundamentally impossible to make this work on ithreads, in which
862 # case the TODO should become a SKIP
864 if ($a == 1) { x() } elsif ($b == 2) { z() }
865 if (do { foo(); GLIPP }) { x() }
866 if (do { $a++; GLIPP }) { x() }
869 if ($a == 1) { x(); } elsif ($b == 2) { z(); }
870 if (do { foo(); GLIPP }) { x(); }
871 if (do { ++$a; GLIPP }) { x(); }
873 # TODO constant deparsing has been backed out for 5.12
874 # tests for deparsing constants
877 # TODO constant deparsing has been backed out for 5.12
878 # tests for deparsing imported constants
881 # TODO constant deparsing has been backed out for 5.12
882 # tests for deparsing re-exported constants
885 # TODO constant deparsing has been backed out for 5.12
886 # tests for deparsing imported constants that got deleted from the original namespace
889 # TODO constant deparsing has been backed out for 5.12
890 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
891 # tests for deparsing constants which got turned into full typeglobs
892 # It might be fundamentally impossible to make this work on ithreads, in which
893 # case the TODO should become a SKIP
895 eval '@Fcntl::O_EXCL = qw/affe tiger/;';
898 # TODO constant deparsing has been backed out for 5.12
899 # tests for deparsing of blessed constant with overloaded numification
900 warn OVERLOADED_NUMIFICATION;
914 # TODO Subsets of warnings could be encoded textually, rather than as bitflips.
915 # subsets of warnings
916 no warnings 'deprecated';
919 # TODO Better test for CPAN #33708 - the deparsed code has different behaviour
935 # SKIP ?$] > 5.013006 && ":= is now a syntax error"
936 # := treated as an empty attribute list
943 # : = empty attribute list
962 # #71870 Use of uninitialized value in bitwise and B::Deparse
964 @a = split(/foo/, $s, 0);
966 @a = split(/$r/, $s, 0);
969 # package declaration before label
992 "foo" =~ (1 ? /foo/ : /bar/);
993 "foo" =~ (1 ? y/foo// : /bar/);
994 "foo" =~ (1 ? y/foo//r : /bar/);
995 "foo" =~ (1 ? s/foo// : /bar/);
997 'foo' =~ ($_ =~ /foo/);
998 'foo' =~ ($_ =~ tr/fo//);
999 'foo' =~ ($_ =~ tr/fo//r);
1000 'foo' =~ ($_ =~ s/foo//);
1002 # The fix for [perl #20444] broke this.
1005 # [perl #81424] match against aelemfast_lex
1012 # [perl #91318] /regexp/applaud
1013 print /a/a, s/b/c/a;
1014 print /a/aa, s/b/c/aa;
1015 print /a/p, s/b/c/p;
1016 print /a/l, s/b/c/l;
1017 print /a/u, s/b/c/u;
1019 use feature "unicode_strings";
1020 print /a/d, s/b/c/d;
1024 print /a/d, s/b/c/d;
1028 print /a/d, s/b/c/d;
1031 print /a/a, s/b/c/a;
1032 print /a/aa, s/b/c/aa;
1033 print /a/p, s/b/c/p;
1034 print /a/l, s/b/c/l;
1035 print /a/u, s/b/c/u;
1037 use feature 'unicode_strings';
1038 print /a/d, s/b/c/d;
1041 BEGIN { $^H{'reflags'} = '0';
1042 $^H{'reflags_charset'} = '2'; }
1043 print /a/d, s/b/c/d;
1047 use feature ':5.12';
1048 print /a/d, s/b/c/d;
1051 # [perl #119807] s//\(3)/ge should not warn when deparsed (\3 warns)
1061 # CONTEXT no warnings 'experimental::autoderef';
1066 # readpipe with complex expression
1072 # aelemfast for a lexical
1076 # feature features without feature
1077 # CONTEXT no warnings 'experimental::smartmatch';
1092 # feature features when feature has been disabled by use VERSION
1093 # CONTEXT no warnings 'experimental::smartmatch';
1094 use feature (sprintf(":%vd", $^V));
1122 # (the above test with CONTEXT, and the output is equivalent but different)
1123 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
1124 # feature features when feature has been disabled by use VERSION
1125 use feature (sprintf(":%vd", $^V));
1141 use feature ':default';
1155 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1156 # lexical subroutines and keywords of the same name
1157 # CONTEXT use feature 'lexical_subs', 'switch'; no warnings 'experimental';
1181 CORE::default { die; }
1182 CORE::if ($1) { die; }
1183 CORE::if ($1) { die; }
1184 CORE::elsif ($1) { die; }
1186 CORE::for (die; $1; die) { die; }
1187 CORE::foreach $_ (1 .. 10) { die; }
1188 die CORE::foreach (1);
1189 CORE::given ($1) { die; }
1194 () = (CORE::q['], CORE::qq["$_], CORE::qr//, CORE::qx[`]);
1197 () = CORE::sub { die; } ;
1199 CORE::unless ($1) { die; }
1200 CORE::until ($1) { die; }
1203 CORE::when ($1 ~~ $2) { die; }
1204 CORE::while ($1) { die; }
1208 use feature 'current_sub', 'evalbytes';
1214 no feature 'unicode_strings';
1217 use feature 'current_sub', 'evalbytes';
1220 use feature ':default';
1223 use feature ':5.12';
1225 no feature 'unicode_strings';
1228 # $#- $#+ $#{%} etc.
1230 @x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
1231 @x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
1232 @x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
1233 @x = ($#{;}, $#{:});
1236 # It's a known TODO that warnings are deparsed as bits, not textually.
1240 # [perl #86060] $( $| $) in regexps need braces
1250 # sort(foo(bar)) is interpreted as sort &foo(bar)
1251 # sort foo(bar) is interpreted as sort foo bar
1252 # parentheses are not optional in this case
1253 print sort(foo('bar'));
1255 print sort(foo('bar'));
1258 substr(my $a, 0, 0) = (foo(), bar());
1261 # This following line works around an unfixed bug that we are not trying to
1263 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1265 BEGIN { $^H{'foo'} = undef; }
1267 BEGIN { $^H{'bar'} = undef; }
1269 BEGIN { $^H{'baz'} = undef; }
1277 BEGIN { $^H{q[']} = '('; }
1280 # This following line works around an unfixed bug that we are not trying to
1282 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1283 # hint hash changes that serialise the same way with sort %hh
1284 BEGIN { $^H{'a'} = 'b'; }
1286 BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
1291 # [perl #47361] do({}) and do +{} (variants of do-file)
1305 # [perl #77096] functions that do not follow the llafr
1306 () = (return 1) + time;
1307 () = (return ($1 + $2) * $3) + time;
1308 () = (return ($a xor $b)) + time;
1309 () = (do 'file') + time;
1310 () = (do ($1 + $2) * $3) + time;
1311 () = (do ($1 xor $2)) + time;
1313 () = (require 'foo') + 3;
1314 () = (require foo) + 3;
1315 () = (CORE::dump 1) + 3;
1326 # [perl #97476] not() *does* follow the llafr
1327 $_ = ($a xor not +($1 || 2) ** 2);
1329 # Precedence conundrums with argument-less function calls
1337 # loopexes have assignment prec
1338 () = (CORE::dump a) | 'b';
1339 () = (goto a) | 'b';
1340 () = (last a) | 'b';
1341 () = (next a) | 'b';
1342 () = (redo a) | 'b';
1344 # [perl #63558] open local(*FH)
1346 pipe local *FH, local *FH;
1348 # [perl #91416] open "string"
1361 () = 'open'->[0]; #aelemfast
1366 () = 'open'->[$_]; #aelem
1371 () = 'open'->{0}; #helem
1392 () = 'a::]b'->{'0'};
1394 # [perl #74740] -(f()) vs -f()
1400 #[perl #30504] foreach-my postfix/prefix difference
1401 $_ = 'foo' foreach my ($foo1, $bar1, $baz1);
1402 foreach (my ($foo2, $bar2, $baz2)) { $_ = 'foo' }
1403 foreach my $i (my ($foo3, $bar3, $baz3)) { $i = 'foo' }
1405 $_ = 'foo' foreach (my($foo1, $bar1, $baz1));
1406 foreach $_ (my($foo2, $bar2, $baz2)) {
1409 foreach my $i (my($foo3, $bar3, $baz3)) {
1413 #[perl #108224] foreach with continue block
1414 foreach (1 .. 3) { print } continue { print "\n" }
1415 foreach (1 .. 3) { } continue { }
1416 foreach my $i (1 .. 3) { print $i } continue { print "\n" }
1417 foreach my $i (1 .. 3) { } continue { }
1419 foreach $_ (1 .. 3) {
1425 foreach $_ (1 .. 3) {
1431 foreach my $i (1 .. 3) {
1437 foreach my $i (1 .. 3) {
1458 # 'my' works with padrange op
1465 ($m3, $m4) = (1, 2);
1467 my($m5, $m6) = (1, 2);
1468 my($m7, undef, $m8) = (1, 2, 3);
1469 @z = ($m7, undef, $m8);
1470 ($m7, undef, $m8) = (1, 2, 3);
1472 # 'our/local' works with padrange op
1483 ($o3, $o4) = (1, 2);
1484 local($o3, $o4) = (1, 2);
1486 @z = local($o3, $o4);
1487 our($o5, $o6) = (1, 2);
1488 our($o7, undef, $o8) = (1, 2, 3);
1489 @z = ($o7, undef, $o8);
1490 @z = local($o7, undef, $o8);
1491 ($o7, undef, $o8) = (1, 2, 3);
1492 local($o7, undef, $o8) = (1, 2, 3);
1494 # 'state' works with padrange op
1496 use feature 'state';
1503 ($s3, $s4) = (1, 2);
1505 # assignment of state lists isn't implemented yet
1506 #state($s5, $s6) = (1, 2);
1507 #state($s7, undef, $s8) = (1, 2, 3);
1508 #@z = ($s7, undef, $s8);
1509 ($s7, undef, $s8) = (1, 2, 3);
1511 # anon lists with padrange
1516 # slices with padrange
1522 # binops with padrange
1536 my($a, $b, $c, $d, @e);
1541 @e = ($a, $b, $c) x $d;
1545 my($a, $b, $c) = @_;
1547 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1548 # TODO unimplemented in B::Deparse; RT #116553
1549 # lexical subroutine
1550 use feature 'lexical_subs';
1551 no warnings "experimental::lexical_subs";
1555 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1556 # TODO unimplemented in B::Deparse; RT #116553
1557 # lexical "state" subroutine
1558 use feature 'state', 'lexical_subs';
1559 no warnings 'experimental::lexical_subs';
1563 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1564 # TODO unimplemented in B::Deparse; RT #116553
1565 # lexical subroutine scoping
1566 # CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
1582 # Elements of %# should not be confused with $#{ array }
1585 # [perl #121050] Prototypes with whitespace
1586 sub _121050(\$ \$) { }
1588 sub _121050empty( ) {}
1589 () = _121050empty() + 1;
1592 () = _121050empty + 1;
1594 # ensure aelemfast works in the range -128..127 and that there's no
1598 $x = $a[-256] + $a[-255] + $a[-129] + $a[-128] + $a[-127] + $a[-1] + $a[0];
1599 $x = $a[1] + $a[126] + $a[127] + $a[128] + $a[255] + $a[256];
1601 $x = $b[-256] + $b[-255] + $b[-129] + $b[-128] + $b[-127] + $b[-1] + $b[0];
1602 $x = $b[1] + $b[126] + $b[127] + $b[128] + $b[255] + $b[256];
1604 # 'm' must be preserved in m??
1607 # \(@array) and \(..., (@array), ...)
1608 my(@array, %hash, @a, @b, %c, %d);
1611 () = \(@a, (@b), (%c), %d);
1612 () = \(@Foo::array);
1614 () = \(@Foo::a, (@Foo::b), (%Foo::c), %Foo::d);
1616 # subs synonymous with keywords
1620 use feature 'state';
1624 # CONTEXT use feature "state", 'lvalue_refs', 'lexical_subs'; no warnings 'experimental';
1636 \($x, my $a) = @{[\$x, \$x]};
1637 (\$x, \my $b) = @{[\$x, \$x]};
1649 \local($a[1]) = foo();
1652 \local @a[0,1] = (\$a)x2;
1659 \local($h{b}) = \$x;
1660 \@h{'a','b'} = foo();
1662 \local @h{'a','b'} = (\$x)x2;
1698 (\$_, $_) = \(1, 2);
1699 $_ == 3 ? \$_ : $_ = \3;
1700 $_ == 3 ? \$_ : \$x = \3;
1701 \($_ == 3 ? $_ : $x) = \3;
1702 for \my $topic (\$1, \$2) {
1705 for \state $topic (\$1, \$2) {
1708 for \our $topic (\$1, \$2) {
1711 for \$_ (\$1, \$2) {
1714 for \my @a ([1,2], [3,4]) {
1717 for \state @a ([1,2], [3,4]) {
1720 for \our @a ([1,2], [3,4]) {
1723 for \@_ ([1,2], [3,4]) {
1726 for \my %a ({5,6}, {7,8}) {
1729 for \our %a ({5,6}, {7,8}) {
1732 for \state %a ({5,6}, {7,8}) {
1735 for \%_ ({5,6}, {7,8}) {
1740 for \&a (sub { 9; }, sub { 10; }) {
1744 for \&a (sub { 9; }, sub { 10; }) {
1759 (\$x, \my $a) = @{[\$x, \$x];};
1760 (\$x, \my $b) = @{[\$x, \$x];};
1772 (\local $a[1]) = foo();
1773 (\@a[0, 1]) = foo();
1774 (\@a[2, 3]) = foo();
1775 (\local @a[0, 1]) = (\$a) x 2;
1781 \local $h{'a'} = \$x;
1782 (\local $h{'b'}) = \$x;
1783 (\@h{'a', 'b'}) = foo();
1784 (\@h{2, 3}) = foo();
1785 (\local @h{'a', 'b'}) = (\$x) x 2;
1811 (\our %zz) = {1, 2};
1821 (\$_, $_) = \(1, 2);
1822 $_ == 3 ? \$_ : $_ = \3;
1823 $_ == 3 ? \$_ : \$x = \3;
1824 ($_ == 3 ? \$_ : \$x) = \3;
1825 foreach \my $topic (\$1, \$2) {
1828 foreach \state $topic (\$1, \$2) {
1831 foreach \our $topic (\$1, \$2) {
1834 foreach \$_ (\$1, \$2) {
1837 foreach \my @a ([1, 2], [3, 4]) {
1840 foreach \state @a ([1, 2], [3, 4]) {
1843 foreach \our @a ([1, 2], [3, 4]) {
1846 foreach \@_ ([1, 2], [3, 4]) {
1849 foreach \my %a ({5, 6}, {7, 8}) {
1852 foreach \our %a ({5, 6}, {7, 8}) {
1855 foreach \state %a ({5, 6}, {7, 8}) {
1858 foreach \%_ ({5, 6}, {7, 8}) {
1863 foreach \&a (sub { 9; } , sub { 10; } ) {
1867 foreach \&a (sub { 9; } , sub { 10; } ) {
1876 $_ = join('???', pos $_);