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

RFC: An "API" for overriding array values in config data

by clinton (Priest)
on Jun 18, 2007 at 18:52 UTC ( [id://621856]=perlmeditation: print w/replies, xml ) Need Help??

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

Replies are listed 'Best First'.
Re: RFC: An "API" for overriding array values in config data
by princepawn (Parson) on Jun 19, 2007 at 13:42 UTC
    The more complications I see with config files and modules, the more persuaded I am by Uri Guttman's statement that Perl modules work just fine for configuring his apps.


    Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality
      Sure - and I'm torn between adding this or not, for that very reason.

      I think I WILL add it (under "Advanced Usage Only") because (a) I have wanted to use something like this in the past, and (b) you don't have to use it if you don't want to.

      thanks for the comment

      Clint

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://621856]
Approved by planetscape
Front-paged by bingos
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2024-04-16 09:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found