[Dancer-users] How to set config-environments when using Dancer as script

Assaf Gordon gordon at cshl.edu
Mon Sep 26 15:40:33 CEST 2011


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


More information about the Dancer-users mailing list