Question

I am currently creating a Perl module for in house use. I used ExtUtils::ModuleMaker to generate a build script and skeleton for my Perl module. I would like to include .ini config files that my core modules need to run properly. Where do I put these files so they are installed with my module? What path do I need to use to access these config files across the main and sub modules?

P.S. this is the directory frame:

   |-lib
   |---Main.pm
   |---Main
   |-----subModule1.pm
   |-----subModule2.pm
   |-----subModule3.pm
   |-scripts
   |-t
Was it helpful?

Solution

If you are using Module::Install, you can use Module::Install::Share and File::ShareDir.

If you are using Module::Build, you may want to use its config_data tool and and a *::ConfigData module.

OTHER TIPS

Taking a look at the generated Makefile, I would bet the better place to put it is under lib/Main and then you can direct your module to look at ~/.modulerc first, then PERLLIB/Main/modulerc.ini or something like that.

You could also embed the defaults in your module in a way that, in absence of ~/.modulerc, the module works using the default data.

To find the home directory, see File::HomeDir. You'll not want to use ~ (since that's a shell thing anyway).

I would suggest having your module work without the rc file as much as possible. If it doesn't exist, the code should fall back to defaults. This should be true, too, even if the file exists, but a particular flag is missing - it should fall back to the default, too.

You may want to look at Config::Any while you're at it. No point reinventing that wheel.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top