What about substitutions in config files?
Hello! There is one useful feature in Catalyst::Plugin::ConfigLoader - substitutions before parsing config: http://search.cpan.org/~bricas/Catalyst-Plugin-ConfigLoader-0.30/lib/Catalys...) Sometimes it's comfortably to use paths relative to 'appdir' or 'public'. Cwd (current working directory) depends on your setup (mod_per,plack,etc.) In my case (plackup under supervise) cwd is under service (daemontools specific) directory. I have adjusted Dancer::Config slightly: --- Dancer/Config.pm.orig 2011-09-01 18:50:30.000000000 +0400 +++ Dancer/Config.pm 2011-09-01 19:00:54.000000000 +0400 @@ -200,7 +200,14 @@ my $config; - eval { $config = YAML::LoadFile($file) }; + my $yaml = do { + open my $fh, $file or + confess "Unable to load the configuration file: $file: $!"; + local $/ = <$fh>; + }; + $yaml =~ s/__setting\((appdir|confdir|public|views)\)__/setting($1)/ge; + + eval { $config = YAML::Load($yaml) }; if (my $err = $@ || (!$config)) { confess "Unable to parse the configuration file: $file: $@"; } This little patch allowed me to use relative paths in config.yml without worry about my top-level setup: engines: xslate: cache_dir: '__setting(appdir)__/var/xslate' path: [ '/','__setting(views)__' ] photos: basedir: '__setting(appdir)__/photos' What do you think about inclusion this functionality in Dancer core? -- Cheers, Oleg A. Mamontov mailto: oleg@mamontov.net jabber: lonerr@charla.mamontov.net icq uin: 79-521-617 cell: +7-903-798-1352
participants (1)
-
Oleg A. Mamontov