[Dancer-users] Using configuration files with other formats than YAML
Octavian Rasnita
orasnita at gmail.com
Thu Oct 18 12:23:22 BST 2012
Hi,
I've seen that Dancer can use just YAML configuration files and no other formats like JSON, ini, Apache or others.
Are there specific reasons for this limitation?
I use a short and dirty code that allows using all types of configuration files supported by Config::Any:
use Dancer ':syntax';
use FindBin;
use Config::Any;
my $config = Config::Any->load_stems( { stems => [ "$FindBin::Bin/../config" ], flatten_to_hash => 1, use_ext => 1 } );
my @config = %$config;
$config = $config[1];
set $_ => $config->{$_} for keys %$config;
my $env = Config::Any->load_stems( { stems => [ "$FindBin::Bin/../environments/" . config->{environment} ], flatten_to_hash => 1, use_ext => 1 } );
my @env = %$env;
$env = $env[1];
set $_ => $env->{$_} for keys %$env;
After doing this I can use configuration files like config.yml, config.conf, config.pl... and environments/development.yml, environments/development.conf... each one with their specific format.
In the code above I used just a single configuration file, but with a code just a little bit longer the app could get and use the vars defined in more files with the same name and different formats if it is needed, but that thing is probably not very useful.
The question is, wouldn't be better if Dancer would use Config::Any in core?
It would be more flexible and Config::Any doesn't require other modules. Those modules will be installed only by those who need them.
--Octavian
More information about the dancer-users
mailing list