From dde1da40ee010b77f9fad43bb9a1cf23c6325f0d Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 21 Apr 2012 04:52:16 +0200 Subject: [PATCH] fileset: replace concatenated regex by smart match --- Build.PL | 2 +- debian/control | 3 ++- lib/File/Rewrite.pm | 8 ++------ t/10-fileset.t | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Build.PL b/Build.PL index e679d6b..c20af5a 100755 --- 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 => { diff --git a/debian/control b/debian/control index 9344d71..fa9349f 100644 --- a/debian/control +++ b/debian/control @@ -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 Standards-Version: 3.8.3 Homepage: http://search.cpan.org/dist/File-Rewrite/ diff --git a/lib/File/Rewrite.pm b/lib/File/Rewrite.pm index 7319259..5e26404 100644 --- a/lib/File/Rewrite.pm +++ b/lib/File/Rewrite.pm @@ -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; diff --git a/t/10-fileset.t b/t/10-fileset.t index ff43498..9e78b11 100644 --- a/t/10-fileset.t +++ b/t/10-fileset.t @@ -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$/.$/"); -- 2.30.0