summaryrefslogtreecommitdiff
path: root/lib/Switch.pm
diff options
context:
space:
mode:
authorRonald J. Kimball <rjk@linguist.dartmouth.edu>2003-05-19 13:53:25 -0400
committerJarkko Hietaniemi <jhi@iki.fi>2003-05-21 19:18:21 +0000
commit52d8c818b517f230f445c3b2cd5dd7fb20ae5fb0 (patch)
treee30554c458d228d4f638c63bd2a6ca33b76a92af /lib/Switch.pm
parent7e8202f19ce9f11d44dfd154b4b8f23de0b348c8 (diff)
downloadperl-52d8c818b517f230f445c3b2cd5dd7fb20ae5fb0.tar.gz
Re: [perl #22231] <$foo> is parsed as glob(' ' . $foo) if Switch.pm is used
Message-ID: <20030519215325.GE1629175@linguist.thayer.dartmouth.edu> (the bug id corrected to be #22231, not #22238) p4raw-id: //depot/perl@19583
Diffstat (limited to 'lib/Switch.pm')
-rw-r--r--lib/Switch.pm20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/Switch.pm b/lib/Switch.pm
index 31590b3dcc..b6645a636c 100644
--- a/lib/Switch.pm
+++ b/lib/Switch.pm
@@ -101,7 +101,8 @@ sub filter_blocks
my @pos = Text::Balanced::_match_quotelike(\$source,qr/\s*/,1,0);
if (defined $pos[0])
{
- $text .= " " . substr($source,$pos[2],$pos[18]-$pos[2]);
+ $text .= " " if $pos[0] < $pos[2];
+ $text .= substr($source,$pos[2],$pos[18]-$pos[2]);
next component;
}
if ($source =~ m/\G\s*($pod_or_DATA)/gc) {
@@ -110,7 +111,8 @@ sub filter_blocks
@pos = Text::Balanced::_match_variable(\$source,qr/\s*/);
if (defined $pos[0])
{
- $text .= " " . substr($source,$pos[0],$pos[4]-$pos[0]);
+ $text .= " " if $pos[0] < $pos[2];
+ $text .= substr($source,$pos[0],$pos[4]-$pos[0]);
next component;
}
@@ -149,8 +151,9 @@ sub filter_blocks
$text .= $1."if (Switch::case";
if (@pos = Text::Balanced::_match_codeblock(\$source,qr/\s*/,qr/\{/,qr/\}/,qr/\{/,qr/\}/,undef)) {
my $code = substr($source,$pos[0],$pos[4]-$pos[0]);
- $text .= " sub" if is_block $code;
- $text .= " " . filter_blocks($code,line(substr($source,0,$pos[0]),$line)) . ")";
+ $text .= " " if $pos[0] < $pos[2];
+ $text .= "sub " if is_block $code;
+ $text .= filter_blocks($code,line(substr($source,0,$pos[0]),$line)) . ")";
}
elsif (@pos = Text::Balanced::_match_codeblock(\$source,qr/\s*/,qr/[[(]/,qr/[])]/,qr/[[({]/,qr/[])}]/,undef)) {
my $code = filter_blocks(substr($source,$pos[0],$pos[4]-$pos[0]),line(substr($source,0,$pos[0]),$line));
@@ -158,13 +161,15 @@ sub filter_blocks
$code =~ s {^\s*[(]\s*m\b} { ( qr} ||
$code =~ s {^\s*[(]\s*/} { ( qr/} ||
$code =~ s {^\s*[(]\s*qw} { ( \\qw};
- $text .= " $code)";
+ $text .= " " if $pos[0] < $pos[2];
+ $text .= "$code)";
}
elsif ($Perl6 && do{@pos = Text::Balanced::_match_variable(\$source,qr/\s*/)}) {
my $code = filter_blocks(substr($source,$pos[0],$pos[4]-$pos[0]),line(substr($source,0,$pos[0]),$line));
$code =~ s {^\s*%} { \%} ||
$code =~ s {^\s*@} { \@};
- $text .= " $code)";
+ $text .= " " if $pos[0] < $pos[2];
+ $text .= "$code)";
}
elsif ( @pos = Text::Balanced::_match_quotelike(\$source,qr/\s*/,1,0)) {
my $code = substr($source,$pos[2],$pos[18]-$pos[2]);
@@ -172,7 +177,8 @@ sub filter_blocks
$code =~ s {^\s*m} { qr} ||
$code =~ s {^\s*/} { qr/} ||
$code =~ s {^\s*qw} { \\qw};
- $text .= " $code)";
+ $text .= " " if $pos[0] < $pos[2];
+ $text .= "$code)";
}
elsif ($Perl5 && $source =~ m/\G\s*(([^\$\@{])[^\$\@{]*)(?=\s*{)/gc
|| $Perl6 && $source =~ m/\G\s*([^;{]*)()/gc) {