Sharing config files
Hi I have 2 Dancer apps, one a web site and another a RESTful api, both connecting to the same database At the mo they each have their own config.yml, but as so much configuration detail between them is common it would be great to have a central configuration for the common stuff and then a config for the relatively few things unique to the app. Any ideas how achieve such a regime? thanks Stephen
On Tue, Nov 15, 2011 at 4:01 AM, Stephen Fenwick-Paul <stephen@activeg.org> wrote:
Hi I have 2 Dancer apps, one a web site and another a RESTful api, both connecting to the same database At the mo they each have their own config.yml, but as so much configuration detail between them is common it would be great to have a central configuration for the common stuff and then a config for the relatively few things unique to the app. Any ideas how achieve such a regime? thanks Stephen
I just thought of this, though it may not be the best way. You can create an YourApp/CommonConfig.pm module which make calls to set(). Then you can import this module in both of your apps. -Naveed
On Tuesday 15 November 2011 09:01:52 Stephen Fenwick-Paul wrote:
Hi
I have 2 Dancer apps, one a web site and another a RESTful api, both connecting to the same database
At the mo they each have their own config.yml, but as so much configuration detail between them is common it would be great to have a central configuration for the common stuff and then a config for the relatively few things unique to the app.
Any ideas how achieve such a regime?
Currently I don't know of a particularly clean way, but that's something I'd like to see - a "merge config" option to allow you to load other config files and merge their content into the app's config. In the meantime, you could store your database settings in a separate YAML file, then in your apps, load that and put it into the app's config with something a little like: my $db_conf = YAML::LoadFile('database.yml'); config->{plugins}{Database} = $db_conf; That should work :) -- David Precious ("bigpresh") http://www.preshweb.co.uk/ "Programming is like sex. One mistake and you have to support it for the rest of your life". (Michael Sinz)
On Tuesday 15 November 2011 10:42:21 David Precious wrote:
In the meantime, you could store your database settings in a separate YAML file, then in your apps, load that and put it into the app's config with something a little like:
my $db_conf = YAML::LoadFile('database.yml'); config->{plugins}{Database} = $db_conf;
That should work :)
And of course that could be even more concise using the from_yaml() keyword provided by Dancer, e.g.: config->{plugins}{Database} = from_yaml('database.yml'); -- David Precious ("bigpresh") http://www.preshweb.co.uk/ "Programming is like sex. One mistake and you have to support it for the rest of your life". (Michael Sinz)
participants (3)
-
David Precious -
Naveed Massjouni -
Stephen Fenwick-Paul