Open JJ opened 3 years ago
Actually, it does not depend on where you put use Dancer2
. It reads from lib/My
anyway
And if you place a (undocumented feature) .dancer
file at the top of your thing as indicated in #1580, it reads from that directory!
It's actually a bit more complicated: When DANCER_CONFIG_VERBOSE
is set, it "merges" the config file twice without the .dancer
file, three times with that file. Even so, it fails to set the port. Opening a different issue for that.
Every module you use Dancer2;
within creates an app (well, instantiates a Dancer2::Core::App object, Dancer2::Core::Runner keeps track of them). Each app get a name, which defaults to the namespace of where it is called.
Your repo has three places there this occurs. My::Hitos
, My::Hitos::Config
and hitos.psgi
(which uses the namespace main
). Each instance will load the config file as its app object gets instantiated. See Importing-using-Appname for how to split the code into several files yet combine into a single app.
Config file location will use $ENV{DANCER_CONFDIR}
or a heuristic if that is not set. The heuristic looks for (./lib
and ./bin
) or a .dancer
file for up to 10 directories above where the source file is. It then falls back to the directory where the source is if neither of those are found. The heuristic is a bit meh, but the CLI tools for generating a new app put the directories/files needed in the right place for it to work as documented.
Also, your psgi file uses the dance
keyword. This uses HTTP::Server::PSGI which is a non-forking single process server. Usually one returns a psgi coderef from their .psgi file (via My::Hitos->to_app
), and use other tools like plackup
to run the app. You gain all the features plackup offers; app reloading on code changes, and easy switching to other servers like Starman.
OK, I see what you mean. Let me try that. Maybe once I do I also fix the problems #1584 and #1585
OK, changed to
use v5.14;
use lib qw(lib);
use My::Hitos;
My::Hitos->to_app;
And it boots up alright. Still no trace of #1584 and #1585 working. It's reading the configuration file just the once:
Merging config file /home/jmerelo/Asignaturas/cloud-computing/p5-hitos/config.yml
/tmp
HTTP::Server::PSGI: Accepting connections at http://0:5000/
but not paying any attention at the port setting either in the config or in the application itself.
The original issue still stands (kinda). Your comment is not entirely clarified in the documentation.
Or maybe not entirely well specified. In this repo,
config.yml
is loaded fromlib/My
, which is if I'm not wrong where theDancer2
library isuse
d first. However, this will mean that in this programThe place where you read the configuration file will depend on where you put the
use
clause, ifMy::Hitos
alsouse
s Dancer2. It's probably OK if that's what you're looking for, but it should be documented.