Adding external config file

This commit is contained in:
piratefinn 2016-08-15 17:44:29 +01:00
parent f2f6e9782c
commit 75e2acfec9
2 changed files with 11 additions and 1 deletions

6
myapp.conf.example Normal file
View file

@ -0,0 +1,6 @@
{
foo => 'bar',
banana => 'monkey',
# Database connection details
dsn => "dbi:SQLite:dbname=foodloop.db",
};

View file

@ -5,7 +5,11 @@ use Data::UUID;
# connect to database
use DBI;
my $dbh = DBI->connect("dbi:SQLite:dbname=foodloop.db") or die "Could not connect";
my $config = plugin Config => {file => 'myapp.conf'};
use Devel::Dwarn; Dwarn $config;
my $dbh = DBI->connect($config->{dsn}) or die "Could not connect";
# shortcut for use in template
helper db => sub { $dbh };