In a package I'm writing, I have a config module that looks like this:
use v6.d;
use JSON::Fast;
use PSBot::Tools;
sub EXPORT(--> Hash) {
my Str $path = do if %*ENV<TESTING> {
$*REPO.Str.IO.child('META6.json').e
?? $*REPO.Str.IO.child('t/config.json').Str # For when testing using zef
!! $*REPO.Str.IO.parent.child('t/config.json').Str; # For when testing using prove
} elsif $*DISTRO.is-win {
"%*ENV<LOCALAPPDATA>\\PSBot\\config.json"
} else {
"$*HOME/.config/PSBot/config.json"
};
unless $path.IO.e {
note "PSBot config at $path does not exist!";
note "Copy psbot.json.example there and read the README for instructions on how to set up the config file.";
exit 1;
}
with from-json slurp $path -> %config {
%(
USERNAME => %config<username>,
PASSWORD => %config<password>,
AVATAR => %config<avatar>,
HOST => %config<host>,
PORT => %config<port>,
SERVERID => %config<serverid>,
COMMAND => %config<command>,
ROOMS => set(%config<rooms>.map: &to-roomid),
ADMINS => set(%config<admins>.map: &to-id),
MAX_RECONNECT_ATTEMPTS => %config<max_reconnect_attempts>,
GIT => %config<git>,
DICTIONARY_API_ID => %config<dictionary_api_id>,
DICTIONARY_API_KEY => %config<dictionary_api_key>,
YOUTUBE_API_KEY => %config<youtube_api_key>,
TRANSLATE_API_KEY => %config<translate_api_key>
)
}
}
Every time I make changes to the config file, I have to delete the precomp files for the changes to appear. Is there a way I can write this so the exports aren't defined at compile time so users don't have to do this?
no precompilation
phaser? that will make it recompile every time the program starts, and other modules that use this one will probably also not be precompiled, but this script should run fast enough, i'd think – timotimo May 27 '19 at 8:25precompilation
could well phase those who don't understand why I'm commenting about it, and make those who do groan about my terrible humor, so I guess I'd better keep it to myself ) – raiph Jun 2 '19 at 13:01