#!/usr/bin/perl -w
Getopt::Long::Configure (
"bundling"
);
pod2usage(2)
if
(
$#ARGV
>= 0 &&
$ARGV
[0] eq
'-?'
);
my
(
$prog
) = $0;
my
$debug
=
undef
;
my
$verbose
=
undef
;
&GetOptions
(
'help|?'
=>
sub
{ pod2usage(1); },
'man'
=>
sub
{ pod2usage(
-verbose
=> 2); },
'd|debug+'
=> \
$debug
,
'v|verbose+'
=> \
$verbose
) or pod2usage(2);
my
$code
=
''
;
my
$in_code
=
undef
;
open
(MFPL,
"< Makefile.PL"
) or
die
"cannot open Makefile.PL\n"
;
while
(<MFPL>) {
if
(!
$in_code
) {
if
(/BEGIN MODULE LIST/) {
$in_code
= 1;
};
}
else
{
if
(
$in_code
&& /END MODULE LIST/) {
$in_code
=
undef
;
}
else
{
s/^
my
//;
$code
.=
$_
;
};
};
};
close
MFPL;
my
@modularized_db_programs
;
my
@modularized_db_converters
;
my
@modularized_db_non_programs
;
my
@helper_db_programs
;
my
@standalone_db_programs
;
my
@converters
;
my
@backwards_db_programs
;
eval
$code
;
$@ &&
die
"internal eval error: $@.\n"
;
my
$active_pn
=
undef
;
sub
prepare_transaction {
my
(
$pn
) =
@_
;
die
"ongoing transaction on $active_pn, cannot start $pn\n"
if
(
defined
(
$active_pn
));
open
(OLD,
"<$pn"
) or
die
"cannot read $pn\n"
;
open
(NEW,
">$pn+"
) or
die
"cannot write $pn\n"
;
$active_pn
=
$pn
;
}
sub
commit_transaction {
close
NEW;
close
OLD;
my
$pn
=
$active_pn
;
$pn
or
die
"no active transaction\n"
;
rename
$pn
,
"$pn~"
or
die
"cannot rename $pn to $pn~\n"
;
if
(!
rename
(
"$pn+"
,
$pn
)) {
rename
"$pn~"
,
$pn
;
die
"cannot rename $pn+ to $pn\n"
;
};
$active_pn
=
undef
;
}
prepare_transaction(
"bin/.gitignore"
);
print
NEW
"# This file is managed by update_modules; DO NOT EDIT DIRECTLY.\n"
;
print
NEW
"*-\n"
;
foreach
(
sort
(
@modularized_db_programs
,
@modularized_db_converters
)) {
print
NEW
"$_\n"
;
};
commit_transaction;
prepare_transaction(
"MANIFEST.SKIP"
);
my
$in_ms_section
=
undef
;
while
(<OLD>) {
if
(
$in_ms_section
) {
$in_ms_section
=
undef
if
(/END AUTOGENERATED SECTION/);
};
if
(!
$in_ms_section
) {
print
NEW
$_
;
if
(/BEGIN AUTOGENERATED SECTION/) {
$in_ms_section
= 1;
print
NEW
"# This next section is managed by update_modules. DO NOT EDIT DIRECTLY.\n"
;
foreach
(
sort
(
@modularized_db_programs
,
@modularized_db_converters
)) {
print
NEW
"bin/$_\$\n"
;
};
};
};
};
commit_transaction;
prepare_transaction(
"lib/Fsdb/Filter/dbpipeline.pm"
);
my
$in_dbp_section
=
undef
;
while
(<OLD>) {
if
(
$in_dbp_section
) {
$in_dbp_section
=
undef
if
(/END AUTOGENERATED \S+ SECTION/);
};
if
(!
$in_dbp_section
) {
print
NEW
$_
;
if
(/BEGIN AUTOGENERATED VARIABLE SECTION/) {
$in_dbp_section
= 1;
print
NEW
"# This next section is managed by update_modules. DO NOT EDIT DIRECTLY.\n"
;
print
NEW
"our \@modularized_db_programs = qw("
.
join
(
"\n\t"
,
''
,
@modularized_db_programs
) .
"\n);\n"
;
print
NEW
"our \@modularized_db_converters = qw("
.
join
(
"\n\t"
,
''
,
@modularized_db_converters
) .
"\n);\n"
;
print
NEW
"our \@modularized_db_non_programs = qw("
.
join
(
"\n\t"
,
''
,
@modularized_db_non_programs
) .
"\n);\n"
;
};
if
(/BEGIN AUTOGENERATED DOCUMENTATION SECTION/) {
$in_dbp_section
= 1;
print
NEW
"\n=over\n\n"
;
foreach
(
sort
(
@modularized_db_programs
,
@modularized_db_converters
)) {
print
NEW
"=item L<$_(1)>\n\n"
;
};
print
NEW
"=back\n\n=for comment\n"
;
};
};
};
commit_transaction;
exit
0;