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) {