$ENV{LC_ALL} = 'C';
-use FindBin;
-chdir $FindBin::Bin or die "$0: Can't chdir $FindBin::Bin: $!";
+my $Quiet;
+@ARGV = grep { not($_ eq '-q' and $Quiet = 1) } @ARGV;
-my $Quiet = @ARGV && $ARGV[0] eq '-q';
-
-open (OUT, ">perlmodlib.pod") or die $!;
-my (@pragma, @mod, @files);
+if (@ARGV) {
+ my $workdir = shift;
+ chdir $workdir
+ or die "Couldn't chdir to '$workdir': $!";
+}
+require 'regen/regen_lib.pl';
# MANIFEST itself is Unix style filenames, so we have to assume that Unix style
# filenames will work.
-open (MANIFEST, "../MANIFEST") or die $!;
-@files = grep m#(?:\.pm|\.pod|_pm\.PL)#, map {s/\s.*//s; $_}
+open MANIFEST, '<', 'MANIFEST'
+ or die "Can't open MANIFEST: $!";
+my @files = grep m#(?:\.pm|\.pod|_pm\.PL)#, map {s/\s.*//s; $_}
grep { m#^(lib|ext|dist|cpan)/# && !m#/(?:t|demo)/# } <MANIFEST>;
+close MANIFEST
+ or die "$0: failed to close MANIFEST: $!";
+
+my $out = open_new('pod/perlmodlib.pod', undef,
+ {by => "$0 extracting documentation",
+ from => 'the Perl source files'}, 1);
my %exceptions = (
'abbrev' => 'Text::Abbrev',
'libnetFAQ' => 'Net::libnetFAQ',
);
+my (@pragma, @mod);
+
for my $filename (@files) {
- unless (open MOD, '<', "../$filename") {
- warn "Couldn't open ../$filename: $!";
+ unless (open MOD, '<', $filename) {
+ warn "Couldn't open $filename: $!";
next;
}
}
my $title = <MOD>;
chomp $title;
- close MOD;
+ close MOD
+ or die "Error closing $filename: $!";
($name, $thing) = split / --? /, $title, 2;
# makes it tidier, by stopping anything doing this mistaking the rest of the
# Perl code for Pod. eg http://search.cpan.org/dist/perl/pod/perlmodlib.PL
-print OUT <<'=cut';
-=for maintainers
-Generated by perlmodlib.PL -- DO NOT EDIT!
-
+print $out <<'=cut';
=head1 NAME
perlmodlib - constructing new Perl modules and finding existing ones
=cut
-print OUT $_ for (sort @pragma);
+print $out $_ for sort @pragma;
-print OUT <<'=cut';
+print $out <<'=cut';
=back
=cut
-print OUT $_ for (sort @mod);
+print $out $_ for sort @mod;
-print OUT <<'=cut';
+print $out <<'=cut', "=cut\n";
=back
=cut
-close MANIFEST or warn "$0: failed to close MANIFEST (../MANIFEST): $!";
-close OUT or warn "$0: failed to close OUT (perlmodlib.pod): $!";
-
+read_only_bottom_close_and_rename($out);