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

I have a module that checks a config file found in the module's share directory for the user name and password for a website. When the module is installed, I would like the module to ask the user to input their user name and password to place in the configuration file and then save it to the share directory during the install process. How do I trigger this script upon installation? Is there a cpan module that makes this easy?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

  • Comment on Module for setting up configuration file during module installation

Replies are listed 'Best First'.
Re: Module for setting up configuration file during module installation
by 1nickt (Canon) on Jan 03, 2019 at 01:54 UTC

      The first link doesn't work. And I don't know enough about MakeMaker files to really know how to write my own to run a configuration script with the second module you linked to, unfortunately.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        The first link is to a function prompt() provided in ExtUtils::MakeMaker. Didn't the lower casing of the last element indicate that? Did you look at the doc for EU::MM to find it? I've corrected the URL now, thanks Athanasius.

        The second link is to a dzil plugin that allows you to create a custom Makefile script, which would incorporate the prompting for input you wanted. If you're not willing to use it because you "don't know enough about it", then I don't know what can be done other than put in the effort to learn about it. Shrug.

        (The same author released Dist::Zilla::Plugin::ModuleBuild::Custom if you use Module::Build, but I am not aware of a built-in way to prompt for user information.)


        The way forward always starts with a minimal test.
Re: Module for setting up configuration file during module installation
by Corion (Patriarch) on Jan 03, 2019 at 12:21 UTC

    Personally, I wouldn't conflate the (module) installation and (application) setup steps. Especially adding interactive parts to the module installation will wreck your chances of automated installation of the module.

    If the module can use some general information, I would add another script to the module which asks the user about some information and then fills a hardcoded template using that information. That way, you can easily add comments and optional (commented out) sections to the user configuration file without needing special handling.