From: Michael G. Schwern Date: Sat, 9 Aug 2003 15:03:02 +0000 (-0700) Subject: produce Foo-Bar/lib/Foo/Bar.pm X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4a6602376e46f7ce9ede73b10063d105a533f05a;p=p5sagit%2Fp5-mst-13.2.git produce Foo-Bar/lib/Foo/Bar.pm Message-ID: <20030809220301.GE24919@windhund.schwern.org> (plus one extra catfile() in h2xs.t) p4raw-id: //depot/perl@20633 --- diff --git a/lib/h2xs.t b/lib/h2xs.t index 5acc0b2..2a5e14b 100644 --- a/lib/h2xs.t +++ b/lib/h2xs.t @@ -58,74 +58,74 @@ If you intend this module to be compatible with earlier perl versions, please specify a minimum perl version with the -b option. Writing $name/ppport.h -Writing $name/$name.pm +Writing $name/lib/$name.pm Writing $name/$name.xs Writing $name/fallback/const-c.inc Writing $name/fallback/const-xs.inc Writing $name/Makefile.PL Writing $name/README -Writing $name/t/1.t +Writing $name/t/$name.t Writing $name/Changes Writing $name/MANIFEST EOXSFILES "-f -n $name -b $thisversion", $], <<"EOXSFILES", Writing $name/ppport.h -Writing $name/$name.pm +Writing $name/lib/$name.pm Writing $name/$name.xs Writing $name/fallback/const-c.inc Writing $name/fallback/const-xs.inc Writing $name/Makefile.PL Writing $name/README -Writing $name/t/1.t +Writing $name/t/$name.t Writing $name/Changes Writing $name/MANIFEST EOXSFILES "-f -n $name -b 5.6.1", "5.006001", <<"EOXSFILES", Writing $name/ppport.h -Writing $name/$name.pm +Writing $name/lib/$name.pm Writing $name/$name.xs Writing $name/fallback/const-c.inc Writing $name/fallback/const-xs.inc Writing $name/Makefile.PL Writing $name/README -Writing $name/t/1.t +Writing $name/t/$name.t Writing $name/Changes Writing $name/MANIFEST EOXSFILES "-f -n $name -b 5.5.3", "5.00503", <<"EOXSFILES", Writing $name/ppport.h -Writing $name/$name.pm +Writing $name/lib/$name.pm Writing $name/$name.xs Writing $name/fallback/const-c.inc Writing $name/fallback/const-xs.inc Writing $name/Makefile.PL Writing $name/README -Writing $name/t/1.t +Writing $name/t/$name.t Writing $name/Changes Writing $name/MANIFEST EOXSFILES "\"-X\" -f -n $name -b $thisversion", $], <<"EONOXSFILES", -Writing $name/$name.pm +Writing $name/lib/$name.pm Writing $name/Makefile.PL Writing $name/README -Writing $name/t/1.t +Writing $name/t/$name.t Writing $name/Changes Writing $name/MANIFEST EONOXSFILES "-f -n $name $header -b $thisversion", $], <<"EOXSFILES", Writing $name/ppport.h -Writing $name/$name.pm +Writing $name/lib/$name.pm Writing $name/$name.xs Writing $name/fallback/const-c.inc Writing $name/fallback/const-xs.inc Writing $name/Makefile.PL Writing $name/README -Writing $name/t/1.t +Writing $name/t/$name.t Writing $name/Changes Writing $name/MANIFEST EOXSFILES @@ -134,7 +134,7 @@ EOXSFILES my $total_tests = 3; # opening, closing and deleting the header file. for (my $i = $#tests; $i > 0; $i-=3) { # 1 test for running it, 1 test for the expected result, and 1 for each file - # plus 1 to open and 1 to check for the use in $name.pm and Makefile.PL + # plus 1 to open and 1 to check for the use in lib/$name.pm and Makefile.PL # And 1 more for our check for "bonus" files, 2 more for ExtUtil::Manifest. # use the () to force list context and hence count the number of matches. $total_tests += 9 + (() = $tests[$i] =~ /(Writing)/sg); @@ -199,7 +199,7 @@ while (my ($args, $version, $expectation) = splice @tests, 0, 3) { pop @INC; chdir ($up) or die "chdir $up failed: $!"; - foreach my $leaf ("$name.pm", 'Makefile.PL') { + foreach my $leaf (File::Spec->catfile('lib', "$name.pm"), 'Makefile.PL') { my $file = File::Spec->catfile($name, $leaf); if (ok (open (FILE, $file), "open $file")) { my $match = qr/use $version;/; diff --git a/utils/h2xs.PL b/utils/h2xs.PL index c21a724..e444d5e 100644 --- a/utils/h2xs.PL +++ b/utils/h2xs.PL @@ -504,6 +504,7 @@ $Text::Wrap::huge = 'overflow'; $Text::Wrap::columns = 80; use ExtUtils::Constant qw (WriteConstants WriteMakefileSnippet autoload); use File::Compare; +use File::Path; sub usage { warn "@_\n" if @_; @@ -912,7 +913,6 @@ if( @path_h ){ # Save current directory so that C::Scan can use it my $cwd = File::Spec->rel2abs( File::Spec->curdir ); -my ($ext, $nested, @modparts, $modfname, $modpname); # As Ilya suggested, use a name that contains - and then it can't clash with # the names of any packages. A directory 'fallback' will clash with any # new pragmata down the fallback:: tree, but that seems unlikely. @@ -920,35 +920,21 @@ my $constscfname = 'const-c.inc'; my $constsxsfname = 'const-xs.inc'; my $fallbackdirname = 'fallback'; -$ext = chdir 'ext' ? 'ext/' : ''; - -if( $module =~ /::/ ){ - $nested = 1; - @modparts = split(/::/,$module); - $modfname = $modparts[-1]; - $modpname = join('/',@modparts); -} -else { - $nested = 0; - @modparts = (); - $modfname = $modpname = $module; -} - - +my $ext = chdir 'ext' ? 'ext/' : ''; + +my @modparts = split(/::/,$module); +my $modpname = join('-', @modparts); +my $modfname = pop @modparts; +my $modpmdir = join '/', 'lib', @modparts; +my $modpmname = join '/', $modpmdir, $modfname.'.pm'; + if ($opt_O) { warn "Overwriting existing $ext$modpname!!!\n" if -e $modpname; } else { die "Won't overwrite existing $ext$modpname\n" if -e $modpname; } -if( $nested ){ - my $modpath = ""; - foreach (@modparts){ - -d "$modpath$_" || mkdir("$modpath$_", 0777); - $modpath .= "$_/"; - } -} --d "$modpname" || mkdir($modpname, 0777); +-d "$modpname" || mkpath([$modpname], 0, 0775); chdir($modpname) || die "Can't chdir $ext$modpname: $!\n"; my %types_seen; @@ -1080,10 +1066,11 @@ if( ! $opt_X ){ # use XS, unless it was disabled } my @const_names = sort keys %const_names; -open(PM, ">$modfname.pm") || die "Can't create $ext$modpname/$modfname.pm: $!\n"; +-d $modpmdir || mkpath([$modpmdir], 0, 0775); +open(PM, ">$modpmname") || die "Can't create $ext$modpname/$modpmname: $!\n"; $" = "\n\t"; -warn "Writing $ext$modpname/$modfname.pm\n"; +warn "Writing $ext$modpname/$modpmname\n"; print PM <<"END"; package $module; @@ -1910,10 +1897,10 @@ use ExtUtils::MakeMaker; # the contents of the Makefile that is written. WriteMakefile( NAME => '$module', - VERSION_FROM => '$modfname.pm', # finds \$VERSION + VERSION_FROM => '$modpmname', # finds \$VERSION PREREQ_PM => {$prereq_pm}, # e.g., Module::Name => 1.1 (\$] >= 5.005 ? ## Add these new keywords supported since 5.005 - (ABSTRACT_FROM => '$modfname.pm', # retrieve abstract from module + (ABSTRACT_FROM => '$modpmname', # retrieve abstract from module AUTHOR => '$author <$email>') : ()), END if (!$opt_X) { # print C stuff, unless XS is disabled @@ -2065,7 +2052,7 @@ _RMEND_ close(RM) || die "Can't close $ext$modpname/README: $!\n"; my $testdir = "t"; -my $testfile = "$testdir/1.t"; +my $testfile = "$testdir/$modpname.t"; unless (-d "$testdir") { mkdir "$testdir" or die "Cannot mkdir $testdir: $!\n"; } @@ -2076,7 +2063,7 @@ open EX, ">$testfile" or die "Can't create $ext$modpname/$testfile: $!\n"; print EX <<_END_; # Before `make install' is performed this script should be runnable with -# `make test'. After `make install' it should work as `perl 1.t' +# `make test'. After `make install' it should work as `perl $modpname.t' ######################### @@ -2190,7 +2177,7 @@ EOP warn "Writing $ext$modpname/MANIFEST\n"; open(MANI,'>MANIFEST') or die "Can't create MANIFEST: $!"; -my @files = grep { -f } (<*>, , <$fallbackdirname/*>); +my @files = grep { -f } (<*>, , <$fallbackdirname/*>, <$modpmdir/*>); if (!@files) { eval {opendir(D,'.');}; unless ($@) { @files = readdir(D); closedir(D); }