RSS Git Download  Clone
Raw Blame History
package AppTest;

BEGIN { # set test env otherwise development config settings loaded
   $ENV{DANCER_ENVIRONMENT} = 'test';
}

use FindBin qw($Bin); # warn $Bin;
use Data::Printer;
use YAML::Tiny;
use Model;
use Moo;

$ENV{SQL_TRACE} = 0;

has model => (
    is => 'ro',
    builder => sub { Model->new( app_config => shift->config ) },
);

has config => ( is => 'lazy' );
sub _build_config {
    my $yml = YAML::Tiny->read($Bin . '/../config.yml') || die $!; # p $yml->[0];
    my $cfg = $yml->[0];
    $cfg->{appdir} = $Bin . '/..'; # need to add manually, done in app by D2
    $cfg->{environment} ||= 'test'; # this is normally set in routes
    # overide config db_name param if env param set:
    if ( my $db_name = $ENV{DBNAME} ) {
        $cfg->{db_name} = $db_name;
    } # p $cfg;
    return $cfg;
}

1;