Dancer2
view release on metacpan or search on metacpan
t/config_reader.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Carp 'croak';
use Path::Tiny qw< path >;
use Dancer2::Core::Runner;
use Dancer2::ConfigReader;
use Dancer2::ConfigReader::Config::Any;
# undefine ENV vars used as defaults for app environment in these tests
local $ENV{DANCER_ENVIRONMENT};
local $ENV{PLACK_ENV};
my $runner = Dancer2::Core::Runner->new();
my $location = path( __FILE__() )->sibling('config');
my $location2 = path( __FILE__() )->sibling('config2');
{
package ConfigUser;
use Moo;
with 'Dancer2::Core::Role::HasConfig';
has environment => ( is => 'ro', required => 1 );
has location => ( is => 'ro', required => 1 );
has default_config => ( is => 'ro', required => 1 );
sub _build_config {
my $self = shift;
return Dancer2::ConfigReader->new(
environment => $self->environment,
location => $self->location,
default_config => $self->default_config,
)->config;
}
}
sub config_any {
my ( $environment, $location ) = @_;
return Dancer2::ConfigReader::Config::Any->new(
environment => $environment,
location => $location,
);
}
sub config_reader {
my ( $environment, $location ) = @_;
return Dancer2::ConfigReader->new(
environment => $environment,
location => $location,
default_config => $runner->config,
);
}
sub config_user {
my ( $environment, $location ) = @_;
return ConfigUser->new(
environment => $environment,
location => $location,
default_config => $runner->config,
);
}
( run in 2.074 seconds using v1.01-cache-2.11-cpan-54e63673c56 )