This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Filter::Simple: eliminate /\C/
authorDavid Mitchell <davem@iabyn.com>
Fri, 4 Jul 2014 11:22:23 +0000 (12:22 +0100)
committerDavid Mitchell <davem@iabyn.com>
Fri, 4 Jul 2014 11:22:23 +0000 (12:22 +0100)
Since that construct is now deprecated, don't use it. It turns out that
it's usage was almost certainly wrong anyway, and a simple /./s is better.

It was temporarily converting literals within the src text to "$;NNNN$;"
where the Ns are 4 octets that encode the index of the literal.  It was
then using /(\C{4})/ to later extract those octets. But since the octets
were originally inserted as chars anyway, they should be extracted as
chars too.

I suspect the original code could have failed on utf8 source once the
number of literals exceeded 0x80.

dist/Filter-Simple/lib/Filter/Simple.pm

index 069482a..8212919 100644 (file)
@@ -119,9 +119,8 @@ sub gen_std_filter_for {
         }
         if ($type =~ /^code/) {
             my $count = 0;
-            no warnings 'deprecated';
-            local $placeholder = qr/\Q$;\E(\C{4})\Q$;\E/;
-            my $extractor =      qr/\Q$;\E(\C{4})\Q$;\E/;
+            local $placeholder = qr/\Q$;\E(.{4})\Q$;\E/s;
+            my $extractor =      qr/\Q$;\E(.{4})\Q$;\E/s;
             $_ = join "",
                   map { ref $_ ? $;.pack('N',$count++).$; : $_ }
                       @components;