hesco has asked for the wisdom of the Perl Monks concerning the following question:

Since discovering Config::Simple a couple of years ago, I have found it useful for more projects than not, including on my most recent application. For this one, though, I'm finding that I'd like to set up a default configuration for each client with one configuration file at /etc/app_name/client_name/app_name.ini, with each job specific instance set up for a client inheriting most of its configuration from there, but over-riding those parameters which are specific to a particular instance, out of its own file at: /etc/app_name/client_name/app_name_job_id.ini. Perhaps providing for multiple levels of inheritance would make sense as well: the server's base installation of the application being accessible at: /etc/app_name/app_name.ini

Is there some elegant, intuitive and simple way to accomplish this task? Am I talking about writing a whole new module: Config::Simple::Inherit to get the job done? Are there other tools out there better suited for this task (which hopefully won't require major surgery on an application which has recently been put into service)?

Any and all advice is appreciated.

-- Hugh Esco

UPDATE:

Man this turned out to be far easier than I feared it might be, at least to accomodate my simple needs. The results are now published on CPAN, as Config::Simple::Inherit. Along the way I learned some more about how absolutely elegant Sherzod B. Ruzmetov's work is. Mr. Ruzmetov: If you're out there and you see any value in this and would like to pick up this new ->inherit() method and include it in core, I certainly feel no need to get territorial about who gets to maintain those 20 or 30 lines of code and its associated documentation. Its available here if you want it: Config-Simple-Inherit-0.03.tar.gz

-- Hugh

if( $lal && $lol ) { $life++; }
  • Comment on Job specific Configuration, Inherit from Client Configuration

Replies are listed 'Best First'.
Re: Job specific Configuration, Inherit from Client Configuration
by hesco (Deacon) on Jun 01, 2008 at 17:42 UTC
    OK, the dishes are done and an idea is forming here. How about something along the lines of:

    =head1 SYNOPSIS my $installation_cfg = Config::Simple->new( file => '/etc/app_name/app +_name.ini' ); my $client_cfg = Config::Simple::Inherit->new( base_config => $installation_cfg, file => '/etc/app_name/client_name/app_name.ini', ); my $job_cfg = Config::Simple::Inherit->new( base_config => $client_cfg, file => '/etc/app_name/client_name/app_job_id.ini', ); =cut
    Does that seem like a reasonable interface to have to deal with? Makes me start thinking of the other missing for me in Config::Simple, namely Config::Simple::Heredoc, or am I making this less simple than it really ought to be? Or worse yet, reinventing a wheel needlessly?

    Thoughts?

    -- Hugh Esco

    if( $lal && $lol ) { $life++; }
Re: Job specific Configuration, Inherit from Client Configuration
by dragonchild (Archbishop) on Jun 01, 2008 at 20:54 UTC
    Catalyst::Plugin::ConfigLoader handles this quite nicely. Take a look at what's done there.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: Job specific Configuration, Inherit from Client Configuration
by hesco (Deacon) on Jun 05, 2008 at 02:02 UTC
    Man this turned out to be far easier than I feared it might be, at least to accomodate my simple needs. The results are now published on CPAN, as Config::Simple::Inherit. Along the way I learned some more about how absolutely elegant Sherzod B. Ruzmetov's work is. Mr. Ruzmetov: If you're out there and you see any value in this and would like to pick up this new ->inherit() method and include it in core, I certainly feel no need to get territorial about who gets to maintain those 20 or 30 lines of code and its associated documentation. Its available here if you want it: Config-Simple-Inherit-0.03.tar.gz

    -- Hugh

    if( $lal && $lol ) { $life++; }