Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
      So what's a good way to deal with this?

One way I've solved this for some modules for general use that I've authored for my job is to use XML::Simple to store my configs. If I have a program that is invoking a module that needs to get to a config file named "foo.pl" I simply create a file in the directory the script lives in called "foo.xml" and put the configuration information in there. For instance I have some database access modules that I use a lot and I store the information as such:

<disco_database> <host>database-host.foo.com</host> <dbname>disco</dbname> <user>disco</dbname> <password>duck</password> </disco_database>
in my xml file. The module s written to invoke XML::Simple thusly:
package my_package; use Class::DBI::Loader; use XML::Simple; | much handwaving... sub new { | more handwaving... my $config = new XMLIn(); $self->{loader} = Class::DBI::Loader -> new ( dsn => sprintf("dbi:%s:dbname=%s;host=%s", $config->{disco_database}->{driver}, $config->{disco_database]->{dbname}, $config->{disco_database}->{host}), user=>$config->{disco_database}->{user}, password=>$config->{disco_database}->{password} | and so forth...
This has the added bonus that if I have change any of the parameters that the script and its associated modules need to live on change I don't have to search through all the source code of the modules and script to change variables.

In other cases (and actually, the project I call "disco" is a good example of this) I put a config file that is central for that module. If I ever have to override it I make that a potential parameter for instantiating the module. For instance:

| blah blah... use IBM::Disco::HostEntry; | } | blah | | my $he = IBM::Disco::HostEntry->new{ config_file => qq(/path/to/file) ); |
When the module is instantiated it uses a default normally but when the parameter config_file is passed to the constructor I use that value instead.


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

In reply to Re: Config files in CPAN modules? by blue_cowdawg
in thread Config files in CPAN modules? by jimt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 18:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found