-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetchParamDescriptionsUpdateVersion.pl
79 lines (69 loc) · 2.52 KB
/
fetchParamDescriptionsUpdateVersion.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use strict; use feature 'unicode_strings'; use Time::localtime;
# enter new version to update all modules with
print "new version (empty to skip and only fetch param descriptions into Wrap.pm):";
my $newVersion = <STDIN>;
chomp $newVersion;
# used for CONFIGURATION REFERENCE, fetches comments from %hashCheck in Common.pm and translates them to pod =items
open (COMMONFILE, "<".'lib\EAI\Common.pm') or die ('can\'t open lib\EAI\Common.pm for reading');
my $insertIntoEAIWrap; my $return; my $startParsing;
while (<COMMONFILE>){
if (/my %hashCheck = \(/) {
$startParsing = 1;
$insertIntoEAIWrap.="=over 4\n\n";
next;
}
next if !$startParsing;
if (/\t\},/) {
$insertIntoEAIWrap.="=back\n\n" if $return;
$return = 0;
}
if (/^\t(\S*?) =>.*# (.*?)$/) {
$insertIntoEAIWrap.="=item $1\n\n$2\n\n=over 4\n\n" if $2;
$return = $2;
}
if (/^\t\t(\S*?) =>.*# (.*?)$/) {
$insertIntoEAIWrap.="=item $1\n\n$2\n\n" if $2;
}
if (/^\);$/) {
$insertIntoEAIWrap.="=back\n\n";
last;
}
}
close COMMONFILE;
my $data = read_file ("Makefile.PL");
print "updating version for Makefile.PL\n";
$data =~ s/', version => [\d\.]+},/', version => $newVersion},/g if $newVersion;
write_file("Makefile.PL", $data);
my $curYear = localtime->year()+1900;
my $data = read_file ("lib/EAI/Wrap.pm");
print "updating version and API descriptions for Wrap.pm\n";
$data =~ s/^(.*?)=head2 CONFIGURATION REFERENCE\n\n(.*?)=head1 COPYRIGHT(.*?)$/$1=head2 CONFIGURATION REFERENCE\n\n${insertIntoEAIWrap}=head1 COPYRIGHT$3/s;
$data =~ s/^package EAI::(.*?) (.*?);\n(.*?)/package EAI::$1 $newVersion;\n$3/s if $newVersion;
$data =~ s/Copyright \(c\) (\d{4}) Roland Kapl/Copyright \(c\) $curYear Roland Kapl/s;
write_file("lib/EAI/Wrap.pm", $data);
for my $libfile ("Common","File","FTP","DB","DateUtil") {
print "updating version for $libfile\n";
my $data = read_file ("lib/EAI/$libfile.pm");
$data =~ s/^package EAI::(.*?) (.*?);\n(.*?)/package EAI::$1 $newVersion;\n$3/s if $newVersion;
$data =~ s/Copyright \(c\) (\d{4}) Roland Kapl/Copyright \(c\) $curYear Roland Kapl/s;
write_file("lib/EAI/$libfile.pm", $data);
}
print "enter to finish.";
<STDIN>;
sub read_file {
my ($filename) = @_;
open my $in, '<:encoding(UTF-8)', $filename or die "Could not open '$filename' for reading $!";
binmode($in);
local $/ = undef;
my $all = <$in>;
close $in;
return $all;
}
sub write_file {
my ($filename, $content) = @_;
open my $out, '>:encoding(UTF-8)', $filename or die "Could not open '$filename' for writing $!";
binmode($out);
print $out $content;
close $out;
return;
}