in reply to Setting values in Module::Build

A couple comments here. First, you're free to get whatever input you want from the user before constructing the Module::Build object. Put that input in a hash and add it to the arguments to new(). If you're really set on using prompt() from Module::Build, there's nothing in that function that requires an object so you should be able to just call it as a class method. See below for an example (on the command line).

$ perl -MModule::Build -e 'Module::Build->prompt("are you there","Y")' are you there [Y] Y

That means that something like this should work:

$user_install_base = Module::Build->prompt("Where to install?","/usr +/local"); Module::Build->new( ... install_base => $user_install_base, ... );

Second, I'm not entirely sure why you feel you need to prompt a user for this as part of your Build.PL or if that's in fact the wisest thing to do if you're building a module for general use. (If you're using this for another purpose, then it may not matter.) For one thing, Module::Build already has a fairly well defined set of default installation locations. Also, it has a very easy method to allow users to override that location by passing parameters on the command line either when creating the Build script with Build.PL or when using the Build script. E.g.:

$ perl Build.PL install_base=/home/david or $ Build install install_base=/home/david

Simply documenting that in your README or other documentation should be sufficient to guide your users for custom locations. If you really want to be picky, your Build.PL could simply check the supplied arguments for a valid "install_base" command line argument to be sure a user supplied that or else quit with an error requiring them to add that. (That will play havoc with CPAN installations, so I'd only use that for some custom purpose.)

Best of luck!

-xdg

Code posted by xdg on PerlMonks is public domain. It has no warranties, express or implied. Posted code may not have been tested. Use at your own risk.

Replies are listed 'Best First'.
Re: Re: Setting values in Module::Build
by EvdB (Deacon) on Mar 19, 2004 at 12:03 UTC
    Thank you for your reply. The stuff I am working on will not go onto CPAN - although I hope to break sub parts out and load them up.

    The idea behind prompting the user for where to install is that the user will not want the libraries in the general path, but will want to ensure that only they have access to them. This is partly because they will have paid for them and partly to ensure that no upgrades happen without their knowledge. Putting everything in a user specified place is the easiest way to deal with this.

      That doesn't explain why you have to use an interactive prompt. Interactive installs are bad. The information you're asking for is commonly called "prefix" and should be passed on the commandline. In fact I'd be very surprised if Module::Build doesn't already know how to handle that as it's a crucial capability for a build system to have. With ExtUtils::MakeMaker it's perl Makefile.PL PREFIX=/opt/foo; there has to be an equivalent for Module::Build.

      Makeshifts last the longest.

        The install needs to be interactive for reasons other than the installation location. At perl Build.PL time lots of questions get asked, related to things such as which database should be used during testing, which user to connect as, etc. These things cannot be guessed reliably and so the user must be prompted for them.

        As the user is being prompted for these details it is only sensible to ask for the installation path as well through a prompt, rather than getting the user to use another method to set that one value.

        If the installation path was the only thing that needed to be determined and it could default to the system standard then I would agree with you, however in _this_ situation I feel that prompting in a consistent manner is the best approach.