my ($tests, $reports);
BEGIN {
- $tests = 60;
- $reports = 68;
+ $tests = 82;
+ $reports = 94;
}
-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);
my ($meth, $obj, $file, $line) = @$_;
$meth = quotemeta $meth;
$obj = ($obj =~ /^\s*\{/) ? "a block" : "object \"\Q$obj\E\"";
- $file = '\(eval \d+\)' unless defined $file;
- $line = '\d+' unless defined $line;
+ $file = '\((?:re_)?eval \d+\)' unless defined $file;
+ $line = '\d+' unless defined $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;
}
}
}
}
+SKIP:
{
+ skip 'No space tests on perl 5.11' => 4 + @expected
+ if "$]" >= 5.011 and "$]" < 5.012;
my $code = $code;
$code =~ s/\$/\$ \n\t /g;
}
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' ]
----
[ 'new', '$x' ]
####
-$obj = new $x(qw/bar baz/);
+$obj = new $x(qw<bar baz>);
----
[ 'new', '$x' ]
####
meh $y, 1, 2;
----
[ 'meh', '$y' ]
-#### $] < 5.010 # use feature 'state'; state $z
+#### "$]" < 5.010 # use feature 'state'; state $z
meh $z;
----
[ 'meh', '$z' ]
-#### $] < 5.010 # use feature 'state'; state $z
+#### "$]" < 5.010 # use feature 'state'; state $z
meh $z 1, 2;
----
[ 'meh', '$z' ]
-#### $] < 5.010 # use feature 'state'; state $z
+#### "$]" < 5.010 # use feature 'state'; state $z
meh $z, 1, 2;
----
[ 'meh', '$z' ]
----
[ 'meh', '$x' ]
####
+$obj = "apple ${\(new Hlagh)} pear"
+----
+[ 'new', 'Hlagh' ]
+####
+$obj = "apple @{[new Hlagh]} pear"
+----
+[ 'new', 'Hlagh' ]
+####
+$obj = "apple ${\(new $x)} pear"
+----
+[ 'new', '$x' ]
+####
+$obj = "apple @{[new $x]} pear"
+----
+[ 'new', '$x' ]
+####
+$obj = "apple ${\(new $y)} pear"
+----
+[ 'new', '$y' ]
+####
+$obj = "apple @{[new $y]} pear"
+----
+[ 'new', '$y' ]
+####
+$obj = "apple ${\(new $x qq|${\(stuff $y)}|)} pear"
+----
+[ 'stuff', '$y' ], [ 'new', '$x' ]
+####
+$obj = "apple @{[new $x qq|@{[stuff $y]}|]} pear"
+----
+[ 'stuff', '$y' ], [ 'new', '$x' ]
+#### # local $_ = "foo";
+s/foo/return; new Hlagh/e;
+----
+[ 'new', 'Hlagh' ]
+#### # local $_ = "bar";
+s/foo/return; new Hlagh/e;
+----
+[ 'new', 'Hlagh' ]
+#### # local $_ = "foo";
+s/foo/return; new $x/e;
+----
+[ 'new', '$x' ]
+#### # local $_ = "bar";
+s/foo/return; new $x/e;
+----
+[ 'new', '$x' ]
+#### # local $_ = "foo";
+s/foo/return; new $y/e;
+----
+[ 'new', '$y' ]
+#### # local $_ = "bar";
+s/foo/return; new $y/e;
+----
+[ 'new', '$y' ]
+####
+"foo" =~ /(?{new Hlagh})/;
+----
+[ 'new', 'Hlagh' ]
+####
+"foo" =~ /(?{new $x})/;
+----
+[ 'new', '$x' ]
+####
+"foo" =~ /(?{new $y})/;
+----
+[ 'new', '$y' ]
+####
+"foo" =~ /(??{new Hlagh})/;
+----
+[ 'new', 'Hlagh' ]
+####
+"foo" =~ /(??{new $x})/;
+----
+[ 'new', '$x' ]
+####
+"foo" =~ /(??{new $y})/;
+----
+[ 'new', '$y' ]
+####
meh { };
----
[ 'meh', '{' ]
meh { feh $x; 1; } new Hlagh, feh $y;
----
[ 'feh', '$x' ], [ 'new', 'Hlagh' ], [ 'feh', '$y' ], [ 'meh', '{' ]
+####
+$obj = "apple @{[new { feh $x; meh $y; 1 }]} pear"
+----
+[ 'feh', '$x' ], [ 'meh', '$y' ], [ 'new', '{' ]