Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/Babble/Plugin/PostfixDeref.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand Down
4 changes: 4 additions & 0 deletions t/plugin-postfixderef.t
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down