12 my ($tests, $reports);
18 use Test::More tests => 3 * (4 * $tests + $reports) + 4;
20 BEGIN { delete $ENV{PERL_INDIRECT_PM_DISABLE} }
31 my ($meth, $obj, $file, $line) = @$_;
32 $meth = quotemeta $meth;
33 $obj = ($obj =~ /^\s*\{/) ? "a block" : "object \"\Q$obj\E\"";
34 $file = '\((?:re_)?eval \d+\)' unless defined $file;
35 $line = '\d+' unless defined $line;
36 qr/^Indirect call of method "$meth" on $obj at $file line $line/
47 local $SIG{__WARN__} = sub { push @warns, @_ };
58 my ($skip, $prefix) = split /#+/, $1;
59 $skip = 0 unless defined $skip;
60 $prefix = '' unless defined $prefix;
65 if (do { local $@; eval $skip }) {
66 my ($code, $expected) = split /^-{4,}$/m, $_, 2;
67 my @expected = expect($expected);
68 skip "$_: $skip" => 3 * (4 + @expected);
74 my ($code, $expected) = split /^-{4,}$/m, $_, 2;
75 my @expected = expect($expected);
77 try "return; $prefix; use indirect; $code";
78 is $@, '', "use indirect: $code";
79 is @warns, 0, 'correct number of reports';
81 try "return; $prefix; no indirect; $code";
82 is $@, '', "no indirect: $code";
83 is @warns, @expected, 'correct number of reports';
84 for my $i (0 .. $#expected) {
85 like $warns[$i], $expected[$i], "report $i is correct";
92 my ($code, $expected) = split /^-{4,}$/m, $_, 2;
93 my @expected = expect($expected);
95 try "return; $prefix; use indirect; $code";
96 is $@, '', "use indirect, defined: $code";
97 is @warns, 0, 'correct number of reports';
99 try "return; $prefix; no indirect; $code";
100 is $@, '', "no indirect, defined: $code";
101 is @warns, @expected, 'correct number of reports';
102 for my $i (0 .. $#expected) {
103 like $warns[$i], $expected[$i], "report $i is correct";
111 my ($code, $expected) = split /^-{4,}$/m, $_, 2;
112 my @expected = expect($expected);
113 skip 'No space tests on perl 5.11' => 4 + @expected
114 if "$]" >= 5.011 and "$]" < 5.012;
115 $code =~ s/\$/\$ \n\t /g;
117 try "return; $prefix; use indirect; $code";
118 is $@, '', "use indirect, spaces: $code";
119 is @warns, 0, 'correct number of reports';
121 try "return; $prefix; no indirect; $code";
122 is $@, '', "no indirect, spaces: $code";
123 is @warns, @expected, 'correct number of reports';
124 for my $i (0 .. $#expected) {
125 like $warns[$i], $expected[$i], "report $i is correct";
135 local $SIG{__WARN__} = sub { push @warns, @_ };
136 eval "return; no indirect 'whatever'; \$obj = new Pkg1;";
138 is $@, '', 'no indirect "whatever" didn\'t croak';
139 is @warns, 1, 'only one warning';
140 my $warn = shift @warns;
141 like $warn, qr/^Indirect call of method "new" on object "Pkg1"/,
142 'no indirect "whatever" enables the pragma';
143 is_deeply \@warns, [ ], 'nothing more';
164 $obj = new Pkg(1, 2);
176 $obj = new Pkg ( 1 ) ;
180 $obj = new Pkg ( 1 , 2 ) ;
219 $obj = new $x('foo');
223 $obj = new $x qq{foo}, 1;
227 $obj = new $x qr{foo\s+bar}, 1 .. 1;
231 $obj = new $x(qw<bar baz>);
245 $obj = new $_ qr/foo/ ;
249 $obj = new $_ qq(bar baz);
292 #### "$]" < 5.010 # use feature 'state'; state $z
296 #### "$]" < 5.010 # use feature 'state'; state $z
300 #### "$]" < 5.010 # use feature 'state'; state $z
307 meh $sploosh::sploosh;
309 [ 'meh', '$sploosh::sploosh' ]
315 [ 'meh', '$sploosh' ]
320 [ 'meh', '$main::bloop' ]
335 meh $sploosh::sploosh;
337 [ 'meh', '$sploosh::sploosh' ]
355 $obj = PkgPkg Pkg; # PkgPkg Pkg
363 $obj = new newnew; # new newnew
371 $obj = feh feh; # feh feh
377 [ 'meh', '$x' ], [ 'new', 'Pkg' ]
383 $obj = "apple ${\(new Pkg)} pear"
387 $obj = "apple @{[new Pkg]} pear"
391 $obj = "apple ${\(new $x)} pear"
395 $obj = "apple @{[new $x]} pear"
399 $obj = "apple ${\(new $y)} pear"
403 $obj = "apple @{[new $y]} pear"
407 $obj = "apple ${\(new $x qq|${\(stuff $y)}|)} pear"
409 [ 'stuff', '$y' ], [ 'new', '$x' ]
411 $obj = "apple @{[new $x qq|@{[stuff $y]}|]} pear"
413 [ 'stuff', '$y' ], [ 'new', '$x' ]
414 #### # local $_ = "foo";
415 s/foo/return; new Pkg/e;
418 #### # local $_ = "bar";
419 s/foo/return; new Pkg/e;
422 #### # local $_ = "foo";
423 s/foo/return; new $x/e;
426 #### # local $_ = "bar";
427 s/foo/return; new $x/e;
430 #### # local $_ = "foo";
431 s/foo/return; new $y/e;
434 #### # local $_ = "bar";
435 s/foo/return; new $y/e;
439 "foo" =~ /(?{new Pkg})/;
443 "foo" =~ /(?{new $x})/;
447 "foo" =~ /(?{new $y})/;
451 "foo" =~ /(??{new Pkg})/;
455 "foo" =~ /(??{new $x})/;
459 "foo" =~ /(??{new $y})/;
482 [ 'new', 'Pkg' ], [ 'meh', '{' ]
486 [ 'feh', '$x' ], [ 'meh', '{' ]
488 meh { feh $x; use indirect; new Pkg; 1; };
490 [ 'feh', '$x' ], [ 'meh', '{' ]
494 [ 'feh', '$y' ], [ 'meh', '{' ]
496 meh { feh $x; 1; } new Pkg, feh $y;
498 [ 'feh', '$x' ], [ 'new', 'Pkg' ], [ 'feh', '$y' ], [ 'meh', '{' ]
500 $obj = "apple @{[new { feh $x; meh $y; 1 }]} pear"
502 [ 'feh', '$x' ], [ 'meh', '$y' ], [ 'new', '{' ]
507 [ 'new', '__PACKAGE_' ]
509 package __PACKAGE___;
512 [ 'new', '__PACKAGE___' ]
515 new { __PACKAGE__ }; # Hurp
529 package __PACKAGE___;