Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Setting values in Module::Build

by EvdB (Deacon)
on Mar 18, 2004 at 13:25 UTC ( [id://337672]=perlquestion: print w/replies, xml ) Need Help??

EvdB has asked for the wisdom of the Perl Monks concerning the following question:

I am using Module::Build for a project and want all the files to be installed into a directory specified by the user.

Is there an elegant way to acheive in my Build.PL something like this:

use Module::Build; my $build = Module::Build->new( module_name => 'Foo::Bar', license => 'perl', ); my $install_dir = $build->prompt( "Where should I install to?", '/usr/local/install_here'); # This is what I am looking for. ################## # $build->set( install_base => $install_dir ); # # ################################################### $build->create_build_script;

I can achieve the above in other ways but none elegant. What I want to be able to do is change a setting after creating the build object.

If I am missing something obvious please let me know - I have read the docs and have even grep '^sub' Module/Build/Base.pm for something like 'set'.

--tidiness is the memory loss of environmental mnemonics

Replies are listed 'Best First'.
Re: Setting values in Module::Build
by chromatic (Archbishop) on Mar 18, 2004 at 18:02 UTC

    I just tried calling prompt() as a class method, to great success. What happens if you prompt first, then create the object?

      Yes - that would solve the problem nicely. Indeed the documentation even says it:
      This method (prompt) may be called as a class or object method.
Re: Setting values in Module::Build
by xdg (Monsignor) on Mar 18, 2004 at 23:28 UTC

    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.

      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 23:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found