while (readline $src) {
chomp;
if ($_ =~ (ref $search ? $search : qr/^\Q$search\E$/)) {
- if (defined $replace and $_ eq $replace) {
+ if (ref $replace eq 'ARRAY') {
+ if (@$replace and $_ eq $replace->[0]) {
+ shift @$replace;
+ }
+ else {
+ $changes++;
+ next;
+ }
+ }
+ elsif (defined $replace and $_ eq $replace) {
undef $replace;
}
else {
}
close $src;
if (defined $replace) {
- $changes++;
- print {$dest} $replace, $/;
+ for (ref $replace eq 'ARRAY' ? @$replace : $replace) {
+ $changes++;
+ print {$dest} $_, $/;
+ }
}
close $dest;
use strict;
use warnings;
-use Test::More tests => 13;
+use Test::More tests => 16;
use Test::NoWarnings;
use autodie;
testfileset('replace all', $BASICBODY, ['', qr/^re/], 3, "noremove$/.$/$/");
testfileset('keep first', "foo$/bar$/foo$/", ['foo'], 1, "foo$/bar$/");
-is(remove_tree($target), 11, 'no unexpected files');
+testfileset('add new array', ".$/", [['foo','.'], ''], 2, ".$/foo$/.$/");
+testfileset('replace by array', "$/foo$/.$/", [['foo',''], ''], 3, "foo$/.$/foo$/$/");
+testfileset('partial add', "foo$/$/", [['foo','.'], 'foo'], 1, "foo$/$/.$/");
+
+is(remove_tree($target), 14, 'no unexpected files');