STATIC OP *indirect_ck_method(pTHX_ OP *o) {
if (indirect_hint()) {
OP *op = cUNOPo->op_first;
- const indirect_op_info_t *oi = indirect_map_fetch(op);
- const char *s = NULL;
- line_t line;
- SV *sv;
- if (oi && (s = oi->pos)) {
- sv = sv_2mortal(newSVpvn(oi->buf, oi->len));
- line = oi->line; /* Keep the old line so that we really point to the first */
- } else {
- sv = cSVOPx_sv(op);
- if (!SvPOK(sv) || (SvTYPE(sv) < SVt_PV))
- goto done;
- sv = sv_mortalcopy(sv);
- s = indirect_find(sv, PL_oldbufptr);
- line = CopLINE(&PL_compiling);
- }
+ /* Indirect method call is only possible when the method is a bareword, so
+ * don't trip up on $obj->$meth. */
+ if (op && op->op_type == OP_CONST) {
+ const indirect_op_info_t *oi = indirect_map_fetch(op);
+ const char *s = NULL;
+ line_t line;
+ SV *sv;
+
+ if (oi && (s = oi->pos)) {
+ sv = sv_2mortal(newSVpvn(oi->buf, oi->len));
+ /* Keep the old line so that we really point to the first line of the
+ * expression. */
+ line = oi->line;
+ } else {
+ sv = cSVOPx_sv(op);
+ if (!SvPOK(sv) || (SvTYPE(sv) < SVt_PV))
+ goto done;
+ sv = sv_mortalcopy(sv);
+ s = indirect_find(sv, PL_oldbufptr);
+ line = CopLINE(&PL_compiling);
+ }
- o = CALL_FPTR(indirect_old_ck_method)(aTHX_ o);
- /* o may now be a method_named */
+ o = CALL_FPTR(indirect_old_ck_method)(aTHX_ o);
+ /* o may now be a method_named */
- indirect_map_store(o, s, sv, line);
- return o;
+ indirect_map_store(o, s, sv, line);
+ return o;
+ }
}
done:
use strict;
use warnings;
-use Test::More tests => 56 * 8;
+use Test::More tests => 80 * 8;
BEGIN { delete $ENV{PERL_INDIRECT_PM_DISABLE} }
my ($obj, $pkg, $cb, $x, @a);
-our $y;
+our ($y, $meth);
sub meh;
sub zap (&);
####
$obj = Hlagh->$cb(sub { 'foo' }, bar => $obj);
####
+$obj = Hlagh->$meth;
+####
+$obj = Hlagh
+ ->
+ $meth ( 1, 2 );
+####
$obj = $pkg->new ;
####
$obj = $pkg -> new ( );
####
$obj = $pkg->$cb(qw/foo bar baz/);
####
+$obj = $pkg->$meth;
+####
+$obj
+ =
+ $pkg
+ ->
+ $meth
+ ( 1 .. 10 );
+####
+$obj = $y->$cb;
+####
+$obj = $y
+ -> $cb (
+ 'foo', 1, 2, 'bar'
+);
+####
+$obj = $y->$meth;
+####
+$obj =
+ $y->
+ $meth (
+ qr(hello),
+);
+####
meh;
####
meh $_;
####
$x->foo($pkg->$cb)
####
+$obj = "apple ${\($x->new)} pear"
+####
+$obj = "apple @{[$x->new]} pear"
+####
+$obj = "apple ${\($y->new)} pear"
+####
+$obj = "apple @{[$y->new]} pear"
+####
+$obj = "apple ${\($x->$cb)} pear"
+####
+$obj = "apple @{[$x->$cb]} pear"
+####
+$obj = "apple ${\($y->$cb)} pear"
+####
+$obj = "apple @{[$y->$cb]} pear"
+####
+$obj = "apple ${\($x->$meth)} pear"
+####
+$obj = "apple @{[$x->$meth]} pear"
+####
+$obj = "apple ${\($y->$meth)} pear"
+####
+$obj = "apple @{[$y->$meth]} pear"
+####
$obj = "apple ${\(new Hlagh)} pear"
####
$obj = "apple @{[new Hlagh]} pear"
####
+$obj = "apple ${\(new $x)} pear"
+####
+$obj = "apple @{[new $x]} pear"
+####
+$obj = "apple ${\(new $y)} pear"
+####
+$obj = "apple @{[new $y]} pear"
+####
exec $x $x, @a;
####
exec { $a[0] } @a;