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?"

In reply to PREFIX patch for Module::Build by dragonchild

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.