How to set config-environments when using Dancer as script
Hello, I want to use "Dancer" (with some plugins, especially Database) from a command-line script, to accompany my website (some sort of behind-the-scenes access to the website infra-structure). But I've noticed that Dancer (when used with ":script" option) ignores any command line arguments, and so the "environment" can't be set, and so the configuration settings are always loaded from "development.yml". Example: === use Data::Dumper; use Dancer ':script'; use Dancer::Plugin::Database; ## too late - dancer already initialized with "development" environment setting ( "environment" => "production" ) ; my @result = database->quick_select( ### Whatever ### ) ; print Dumper(\@result),"\n"; === A work-around is to load Dancer with ":syntax" and initialize manually, but is this the best way? === use Data::Dumper; use Dancer ':syntax'; use Dancer::Plugin::Database; setting( "environment" => "production" ) ; Dancer::_init_script_dir($0); Dancer::Config->load; my @result = database->quick_select( ### Whatever ### ) ; print Dumper(\@result),"\n"; === Perhaps I'm doing something wrong, so any help is appreciated. Thanks, -gordon
On Mon, Sep 26, 2011 at 4:40 PM, Assaf Gordon <gordon@cshl.edu> wrote:
But I've noticed that Dancer (when used with ":script" option) ignores any command line arguments, and so the "environment" can't be set, and so the configuration settings are always loaded from "development.yml".
That's unfortunate behavior from Dancer. Sorry about that. :) Have you tried the environment variable for Dancer environments? S.
sawyer x wrote, On 09/28/2011 01:40 PM:
On Mon, Sep 26, 2011 at 4:40 PM, Assaf Gordon <gordon@cshl.edu <mailto:gordon@cshl.edu>> wrote:
But I've noticed that Dancer (when used with ":script" option) ignores any command line arguments, and so the "environment" can't be set, and so the configuration settings are always loaded from "development.yml".
Have you tried the environment variable for Dancer environments?
From what I understand from the Dancer code (version '1.3079_03'),
The config file is defined as: === sub conffile { path(setting('confdir') || setting('appdir'), 'config.yml') } === And 'appdir' can be changed with DANCER_APPDIR environment variable. But the environment-specific file is defined as: === sub environment_file { my $env = setting('environment'); return path(setting('appdir'), 'environments', "$env.yml"); } === And "setting{'environment'}" can't be set using unix environment variables (at least I couldn't find any reference to that in the code). -gordon
I meant DANCER_ENVIRONMENT. Try setting that.
participants (2)
-
Assaf Gordon -
sawyer x