reusing config.yml with environments
Hiya, This may be a colossally stupid question. I have a webapp that has many nifty things in config.yml and different settings based on the envirnoment. I'd like to use the Dancer config for cli utilities (a data loader for example) and not have to manually munge together the config.yml and the envinroment/<whatever>.yml. I don't want to use YAML, load the config.yml, find the environment, find the environment config file, load it and merge it with the main config... because Dancer already does that. Now, something like this works for a script I've got in a "scripts" folder off the root of my Dancer app: #!/usr/bin/perl use common::sense; use FindBin; use Data::Dumper::Concise; use Dancer ':syntax'; use Dancer::Config; set appdir => "$FindBin::Bin/../"; set environment => 'production'; Dancer::Config->load(); say Dumper(config); This does it just fine. Granted, it's relatively small but it seems klugy to me. Anyone else done something like this? How do you do it? Is there a better way? Am I utterly blind? Thanks, D aka meraxes -- dave.s.doyle@gmail.com
For what I know the dancer has no user friendly way of using config values outside dancer webapp. I'm just using YAML to manually parse config. I think this is the part where the dancer should help the user. I hope that somebody will write code that will solve this small issue (as we know there is a great myth about dancer, that one should only suggest plugin in the mail list and sooner or later the code will be on cpan =). 2011/2/10 Dave Doyle <dave.s.doyle@gmail.com>:
Hiya, This may be a colossally stupid question. I have a webapp that has many nifty things in config.yml and different settings based on the envirnoment. I'd like to use the Dancer config for cli utilities (a data loader for example) and not have to manually munge together the config.yml and the envinroment/<whatever>.yml. I don't want to use YAML, load the config.yml, find the environment, find the environment config file, load it and merge it with the main config... because Dancer already does that. Now, something like this works for a script I've got in a "scripts" folder off the root of my Dancer app:
#!/usr/bin/perl use common::sense; use FindBin; use Data::Dumper::Concise; use Dancer ':syntax'; use Dancer::Config; set appdir => "$FindBin::Bin/../"; set environment => 'production'; Dancer::Config->load(); say Dumper(config);
This does it just fine. Granted, it's relatively small but it seems klugy to me. Anyone else done something like this? How do you do it? Is there a better way? Am I utterly blind? Thanks, D aka meraxes -- dave.s.doyle@gmail.com
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
Sorry for the late reply! 2011/2/14 Иван Бессарабов <ivan@bessarabov.ru>
For what I know the dancer has no user friendly way of using config values outside dancer webapp.
Sure it does!
I hope that somebody will write code that will solve this small issue (as we know there is a great myth about dancer, that one should only suggest plugin in the mail list and sooner or later the code will be on cpan =).
I would if it didn't already exist. :) All you need to do is: use Dancer::Config 'setting'; my $template = setting('template'); my $layout = setting('layout'); my $extra = setting('MySettings'); Hope this helps! Sawyer.
participants (3)
-
Dave Doyle -
sawyer x -
Иван Бессарабов