-
Notifications
You must be signed in to change notification settings - Fork 281
Description
Could we separate the configuration system into its own distribution?
Dancer2's config system is quite usable for a serious business application. It is straightforward and clear, and still allows different configurations for different environment type, deployments and local special cases.
In my own applications I have many services: Dancer2 webservices, TheSchwarz worker queue, daemons, and others. Also database migration scripts and others. They all use the same configuration. When starting, they use DancerLikeConfig which is a module I programmed so that I would not need to include all of Dancer2 hierarchy into the program. But it still includes a lot, especially Dancer2::Core.
It would be great to be able to use only the configuration, not the whole of Dancer2. Loading everything takes time, sometimes seconds.
Name proposals: "App-Config-Dancer2", "App-Config-Modern", "App-Config-Deployments".
My DancerLikeConfig:
package Util::Config::DancerLikeConfig;
use strict;
use warnings;
use Moo;
use Dancer2::ConfigReader;
use Dancer2::Core::Types;
with qw<
Dancer2::Core::Role::HasConfig
Dancer2::Core::Role::HasLocation
Dancer2::Core::Role::HasEnvironment
>;
has config_reader => (
is => 'lazy',
isa => InstanceOf['Dancer2::ConfigReader'],
);
sub _build_config_reader { ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
my ($self) = @_;
my $cfgr = Dancer2::ConfigReader->new(
environment => $self->environment,
location => $ENV{DANCER_CONFDIR} || $self->location,
# default_config => $self->_build_default_config(),
default_config => {},
);
return $cfgr;
}
has '+config' => (
is => 'lazy',
isa => HashRef,
);
sub _build_config { ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
my ($self) = @_;
my $config_reader = $self->config_reader;
my $config = $config_reader->config;
return $config;
}
1;