| 1 |
#!/usr/local/bin/perl |
| 2 |
|
| 3 |
use File::Find; |
| 4 |
|
| 5 |
$expr = '^\s*BEGIN\s*\{\s*unshift\s*\(\s*@INC\s*,(.*)\)\s*;?\s*\}\s*$'; |
| 6 |
|
| 7 |
@todo = (); |
| 8 |
|
| 9 |
sub match |
| 10 |
{ |
| 11 |
if ($unsure) |
| 12 |
{ |
| 13 |
return 1 unless (/#!.*perl/); |
| 14 |
$unsure = 0; |
| 15 |
} |
| 16 |
if (/$expr/o) |
| 17 |
{ |
| 18 |
my $name = "$File::Find::dir/$file"; |
| 19 |
print "$name:$.: $_"; |
| 20 |
push(@todo,$name); |
| 21 |
return 1; |
| 22 |
} |
| 23 |
return 0; |
| 24 |
} |
| 25 |
|
| 26 |
sub wanted |
| 27 |
{ |
| 28 |
$File::Find::prune = 0; |
| 29 |
if (-x $_ && -T $_ && !/%$/) |
| 30 |
{ |
| 31 |
local $unsure = !/\.p[ml]$/; |
| 32 |
local $file = ($_); |
| 33 |
local ($_); |
| 34 |
open($file,"<$file") || die "Cannot open $file:$!"; |
| 35 |
while (<$file>) |
| 36 |
{ |
| 37 |
last if &match; |
| 38 |
} |
| 39 |
close($file); |
| 40 |
} |
| 41 |
elsif (-d $_) |
| 42 |
{ |
| 43 |
$File::Find::prune = 1 if ($_ eq 'blib'); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
@ARGV = '.' unless (@ARGV); |
| 48 |
|
| 49 |
sub de_bak |
| 50 |
{ |
| 51 |
if (/^(.*)\.bak$/) |
| 52 |
{ |
| 53 |
unlink("$1.oops"); |
| 54 |
rename($1,"$1.oops") if (-f $1); |
| 55 |
rename($_,$1); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
# find(\&de_bak,@ARGV); |
| 61 |
|
| 62 |
find(\&wanted,@ARGV); |
| 63 |
|
| 64 |
print join(',',@todo),"\n"; |
| 65 |
|
| 66 |
|
| 67 |
$^I = ".bak"; |
| 68 |
|
| 69 |
if (@todo) |
| 70 |
{ |
| 71 |
@ARGV = @todo; |
| 72 |
while (<>) |
| 73 |
{ |
| 74 |
s/$expr/use lib ($1);\n/; |
| 75 |
print; |
| 76 |
} |
| 77 |
} |
| 78 |
|