From 0cd7fc4e27c3253340100379bdc10369bc994513 Mon Sep 17 00:00:00 2001 From: Diab Jerius Date: Thu, 28 May 2020 16:39:13 -0400 Subject: [PATCH] don't treat array- or hash- lookups as postfix dereferencers --- lib/Babble/Plugin/PostfixDeref.pm | 9 ++++++--- t/plugin-postfixderef.t | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Babble/Plugin/PostfixDeref.pm b/lib/Babble/Plugin/PostfixDeref.pm index 65240ee..bbcc3d5 100644 --- a/lib/Babble/Plugin/PostfixDeref.pm +++ b/lib/Babble/Plugin/PostfixDeref.pm @@ -58,9 +58,12 @@ sub transform_to_plain { } } if ($postfix) { - my ($sigil, $rest) = ($postfix =~ /^\s*->\s*([\@%])(.*)$/); - $rest = '' if $rest eq '*'; - $term = '(map '.$sigil.'{$_}'.$rest.', '.$term.')'; + if ( my ($sigil, $rest) = ($postfix =~ /^\s*->\s*([\@%])(.*)$/) ) { + $rest = '' if $rest eq '*'; + $term = '(map '.$sigil.'{$_}'.$rest.', '.$term.')'; + } else { + $term .= $postfix; + } } $m->submatches->{term}->replace_text($term); $m->submatches->{postfix}->replace_text(''); diff --git a/t/plugin-postfixderef.t b/t/plugin-postfixderef.t index a01a43f..d732456 100644 --- a/t/plugin-postfixderef.t +++ b/t/plugin-postfixderef.t @@ -12,6 +12,10 @@ my @cand = ( 'my $x = (map @{$_}, ((map $$_, $foo->bar)[0])->baz);' ], [ 'my @val = $foo->@{qw(key names)};', 'my @val = (map @{$_}{qw(key names)}, $foo);' ], + [ 'my $val = $foo[0];', + 'my $val = $foo[0];' ], + [ 'my $val = $foo[$idx];', + 'my $val = $foo[$idx];' ], ); foreach my $cand (@cand) {