From f556af6c048b2769e0a588d55ef54f5949171836 Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Wed, 10 Jul 2013 13:59:57 +0200 Subject: [PATCH] Refactor perlmodlib.PL to use regen_lib.pl and avoid FindBin. Instead of using FindBin, pass a directory to use on the command line. Use regen_lib for handling the output file. die if any file opened for reading has errors on closing. Run with the cwd as the top level of the distribution, instead of pod/ --- pod/perlmodlib.PL | 51 +++++++++++++++++++++++++++++---------------------- win32/Makefile | 2 +- win32/makefile.mk | 2 +- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/pod/perlmodlib.PL b/pod/perlmodlib.PL index 36990f9..7423f42 100644 --- a/pod/perlmodlib.PL +++ b/pod/perlmodlib.PL @@ -5,20 +5,29 @@ use warnings; $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)/# } ; +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', @@ -31,9 +40,11 @@ my %exceptions = ( '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; } @@ -54,7 +65,8 @@ for my $filename (@files) { } my $title = ; chomp $title; - close MOD; + close MOD + or die "Error closing $filename: $!"; ($name, $thing) = split / --? /, $title, 2; @@ -89,10 +101,7 @@ push @mod, "=item Config\n\nAccess Perl configuration information\n\n"; # 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 @@ -141,9 +150,9 @@ The following pragmas are defined (and have their own documentation). =cut -print OUT $_ for (sort @pragma); +print $out $_ for sort @pragma; -print OUT <<'=cut'; +print $out <<'=cut'; =back @@ -161,9 +170,9 @@ don't have the gdbm library. =cut -print OUT $_ for (sort @mod); +print $out $_ for sort @mod; -print OUT <<'=cut'; +print $out <<'=cut', "=cut\n"; =back @@ -1510,6 +1519,4 @@ you're redefining the world and willing to take the consequences. =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); diff --git a/win32/Makefile b/win32/Makefile index 024a238..eb686fd 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -1152,7 +1152,7 @@ utils: $(PERLEXE) $(X2P) ..\utils\Makefile cd ..\win32 $(PERLEXE) $(PL2BAT) $(UTILS) $(MINIPERL) -I..\lib ..\autodoc.pl .. - $(MINIPERL) -I..\lib ..\pod\perlmodlib.pl -q + $(MINIPERL) -I..\lib ..\pod\perlmodlib.PL -q .. ..\pod\perltoc.pod: $(PERLEXE) Extensions Extensions_nonxs $(PERLEXE) -f ..\pod\buildtoc -q diff --git a/win32/makefile.mk b/win32/makefile.mk index 4ed4a16..77da22c 100644 --- a/win32/makefile.mk +++ b/win32/makefile.mk @@ -1330,7 +1330,7 @@ utils: $(PERLEXE) $(X2P) ..\utils\Makefile copy ..\pod\perldelta.pod ..\pod\perl5192delta.pod $(PERLEXE) $(PL2BAT) $(UTILS) $(MINIPERL) -I..\lib ..\autodoc.pl .. - $(MINIPERL) -I..\lib ..\pod\perlmodlib.pl -q + $(MINIPERL) -I..\lib ..\pod\perlmodlib.PL -q .. ..\pod\perltoc.pod: $(PERLEXE) Extensions Extensions_nonxs $(PERLEXE) -f ..\pod\buildtoc -q -- 2.7.4