summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWolfgang Laun <Wolfgang.Laun@alcatel.at>2007-02-24 16:08:44 +0100
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2007-02-25 16:19:07 +0000
commit4f8a7904197dd025b819b8286e290f52246539b7 (patch)
tree9bbc7bd3754ac2ce953e1ff6063c36754de7b5f1 /lib
parent5e1aa25cd135297c28ecf395d4efa30e3d85d375 (diff)
downloadperl-4f8a7904197dd025b819b8286e290f52246539b7.tar.gz
Re: [perl #41513] (parsing?)problem when using a '/' followed by a Switch statement
From: "Wolfgang Laun" <wolfgang.laun@gmail.com> Message-ID: <17de7ee80702240608n1411ef67xcdd1ffb238742bc1@mail.gmail.com> p4raw-id: //depot/perl@30397
Diffstat (limited to 'lib')
-rw-r--r--lib/Switch.pm21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/Switch.pm b/lib/Switch.pm
index c6d3931c26..d7658bac84 100644
--- a/lib/Switch.pm
+++ b/lib/Switch.pm
@@ -4,7 +4,7 @@ use strict;
use vars qw($VERSION);
use Carp;
-$VERSION = '2.12';
+$VERSION = '2.13';
# LOAD FILTERING MODULE...
@@ -101,7 +101,18 @@ sub filter_blocks
if (defined $pos[0])
{
my $pre = substr($source,$pos[0],$pos[1]); # matched prefix
- $text .= $pre . substr($source,$pos[2],$pos[18]-$pos[2]);
+ my $iEol;
+ if( substr($source,$pos[4],$pos[5]) eq '/' && # 1st delimiter
+ substr($source,$pos[2],$pos[3]) eq '' && # no op like 'm'
+ index( substr($source,$pos[16],$pos[17]), 'x' ) == -1 && # no //x
+ ($iEol = index( $source, "\n", $pos[4] )) > 0 &&
+ $iEol < $pos[8] ){ # embedded newlines
+ # If this is a pattern, it isn't compatible with Switch. Backup past 1st '/'.
+ pos( $source ) = $pos[6];
+ $text .= $pre . substr($source,$pos[2],$pos[6]-$pos[2]);
+ } else {
+ $text .= $pre . substr($source,$pos[2],$pos[18]-$pos[2]);
+ }
next component;
}
if ($source =~ m/\G\s*($pod_or_DATA)/gc) {
@@ -849,7 +860,11 @@ Bug reports and other feedback are most welcome.
=head1 LIMITATIONS
-Due to the heuristic nature of Switch.pm's source parsing, the presence
+Due to the heuristic nature of Switch.pm's source parsing, the presence of
+regexes with embedded newlines that are specified with raw C</.../>
+delimiters and don't have a modifier C<//x> are indistinguishable from
+code chunks beginning with the division operator C</>. As a workaround
+you must use C<m/.../> or C<m?...?> for such patterns. Also, the presence
of regexes specified with raw C<?...?> delimiters may cause mysterious
errors. The workaround is to use C<m?...?> instead.