-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbump_version.pl
58 lines (45 loc) · 1.38 KB
/
bump_version.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use Carp;
use File::Copy;
use File::Spec;
my ($old, $new) = @ARGV;
if (defined $old and defined $new) {
say 'Changing version from ', $old, ' to ', $new;
my @files = ('dist.ini', 'bin/cpandb', find_pm('lib'));
foreach my $file (@files) {
open(my $FIN, '<', $file) or fail('Cannot open file ', $file, ':', $!);
local $/;
my $content = <$FIN>;
close $FIN or fail('Cannot close file ', $file, ':', $!);
$content =~ s/$old/$new/g;
$content =~ s/\n\r/\n/g;
if (-e $file . '.bak') {
unlink($file . '.bak') or fail('Cannot open file ', $file, '.bak:', $!);
}
File::Copy::move($file => $file . '.bak') or fail('Cannot backup file ', $file, ':', $!);
open(my $FOUT, '>', $file) or fail('Cannot write file ', $file, ':', $!);
binmode $FOUT;
print $FOUT $content;
close $FOUT or fail('Cannot close file ', $file, ':', $!);
say $file;
}
} else {
say 'Usage: bump_version.pl <old_version> <new_version>';
}
sub fail {
Carp::longcarp(@_);
}
sub find_pm {
my ($dir) = @_;
opendir(my $DIR => $dir);
my @files = grep { !/^\./ } readdir($DIR);
closedir $DIR;
my @pm = map { File::Spec->catfile($dir, $_) } grep { /\.pm$/ } @files;
foreach my $subdir (grep { -d File::Spec->catfile($dir, $_) } @files) {
push @pm, find_pm(File::Spec->catfile($dir, $subdir));
}
return @pm;
}