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 = '\(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 my ($code, $expected) = split /^-{4,}$/m, $_, 2;
66 my @expected = expect($expected);
68 skip "$_: $skip" => 3 * (4 + @expected) if eval $skip;
71 try "return; $prefix; use indirect; $code";
72 is $@, '', "use indirect: $code";
73 is @warns, 0, 'correct number of reports';
75 try "return; $prefix; no indirect; $code";
76 is $@, '', "no indirect: $code";
77 is @warns, @expected, 'correct number of reports';
78 for my $i (0 .. $#expected) {
79 like $warns[$i], $expected[$i], "report $i is correct";
86 my ($code, $expected) = split /^-{4,}$/m, $_, 2;
87 my @expected = expect($expected);
89 try "return; $prefix; use indirect; $code";
90 is $@, '', "use indirect, defined: $code";
91 is @warns, 0, 'correct number of reports';
93 try "return; $prefix; no indirect; $code";
94 is $@, '', "no indirect, defined: $code";
95 is @warns, @expected, 'correct number of reports';
96 for my $i (0 .. $#expected) {
97 like $warns[$i], $expected[$i], "report $i is correct";
103 $code =~ s/\$/\$ \n\t /g;
105 try "return; $prefix; use indirect; $code";
106 is $@, '', "use indirect, spaces: $code";
107 is @warns, 0, 'correct number of reports';
109 try "return; $prefix; no indirect; $code";
110 is $@, '', "no indirect, spaces: $code";
111 is @warns, @expected, 'correct number of reports';
112 for my $i (0 .. $#expected) {
113 like $warns[$i], $expected[$i], "report $i is correct";
123 local $SIG{__WARN__} = sub { push @warns, @_ };
124 eval "return; no indirect 'hlagh'; \$obj = new Hlagh1;";
126 is $@, '', 'no indirect "hlagh" didn\'t croak';
127 is @warns, 1, 'only one warning';
128 my $warn = shift @warns;
129 like $warn, qr/^Indirect call of method "new" on object "Hlagh1"/,
130 'no indirect "hlagh" enables the pragma';
131 is_deeply \@warns, [ ], 'nothing more';
140 $obj = new Hlagh if 0;
152 $obj = new Hlagh(1, 2);
160 $obj = new Hlagh ( ) ;
164 $obj = new Hlagh ( 1 ) ;
168 $obj = new Hlagh ( 1 , 2 ) ;
207 $obj = new $x('foo');
211 $obj = new $x qq{foo}, 1;
215 $obj = new $x qr{foo\s+bar}, 1 .. 1;
219 $obj = new $x(qw/bar baz/);
233 $obj = new $_ qr/foo/ ;
237 $obj = new $_ qq(bar baz);
280 #### $] < 5.010 # use feature 'state'; state $z
284 #### $] < 5.010 # use feature 'state'; state $z
288 #### $] < 5.010 # use feature 'state'; state $z
295 meh $sploosh::sploosh;
297 [ 'meh', '$sploosh::sploosh' ]
303 [ 'meh', '$sploosh' ]
308 [ 'meh', '$main::bloop' ]
323 meh $sploosh::sploosh;
325 [ 'meh', '$sploosh::sploosh' ]
335 new Hlagh->wut, "Wut";
339 $obj = HlaghHlagh Hlagh;
341 [ 'HlaghHlagh', 'Hlagh' ]
343 $obj = HlaghHlagh Hlagh; # HlaghHlagh Hlagh
345 [ 'HlaghHlagh', 'Hlagh' ]
351 $obj = new newnew; # new newnew
359 $obj = feh feh; # feh feh
365 [ 'meh', '$x' ], [ 'new', 'Hlagh' ]
388 meh { new Hlagh; 1; };
390 [ 'new', 'Hlagh' ], [ 'meh', '{' ]
394 [ 'feh', '$x' ], [ 'meh', '{' ]
396 meh { feh $x; use indirect; new Hlagh; 1; };
398 [ 'feh', '$x' ], [ 'meh', '{' ]
402 [ 'feh', '$y' ], [ 'meh', '{' ]
404 meh { feh $x; 1; } new Hlagh, feh $y;
406 [ 'feh', '$x' ], [ 'new', 'Hlagh' ], [ 'feh', '$y' ], [ 'meh', '{' ]