tags:

views:

134

answers:

3

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
+1  A: 

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.

Massa
How do I get perl to handle ~ for both *nix and win32 properly. When I try mkdir "~/.config" it actually makes a ./~/.config folder in win32
kthakore
_That_ is really another question, isn't it? _I_ would do`"@{[$ENV{HOME}//$ENV{HOMEPATH}//$ENV{USERPROFILE}]}/.modulerc"`... it should be enough. If your perl is < 5.10, substitute the slanted bars with upright bars :-D
Massa
+1  A: 

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.

Tanktalus
Config::Any is always a good idea...
Massa
+3  A: 

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.

ysth
Exactly what I wanted!
kthakore
umm ... I am doing use Module::Install::Share;# Put everything inside ./share/ into the distribution 'auto' pathModule::Install::Share::install_share( 'share' );but I get error Can't locate object method "postamble" via package "share"
kthakore
@kthahore: Don't qualify it; just use "install_share 'share';". Module::Install uses too much magic
ysth