xref: /openbsd-src/gnu/usr.bin/perl/t/lib/feature/indirect (revision f2a19305cfc49ea4d1a5feb55cd6c283c6f1e031)
1Test no feature indirect.
2
3__END__
4# NAME feature indirect
5use feature 'say';
6package Foo {
7  sub new { bless {}, shift }
8}
9# various indirect object look-alikes
10my $foox = "foox";
11print STDERR "Hello\n";
12printf STDERR "Test%s\n", "x";
13say STDERR "Hello";
14exec $foox "foo", "bar";
15system $foox "foo", "bar";
16my $x = new Foo;
17no feature "indirect";
18print STDERR "Hello\n";
19printf STDERR "Test%s\n", "x";
20say STDERR "Hello";
21exec $foox "foo", "bar";
22system $foox "foo", "bar";
23my $y = new Foo;
24EXPECT
25OPTIONS fatal
26Bareword found where operator expected (Do you need to predeclare "new"?) at - line 19, near "new Foo"
27syntax error at - line 19, near "new Foo"
28Execution of - aborted due to compilation errors.
29########
30# NAME METHOD BLOCK
31use feature 'say';
32package Foo {
33  sub new { bless {}, shift }
34}
35# make sure this works (either way)
36my $st = STDOUT;
37print { $st } "Foo\n";
38say { $st } "Foo";
39
40# make sure this continues to work by default
41my $class = "Foo";
42my $x = new { $class };
43
44use feature "indirect";
45
46# and with it explicitly enabled
47
48print { $st } "Foo\n";
49say { $st } "Foo";
50
51my $y = new { $class };
52
53
54no feature "indirect";
55
56# and only the indirect now fails
57print { $st } "Foo\n";
58say { $st } "Foo";
59my $z = new { $class };
60
61EXPECT
62OPTIONS fatal
63syntax error at - line 29, near "new { "
64Execution of - aborted due to compilation errors.
65########
66# NAME METHOD SCALAR
67use feature 'say';
68package Foo {
69  sub new { bless {}, shift }
70}
71# make sure this works (either way)
72my $st = STDOUT;
73print $st "Foo\n";
74say $st "Foo";
75
76# make sure this continues to work by default
77my $class = "Foo";
78my $x = new $class;
79
80use feature "indirect";
81
82# and with it explicitly enabled
83
84print $st "Foo\n";
85say $st "Foo";
86
87my $y = new $class;
88
89
90no feature "indirect";
91
92# and only the indirect now fails
93print $st "Foo\n";
94say $st "Foo";
95my $z = new $class;
96
97EXPECT
98OPTIONS fatal
99Scalar found where operator expected (Do you need to predeclare "new"?) at - line 29, near "new $class"
100syntax error at - line 29, near "new $class"
101Execution of - aborted due to compilation errors.
102########
103# NAME FUNCMETH SCALAR
104use feature 'say';
105package Foo {
106  sub new { bless {}, shift }
107}
108# make sure this works (either way)
109my $st = STDOUT;
110print $st ("Foo\n");
111say $st ("Foo");
112
113# make sure this continues to work by default
114my $class = "Foo";
115my $x = new $class ();
116
117use feature "indirect";
118
119# and with it explicitly enabled
120
121print $st ("Foo\n");
122say $st ("Foo");
123
124my $y = new $class ();
125
126
127no feature "indirect";
128
129# and only the indirect now fails
130print $st ("Foo\n");
131say $st ("Foo");
132my $z = new $class ();
133
134EXPECT
135OPTIONS fatal
136Scalar found where operator expected (Do you need to predeclare "new"?) at - line 29, near "new $class"
137syntax error at - line 29, near "new $class "
138Execution of - aborted due to compilation errors.
139