my ($tests, $reports);
BEGIN {
- $tests = 52;
- $reports = 53;
+ $tests = 61;
+ $reports = 69;
}
-use Test::More tests => 3 * (4 * $tests + $reports) + 2;
+use Test::More tests => 3 * (4 * $tests + $reports) + 4;
+
+BEGIN { delete $ENV{PERL_INDIRECT_PM_DISABLE} }
my ($obj, $x);
our ($y, $bloop);
map {
my ($meth, $obj, $file, $line) = @$_;
- $_ = quotemeta for $meth, $obj;
+ $meth = quotemeta $meth;
+ $obj = ($obj =~ /^\s*\{/) ? "a block" : "object \"\Q$obj\E\"";
$file = '\(eval \d+\)' unless defined $file;
$line = '\d+' unless defined $line;
- qr/^Indirect call of method "$meth" on object "$obj" at $file line $line/
+ qr/^Indirect call of method "$meth" on $obj at $file line $line/
} eval $expected;
}
@warns = ();
{
- local $SIG{__WARN__} = sub { push @warns, join(' ', @_) };
+ local $SIG{__WARN__} = sub { push @warns, @_ };
eval $code;
}
}
}
eval {
- my $warn;
- local $SIG{__WARN__} = sub { $warn = join ' ', @_ };
- eval "die qq{ok\n}; no indirect 'hlagh'; \$obj = new Hlagh1;";
- is($@, "ok\n", 'no indirect "hlagh" didn\'t croak');
- like($warn, qr/^Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"Hlagh1"/, 'no indirect "hlagh" enables the pragma');
+ my @warns;
+ {
+ local $SIG{__WARN__} = sub { push @warns, @_ };
+ eval "return; no indirect 'hlagh'; \$obj = new Hlagh1;";
+ }
+ is $@, '', 'no indirect "hlagh" didn\'t croak';
+ is @warns, 1, 'only one warning';
+ my $warn = shift @warns;
+ like $warn, qr/^Indirect call of method "new" on object "Hlagh1"/,
+ 'no indirect "hlagh" enables the pragma';
+ is_deeply \@warns, [ ], 'nothing more';
}
__DATA__
----
[ 'new', 'Hlagh' ]
####
+$obj = new Hlagh if 0;
+----
+[ 'new', 'Hlagh' ]
+####
$obj = new Hlagh();
----
[ 'new', 'Hlagh' ]
Hlagh->new(meh $x)
----
[ 'meh', '$x' ]
+####
+meh { };
+----
+[ 'meh', '{' ]
+####
+meh {
+ 1;
+};
+----
+[ 'meh', '{' ]
+####
+meh {
+ 1;
+ 1;
+};
+----
+[ 'meh', '{' ]
+####
+meh { new Hlagh; 1; };
+----
+[ 'new', 'Hlagh' ], [ 'meh', '{' ]
+####
+meh { feh $x; 1; };
+----
+[ 'feh', '$x' ], [ 'meh', '{' ]
+####
+meh { feh $x; use indirect; new Hlagh; 1; };
+----
+[ 'feh', '$x' ], [ 'meh', '{' ]
+####
+meh { feh $y; 1; };
+----
+[ 'feh', '$y' ], [ 'meh', '{' ]
+####
+meh { feh $x; 1; } new Hlagh, feh $y;
+----
+[ 'feh', '$x' ], [ 'new', 'Hlagh' ], [ 'feh', '$y' ], [ 'meh', '{' ]