fileset: replace concatenated regex by smart match
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 21 Apr 2012 02:52:16 +0000 (04:52 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 21 May 2012 15:51:50 +0000 (17:51 +0200)
Build.PL
debian/control
lib/File/Rewrite.pm
t/10-fileset.t

index e679d6b4601e254af747a1937df5ac7b466f63c0..c20af5adac64825119b84f893703ab6701665f55 100755 (executable)
--- a/Build.PL
+++ b/Build.PL
@@ -9,7 +9,7 @@ Module::Build->new(
        dynamic_config => 0,
        license     => 'perl',
        requires => {
-               'perl' => '5.006', # probably, only 5.8+ tested
+               'perl' => '5.010',
                'autodie' => 0,
        },
        build_requires => {
index 9344d7170bb2079e695f3525fe60ee2dc11abdf0..fa9349f351188fc9dfef53daf9fdb2dc488ec733 100644 (file)
@@ -1,8 +1,9 @@
 Source: libfile-rewrite-perl
 Section: perl
 Priority: optional
+Depends: perl (>= 5.10.0)
 Build-Depends: debhelper (>= 7), perl (>= 5.6) | libmodule-build-perl
-Build-Depends-Indep: perl (>= 5.6.1), libtest-nowarnings-perl
+Build-Depends-Indep: perl (>= 5.10.0), libtest-nowarnings-perl
 Maintainer: Mischa POSLAWSKY <perl@shiar.org>
 Standards-Version: 3.8.3
 Homepage: http://search.cpan.org/dist/File-Rewrite/
index 731925929d9536a09ed1e2a998850f648b7ef47e..5e26404bfbc928c33e898dcf5afcda8c60a04436 100644 (file)
@@ -2,6 +2,7 @@ package File::Rewrite;
 
 use strict;
 use warnings;
+use 5.010;  # smart match
 
 use autodie ':all';
 use Exporter 'import';
@@ -16,16 +17,11 @@ sub fileset {
 
        $replace = $search if @_ < 3;
 
-       # generate a single regex to emulate smart match
-       $search = [$search] unless ref $search eq 'ARRAY';
-       @$search = grep { defined } @$search;
-       $search = @$search ? join('|', map { ref $_ ? $_ : "^\Q$_\E\$" } @$search) : undef;
-
        open my $src,  '<', $filename;
        open my $dest, '>', $tmpname;
        while (readline $src) {
                chomp;
-               if (defined $search and $_ =~ /$search/s) {
+               if ($_ ~~ $search) {
                        if (ref $replace eq 'ARRAY') {
                                if (@$replace and $_ eq $replace->[0]) {
                                        shift @$replace;
index ff43498731a4f4868cdf640fdab8b7d7832b7c7f..9e78b11ab620642af1f78c4cf4ee287cb077f75f 100644 (file)
@@ -57,7 +57,7 @@ testfileset('add unconditionally', "$/0$/", [undef()   => '0'], 1, "$/0$/0$/");
 testfileset('add string',     "foo$/",      ['bar'],            1, "foo$/bar$/");
 testfileset('keep string',    "foo$/bar$/", ['foo'],            0, "foo$/bar$/");
 testfileset('keep first',     "foo$/FOO$/foo$/", ['foo'],       1, "foo$/FOO$/");
-testfileset('replace string', "$/0$/1$/2$/", [0 => 3],          2, "$/1$/2$/3$/");
+testfileset('replace string', "$/0$/1$/2$/", ['0' => 3],        2, "$/1$/2$/3$/");
 testfileset('keep regex',     "foo$/hi$/$/", [qr/./ => 'hi'],   1, "hi$/$/");
 
 testfileset('add new array',  ".$/",        ['' => ['foo','.']],  2, ".$/foo$/.$/");