12 my ($tests, $reports);
18 use Test::More tests => 3 * (4 * $tests + $reports) + 4;
29 my ($meth, $obj, $file, $line) = @$_;
30 $meth = quotemeta $meth;
31 $obj = ($obj =~ /^\s*\{/) ? "a block" : "object \"\Q$obj\E\"";
32 $file = '\(eval \d+\)' unless defined $file;
33 $line = '\d+' unless defined $line;
34 qr/^Indirect call of method "$meth" on $obj at $file line $line/
45 local $SIG{__WARN__} = sub { push @warns, @_ };
56 my ($skip, $prefix) = split /#+/, $1;
57 $skip = 0 unless defined $skip;
58 $prefix = '' unless defined $prefix;
63 my ($code, $expected) = split /^-{4,}$/m, $_, 2;
64 my @expected = expect($expected);
66 skip "$_: $skip" => 3 * (4 + @expected) if eval $skip;
69 try "return; $prefix; use indirect; $code";
70 is $@, '', "use indirect: $code";
71 is @warns, 0, 'correct number of reports';
73 try "return; $prefix; no indirect; $code";
74 is $@, '', "no indirect: $code";
75 is @warns, @expected, 'correct number of reports';
76 for my $i (0 .. $#expected) {
77 like $warns[$i], $expected[$i], "report $i is correct";
84 my ($code, $expected) = split /^-{4,}$/m, $_, 2;
85 my @expected = expect($expected);
87 try "return; $prefix; use indirect; $code";
88 is $@, '', "use indirect, defined: $code";
89 is @warns, 0, 'correct number of reports';
91 try "return; $prefix; no indirect; $code";
92 is $@, '', "no indirect, defined: $code";
93 is @warns, @expected, 'correct number of reports';
94 for my $i (0 .. $#expected) {
95 like $warns[$i], $expected[$i], "report $i is correct";
101 $code =~ s/\$/\$ \n\t /g;
103 try "return; $prefix; use indirect; $code";
104 is $@, '', "use indirect, spaces: $code";
105 is @warns, 0, 'correct number of reports';
107 try "return; $prefix; no indirect; $code";
108 is $@, '', "no indirect, spaces: $code";
109 is @warns, @expected, 'correct number of reports';
110 for my $i (0 .. $#expected) {
111 like $warns[$i], $expected[$i], "report $i is correct";
121 local $SIG{__WARN__} = sub { push @warns, @_ };
122 eval "return; no indirect 'hlagh'; \$obj = new Hlagh1;";
124 is $@, '', 'no indirect "hlagh" didn\'t croak';
125 is @warns, 1, 'only one warning';
126 my $warn = shift @warns;
127 like $warn, qr/^Indirect call of method "new" on object "Hlagh1"/,
128 'no indirect "hlagh" enables the pragma';
129 is_deeply \@warns, [ ], 'nothing more';
138 $obj = new Hlagh if 0;
150 $obj = new Hlagh(1, 2);
158 $obj = new Hlagh ( ) ;
162 $obj = new Hlagh ( 1 ) ;
166 $obj = new Hlagh ( 1 , 2 ) ;
205 $obj = new $x('foo');
209 $obj = new $x qq{foo}, 1;
213 $obj = new $x qr{foo\s+bar}, 1 .. 1;
217 $obj = new $x(qw/bar baz/);
231 $obj = new $_ qr/foo/ ;
235 $obj = new $_ qq(bar baz);
278 #### $] < 5.010 # use feature 'state'; state $z
282 #### $] < 5.010 # use feature 'state'; state $z
286 #### $] < 5.010 # use feature 'state'; state $z
293 meh $sploosh::sploosh;
295 [ 'meh', '$sploosh::sploosh' ]
301 [ 'meh', '$sploosh' ]
306 [ 'meh', '$main::bloop' ]
321 meh $sploosh::sploosh;
323 [ 'meh', '$sploosh::sploosh' ]
333 new Hlagh->wut, "Wut";
337 $obj = HlaghHlagh Hlagh;
339 [ 'HlaghHlagh', 'Hlagh' ]
341 $obj = HlaghHlagh Hlagh; # HlaghHlagh Hlagh
343 [ 'HlaghHlagh', 'Hlagh' ]
349 $obj = new newnew; # new newnew
357 $obj = feh feh; # feh feh
363 [ 'meh', '$x' ], [ 'new', 'Hlagh' ]
386 meh { new Hlagh; 1; };
388 [ 'new', 'Hlagh' ], [ 'meh', '{' ]
392 [ 'feh', '$x' ], [ 'meh', '{' ]
394 meh { feh $x; use indirect; new Hlagh; 1; };
396 [ 'feh', '$x' ], [ 'meh', '{' ]
400 [ 'feh', '$y' ], [ 'meh', '{' ]
402 meh { feh $x; 1; } new Hlagh, feh $y;
404 [ 'feh', '$x' ], [ 'new', 'Hlagh' ], [ 'feh', '$y' ], [ 'meh', '{' ]