Re: [Dancer-users] Dancer.pm sets confdir too early
[ CC'ing the list ] Le lundi 26 avril 2010 à 15:50 +0200, Stéphane a écrit :
In latest git, Dancer.pm at line 148 does:
setting confdir => $ENV{DANCER_CONFDIR} || setting('appdir');
however this overrides what Dancer::Config->load() (especially this means init_confdir() never get a chance to run).
Basically I'd like to be able to do:
use Dancer ':syntax'; set confdir => MyApp::confdir; # e.g. /etc/myapp/config.yml use Dancer;
but currently this gets overriden by Dancer->import().
No, you can't do that. It has never been possible to set the confdir via the "set" keyword as Dancer needs to parse configuration files at import time. The only supported way for using a separate confdir is to use the DANCER_CONFDIR environment variable. If you're running with the standalone server, just run it like: $ DANCER_CONFDIR=/etc/myapp ./server.pl ... Or under Apache, use SetEnv to set DANCER_CONFDIR. Changing that specific setting within the application code is not possible because if we allow that, we can't parse the configuration at load time. Regards, -- Alexis Sukrieh
use Dancer ':syntax'; set confdir => MyApp::confdir; # e.g. /etc/myapp/config.yml use Dancer;
[...] No, you can't do that. It has never been possible to set the confdir via the "set" keyword as Dancer needs to parse configuration files at import time.
Agreed. I had seen the DANCER_CONFDIR environment variable, but could not get it to work from within a Perl script or module (using $ENV{DANCER_CONFDIR} = ..) without calling Dancer->import() manually, so that defeated the purpose. I worked around it by doing: package MyApp::Portal; use Dancer ':syntax'; set confdir => MyApp::ConfDir; set appdir => ... and #!/usr/bin/env perl use MyApp::Portal; use Dancer ':syntax'; use Dancer::Config; use Dancer::GetOpt; Dancer::GetOpt->process_args(); Dancer::Config->load; dance; which mimics import() without forcing the settings. YMMV. Maybe import() could have a different parameter (besides :syntax), for example :nodefaults, which would do: unless ($symbol && $symbol eq ':nodefaults') { setting appdir => dirname(File::Spec->rel2abs($script)); # etc. setting confdir => $ENV{DANCER_CONFDIR} || setting('appdir'); } Stéphane
Le lundi 26 avril 2010 à 17:08 +0200, Stéphane a écrit :
use Dancer ':syntax'; set confdir => MyApp::confdir; # e.g. /etc/myapp/config.yml use Dancer;
[...] No, you can't do that. It has never been possible to set the confdir via the "set" keyword as Dancer needs to parse configuration files at import time.
Agreed. I had seen the DANCER_CONFDIR environment variable, but could not get it to work from within a Perl script or module (using $ENV{DANCER_CONFDIR} = ..) without calling Dancer->import() manually, so that defeated the purpose.
Then there is a bug we have to fix. Thanks for the report, if you have the time, could you report this issue? Thanks. -- Alexis Sukrieh
Agreed. I had seen the DANCER_CONFDIR environment variable, but could not get it to work from within a Perl script or module (using $ENV{DANCER_CONFDIR} = ..) without calling Dancer->import() manually, so that defeated the purpose.
Thinking about it, I didn't try putting it in a BEGIN block. That should take care of it. S.
participants (2)
-
Alexis Sukrieh -
Stéphane