Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by blue_cowdawg (Prior)
on Sep 17, 2012 at 18:36 UTC ( #994074=note: print w/ replies, xml ) Need Help??


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

As moritz already pointed out, if the information is static then what you have is a data file. In that event why not embed it into your module somehow?

If the end user is expected to modify the information somehow (DB name, DB host, user, password et. al.) then you should be using a configuration file. YAML, JSON, XML or just a good old fashioned text file with key value pairs is good. Another technique I've seen more than once is to create a file that looks a lot like a Perl module (in fact is) or plain Perl code to be read. Example:

package MyConfig; # # For the record: fixed the following 4 lines since my fingertips dec +ided to do something # other than what my brain was telling them to. s/my/our/ our $datahost="blah.foo.com"; our $datauser="user"; our $password="s3cr3t"; our $database="thedata"; 1;
which is then used thusly:
|random handwaving here... use MyConfig; my $host=$MyConfig::datahost; my $user=$MyConfig::datauser; my $pass=$MyConfig::password; my $database=$MyConfig::database; | now do something with it...

Personally for my own uses I use XML files and XML::Simple to load them.


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg


Comment on Re: Refactoring conf-driven app into a module; what to do with the config?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2014-07-13 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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








    Results (252 votes), past polls