[Dancer-users] Dancer.pm sets confdir too early

Stéphane stephane at shimaore.net
Mon Apr 26 17:08:42 CEST 2010

>>     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      => ...


   #!/usr/bin/env perl
   use MyApp::Portal;

   use Dancer ':syntax';
   use Dancer::Config;
   use Dancer::GetOpt;



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');


More information about the Dancer-users mailing list