I'm working on an app and I want to include sophisticated config files processing. Here's a list of what I want:

Dizzy yet?

The hard part of all this is the chicken-and-egg of letting the config files decide which config files to process.

For example A.conf,B.conf and C.conf are the normal config files in order. (A.conf overrides B.conf, B.conf overrides C.conf) C.conf adds D.conf, B.conf removes C.conf and adds E.conf. So, in the end, we should get the values from A.conf, B.conf and E.conf. I got confused just writing this example!

My best idea so far is to write a big fat algorithm that starts with the basic list of config files and...

  1. reads the files in the list
  2. alters the list of config files
  3. checks to see if in the first read through it read something it shouldn't have
  4. alter the list again
  5. read the files in the list
  6. repeat until the list is stable

And only then start reading config files for the purpose of gathering the other config values.

Does anyone have any bright ideas of how to handle this?

Thanks!
--Pileofrogs

Update: I never knew the right names for the XY Problem and YAGNI. Groovy!

I think, yeah, you're probably both right in that I'm suffering from both XY and YAGNI.

To speak to the XY issues, I've been working with CPAN::Mini::Inject, but the configuration files and command line handling could be better. Specifically, you have to put some variables in config files and others have to be specified on the command line. The command line is always really long. I thought it would be better if you could (1) specify any variable either on the command line or the config file and (2) if values set in the global config files (/etc/mcpani) could be overridden by values in more specific config files ($HOME/.mcpani/config). Some values tend to be the same no matter what you are doing, others tend to be different from user to user, but the same across that user's projects. Others tend to be different from project to project. I've emailed with the author, and he liked my ideas so I'm working on implementing it now.

Now, we get to the YAGNI. What if I decide I don't like what the sysadmin puts in /etc/mcpani? Or, maybe I realise that half my projects use 5 of the same variables, so maybe I want to include a file?

In the reality of the problem, I should probably just say "These are your config files, if you don't like the values, in the global config, override them yourself. If you have the same values come up over and over, deal with it."

However, in the context of monks chewing the fat, this problem seems interesting. I know certain apps do something like this, for example, vim reads /etc/vimrc and $HOME/.vimrc and a zillion other config files as well...


In reply to Config File Shuffle by pileofrogs

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.