Weird title - sorry. Let me explain...

The module Config::Loader Config::Merge has the ability to override the default config with local values. For instance, on your development machine, you may want to use a different database host. So you can override just that value:

app: servers: db: host: db.domain.com username: username password: password email: host: mail.domain.com etc

Then override/merge with:

app: servers: db: host: dev.domain.com email: host: dev.domain.com

A deep merge of hashes is done, so that the other config data is preserved.

I would like to provide a mechanism for altering arrays, rather than just having to copy and paste the entire array. So what I have thought of is the following:

main: cronjobs: - job1 - job2 - job3 - job4 - job5

Then override/merge with:

main: cronjobs: '!' : # key '!' must exist to signal m +erge '-' : # delete elements 3 and 5 - 3 - 5 '+' : # append jobs 6 and 7 - job6 - job7 OR '+' : # insert job8 at index 2, job9 a +t index 5 2: job8 5: job9 1: job10 # change index1 from job2 to job +10
I realise that most people probably won't use this, but I have wanted something like this on occasion, and so I was wondering if anybody had a better/simpler way of representing these changes?

thanks

Clint

UPDATE - corrected hostname to host (thanks fenLisesi)

UPDATE - change the module name to Config::Merge


In reply to RFC: An "API" for overriding array values in config data by clinton

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.