Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Changing values in module installations.

by shotgunefx (Parson)
on Mar 21, 2002 at 00:29 UTC ( #153175=perlquestion: print w/replies, xml ) Need Help??
shotgunefx has asked for the wisdom of the Perl Monks concerning the following question:

What's the ideal way of specifying a value in a .pm file during it's installation.

Let's say I have a module that has an our $SYSTEM_ID that I want to be populated during the installation of one of my own modules. What's the best way to do this? (I'm using h2xs to generate the Makefile.PL) Do I just make a script that prompts and s/// the value in the file? I looked through the MakeMaker docs and really didn't find anything that helped. (Could be I missed it too.)


"To be civilized is to deny one's nature."
  • Comment on Changing values in module installations.

Replies are listed 'Best First'.
Re: Changing values in module installations.
by andreychek (Parson) on Mar 21, 2002 at 04:04 UTC
    There seems to be several different camps on how to handle something like that. As with the above suggestions, you could use the prompt method of ExtUtils::MakeMaker. It works something like this:
    # Somewhere in your Makefile.PL... use ExtUtils::MakeMaker qw(prompt); # Prompt the user for the system ID, offering "Default_id" # as the default (ie, if they just hit enter without # entering any new text) my $system_id = prompt("What is the system ID", "Default_id"); run_code_to_update_system_id_in_all_files( $system_id );
    Another idea is to offer a script which updates this variable, after all of your Perl modules are already installed. The advantage of this is that if the system id changes, it's very easy for the user to update their modules. This is almost like a package manager of some sort, but it doesn't have to be too complicated. It might act something like this:
    /usr/bin/ new_system_id
    This script could then find all your modules, and update them appropriatly.

    Just some thoughts.. hope that helps!
      Thanks for the suggestion. The former is basically what I ended up doing. I didn't know if there was a better idiom. The id shouldn't change later so I'm not worried about the update possibility, and in the rare case it does, I can vi it.


      "To be civilized is to deny one's nature."
Re: Changing values in module installations.
by hossman (Prior) on Mar 21, 2002 at 01:42 UTC
    Allthough I've never used it, I know that a ExtUtils::MakeMaker::prompt method exists (allthough, it seems to be extremely poorly documented).

    It should do exactly what you want, take a look at some other CPAN modules that use it in their Makefile.PL for examples.

      Thanks for the hint. What I find not obvious is how most people handle parts of a module that change during install time. I ended up just reading the source from the Makefile.PL and changing the value of $SYSTEMID to the prompted value with a s///. I didn't want a seperate cfg file as this module is loaded a lot. Basically a bunch of vars that define system defineds. (SMTP server, features enabled, log locations, etc.)


      "To be civilized is to deny one's nature."
Re: Changing values in module installations.
by Bobcat (Scribe) on Mar 21, 2002 at 03:14 UTC
    The CPAN module does something similar with various proxy settings and preferred mirrors, if I remember correctly. Perhaps this method is a good one to look at?

    The way we do it at my office is via a config file in a specified location relative to our application directories.

    All of my modules use either the current working directory as a "root" or pick the file from /etc/whatever.config, depending upon how it's running. This allows for testing with multiple software revisions; we have several software branches.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://153175]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2017-01-21 07:40 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (182 votes). Check out past polls.