Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

PREFIX patch for Module::Build

by dragonchild (Archbishop)
on Jun 01, 2005 at 15:24 UTC ( [id://462520]=perlmeditation: print w/replies, xml ) Need Help??

This is the patch adding PREFIX support that I provided to the Module::Build mailing list on May 24, 2005. The maintainers have said the patch is incomplete, so I'm posting it here (along with the test case) so that others can take it further and get PREFIX into Module::Build.

Patch for the source tree. (This is against the CVS head as of May 22, 2005.)

? MB.patch ? t/destinations.t Index: lib/Module/Build/Base.pm =================================================================== RCS file: /cvsroot/module-build/Module-Build/lib/Module/Build/Base.pm, +v retrieving revision 1.416 diff -u -r1.416 Base.pm --- lib/Module/Build/Base.pm 21 Apr 2005 01:59:55 -0000 1.416 +++ lib/Module/Build/Base.pm 25 May 2005 02:15:31 -0000 @@ -510,6 +510,7 @@ ignore_prereq_requires ignore_prereqs skip_rcfile + prefix ); { @@ -2536,12 +2537,42 @@ return File::Spec->catdir(@{$map{$type}}); } +sub prefixify { + my ($self, $type, $prefix) = @_; + + my %map = ( + site => { + lib => $self->{config}{installsitelib}, + arch => $self->{config}{installsitearch}, + bin => $self->{config}{installsitebin}, + script => $self->{config}{installscript}, + bindoc => $self->{config}{installsiteman1dir}, + libdoc => $self->{config}{installsiteman3dir}, + }, + ); + + my $installdirs = $self->installdirs; + return unless exists $map{$installdirs}{$type}; + + # Adapted from ExtUtils::MakeMaker::MM_Any::init_INSTALL_from_PRE +FIX() + my %prefixes = ( + core => $Config{installprefixexp} || $Config{installprefix} | +| + $Config{prefixexp} || $Config{prefix} || '', + vendor => $Config{usevendorprefix} ? $Config{vendorprefixexp +} : '', + ); + $prefixes{ site } = $Config{siteprefixexp} || $prefixes{core}; + + (my $rv = $map{$installdirs}{$type}) =~ s!\Q$prefixes{$installdir +s}\E\b!$prefix!; + return $rv; +} + sub install_destination { my ($self, $type) = @_; my $p = $self->{properties}; return $p->{install_path}{$type} if exists $p->{install_path}{$type +}; return File::Spec->catdir($p->{install_base}, $self->install_base_r +elative($type)) if $p->{install_base}; + return $self->prefixify($type, $p->{prefix}) if $p->{prefix}; return $p->{install_sets}{ $p->{installdirs} }{$type}; } Index: lib/Module/Build/Notes.pm =================================================================== RCS file: /cvsroot/module-build/Module-Build/lib/Module/Build/Notes.pm +,v retrieving revision 1.6 diff -u -r1.6 Notes.pm --- lib/Module/Build/Notes.pm 15 Apr 2005 22:59:05 -0000 1.6 +++ lib/Module/Build/Notes.pm 25 May 2005 02:15:31 -0000 @@ -76,7 +76,7 @@ foreach my $key (keys %{ $self->{new} }) { next if ref $self->{new}{$key}; next if ref $self->{disk}{$key} or !exists $self->{disk}{$key}; - delete $self->{new}{$key} if $self->{new}{$key} eq $self->{disk}{ +$key}; + delete $self->{new}{$key} if ($self->{new}{$key}||'') eq ($self-> +{disk}{$key}||''); } if (my $file = $self->{file}) {

This is the new test file (destinations.t) that tests this (and the current install_base) functionality.

use strict; use Test; BEGIN { plan tests => 32 } use Module::Build; ok(1); use Config; use File::Spec::Functions qw( catdir ); #use File::Spec; # #my $common_pl = File::Spec->catfile('t', 'common.pl'); #require $common_pl; ok( $INC{'Module/Build.pm'}, '/blib/', "Make sure Module::Build was lo +aded from blib/"); my $m = Module::Build->current; ok( UNIVERSAL::isa( $m, 'Module::Build::Base' ) ); ok( !defined $m->install_base ); ok( !defined $m->prefix ); # Do default tests here ok( $m->install_destination( 'lib' ) eq $Config{ installsitelib } ); ok( $m->install_destination( 'arch' ) eq $Config{ installsitearch } ); ok( $m->install_destination( 'bin' ) eq $Config{ installsitebin } || $ +Config{ installbin } ); ok( $m->install_destination( 'script' ) eq $Config{ installsitescript +} || $Config{ installsitebin } || $Config{ installscript } ); ok( $m->install_destination( 'bindoc' ) eq $Config{ installsiteman1dir + } || $Config{ installman1dir } ); ok( $m->install_destination( 'libdoc' ) eq $Config{ installsiteman3dir + } || $Config{ installman3dir } ); my $install_base = catdir( 'foo', 'bar' ); $m->install_base( $install_base ); ok( !defined $m->prefix ); ok( $m->install_destination( 'lib' ) eq catdir( $install_base, 'lib', +'perl5' ) ); ok( $m->install_destination( 'arch' ) eq catdir( $install_base, 'lib', + 'perl5', $Config{archname} ) ); ok( $m->install_destination( 'bin' ) eq catdir( $install_base, 'bin' ) + ); ok( $m->install_destination( 'script' ) eq catdir( $install_base, 'bin +' ) ); ok( $m->install_destination( 'bindoc' ) eq catdir( $install_base, 'man +', 'man1') ); ok( $m->install_destination( 'libdoc' ) eq catdir( $install_base, 'man +', 'man3' ) ); $m->install_base( undef ); ok( !defined $m->install_base ); ##### Adaptation START # Adapted from ExtUtils::MakeMaker::MM_Any::init_INSTALL_from_PREFIX() my $core_prefix = $Config{installprefixexp} || $Config{installprefix} +|| $Config{prefixexp} || $Config{prefix} || ''; my $vend_prefix = $Config{usevendorprefix} ? $Config{vendorprefixexp} + : ''; my $site_prefix = $Config{siteprefixexp} || $core_prefix; my $libstyle = $Config{installstyle} || 'lib/perl5'; my $manstyle = $libstyle eq 'lib/perl5' ? $libstyle : ''; ##### Adaptation END my $prefix = catdir( qw( some prefix ) ); $m->prefix( $prefix ); ok( $m->{properties}{prefix} eq $prefix ); my $test_val; ($test_val = $Config{installsitelib}) =~ s!\Q$site_prefix\E\b!$prefix! +; ok( $m->install_destination( 'lib' ) eq $test_val ); ($test_val = $Config{installsitearch}) =~ s!\Q$site_prefix\E\b!$prefix +!; ok( $m->install_destination( 'arch' ) eq $test_val ); ($test_val = $Config{installsitebin}) =~ s!\Q$site_prefix\E\b!$prefix! +; ok( $m->install_destination( 'bin' ) eq $test_val ); ($test_val = $Config{installscript}) =~ s!\Q$site_prefix\E\b!$prefix!; ok( $m->install_destination( 'script' ) eq $test_val ); ($test_val = $Config{installsiteman1dir}) =~ s!\Q$site_prefix\E\b!$pre +fix!; ok( $m->install_destination( 'bindoc' ) eq $test_val ); ($test_val = $Config{installsiteman3dir}) =~ s!\Q$site_prefix\E\b!$pre +fix!; ok( $m->install_destination( 'libdoc' ) eq $test_val ); $m->install_base( $install_base ); ok( $m->install_destination( 'lib' ) eq catdir( $install_base, 'lib', +'perl5' ) ); ok( $m->install_destination( 'arch' ) eq catdir( $install_base, 'lib', + 'perl5', $Config{archname} ) ); ok( $m->install_destination( 'bin' ) eq catdir( $install_base, 'bin' ) + ); ok( $m->install_destination( 'script' ) eq catdir( $install_base, 'bin +' ) ); ok( $m->install_destination( 'bindoc' ) eq catdir( $install_base, 'man +', 'man1') ); ok( $m->install_destination( 'libdoc' ) eq catdir( $install_base, 'man +', 'man3' ) );

  • In general, if you think something isn't in Perl, try it out, because it usually is. :-)
  • "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"

Replies are listed 'Best First'.
Re: PREFIX patch for Module::Build
by Steve_p (Priest) on Jun 02, 2005 at 02:31 UTC

    One thing to consider is using Test::More instead of Test. The use of Test::More is suggested by the Phalanx project. Also, a slow conversion to using Test::More to test core modules has been in the works for a while as well. Since Module::Build is slated to be part of the core in 5.10, it'd be nice to avoid having to redo the tests later.

      You're absolutely right, and I use Test::More in my modules. However, I used Test based on two considerations:
      1. The other testfiles in the Module::Build distribution used Test instead of Test::More and I felt that following their lead would be one less reason to deny the patch.
      2. Test is in the core for 5.003. Test::More doesn't enter the core until 5.005_03 (or so). I suspect that's the reason Ken Williams chose to use Test.

      • In general, if you think something isn't in Perl, try it out, because it usually is. :-)
      • "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"
Re: PREFIX patch for Module::Build
by ysth (Canon) on Jun 01, 2005 at 16:18 UTC
    The maintainers have said the patch is incomplete
    Unless you've had private mail, that seems to be overstating a little. The relevant message is here.
      The relevant section:

      Not sure. There's a lot of stuff missing that might not be necessary in Module::Build.

      I had already said that the patch was meant to be a starting point. IMHO, it's ok to release a developer build with documented caveats.


      • In general, if you think something isn't in Perl, try it out, because it usually is. :-)
      • "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"
        To perhaps clarify, I was just making a minor point; nothing wrong that I see with posting the patch here for people to review/add onto/try out.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://462520]
Approved by Limbic~Region
Front-paged by Limbic~Region
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-16 08:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found