Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Refactoring conf-driven app into a module; what to do with the config?

by moritz (Cardinal)
on Sep 17, 2012 at 18:27 UTC ( #994071=note: print w/ replies, xml ) Need Help??


in reply to Refactoring conf-driven app into a module; what to do with the config?

First of all you should be clear about "config file" versus "data file". If another user installs the same module on another machine, will he have to adapt some of those values? If yes, it's config. If not, it's data.

Second point: Just because it's a module doesn't mean that by some magic it shouldn't have to have configuration or data files. There are good use cases for those. So I'm not quite sure what your question is. Yes, I have written code that depended on data files and configuration files. Yes, one can handle that.

If your module has a build system similar to most CPAN modules, File::ShareDir can help you locating the files.

The needs regarding configuration can vary drastically by application, but they have in common that for most needs CPAN already has a solution.


Comment on Re: Refactoring conf-driven app into a module; what to do with the config?
Re^2: Refactoring conf-driven app into a module; what to do with the config?
by wokka (Acolyte) on Sep 17, 2012 at 19:07 UTC

    "Just because it's a module doesn't mean that by some magic it shouldn't have to have configuration or data files. There are good use cases for those. So I'm not quite sure what your question is."

    You seem to have a pretty good handle on either possibility, actually. Also, you seem to have some insight into misunderstandings I might have made, would you mind addressing those for posterity? Note that I wasn't asking if one could handle that, but how.

    "The needs regarding configuration can vary drastically by application, but they have in common that for most needs CPAN already has a solution."

    Exactly why I'm here...or why most people are here: for some suggestions and advice on best practices used in certain circumstances. Having reflected upon my question in light of your observations, I'm thinking that this falls into the "data file" category. Occasionally certain values will need to be changed, but this would be on an application-wide basis, not on a user-by-user basis.

    The module does not require a build process because it isn't intended for distribution, nor has it become generally useful enough to merit it, so perhaps File::SharDir is not the best solution.

    Do you have any further suggestions, given my clarification?

      The module does not require a build process because it isn't intended for distribution, nor has it become generally useful enough to merit it, so perhaps File::SharDir is not the best solution.

      File::ShareDir::ProjectDistDir then :)

      In your case I'd probably just hardcode a path, like /usr/share/yourmodule/ and put the data file(s) there. Unless they are pretty small, in which case a __DATA__ section would be even easier. Then change your module to read them when it needs them.

      That's the "how" if you don't follow the File::ShareDir route -- though personally I think that even simples modules should have a proper build/install system (via Module::Install or Module::Build), because it's easy to set up and easy to use.

      Occasionally certain values will need to be changed, but this would be on an application-wide basis, not on a user-by-user basis.

      This indicates that it's not a one-off script, but something that is developed and/or maintained over a longer period of time. I'd definitively go the Module::Install/Module::Build route for that, and use File::ShareDir to locate the data files. But your mileage my vary, of course.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994071]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2014-07-10 17:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (214 votes), past polls