1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#!perl -T
use strict;
use warnings;
use Test::More tests => 3 * 4;
BEGIN { delete $ENV{PERL_INDIRECT_PM_DISABLE} }
sub expect {
my ($pkg, $line) = @_;
return qr/^Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"$pkg"\s+at\s+\(eval\s+\d+\)\s+line\s+$line/;
}
{
local $/ = "####";
while (<DATA>) {
chomp;
s/^\s+//;
my ($code, $lines) = split /#+/, $_, 2;
$lines = eval "[ sort ($lines) ]";
if ($@) {
diag "Couldn't parse line numbers: $@";
next;
}
my (@warns, @lines);
{
local $SIG{__WARN__} = sub { push @warns, "@_" };
eval "return; no indirect hook => sub { push \@lines, \$_[3] }; $code";
}
is $@, '', 'did\'t croak';
is_deeply \@warns, [ ], 'didn\'t warn';
is_deeply [ sort @lines ], $lines, 'correct line numbers';
}
}
__DATA__
my $x = new X; # 1
####
my $x = new
X; # 1
####
my $x = new X; $x = new X; # 1, 1
####
my $x = new
X new
X; # 1, 2
|