【发布时间】:2019-06-05 12:01:56
【问题描述】:
在我正在编写的一个包中,我有一个如下所示的配置模块:
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>
)
}
}
每次我对配置文件进行更改时,我都必须删除 precomp 文件才能使更改出现。有没有办法我可以这样写,以便在编译时不定义导出,这样用户就不必这样做?
【问题讨论】:
-
我最初的想法是,您会导出关闭由 INIT 移相器初始化的 %config 的潜艇?
-
任何时候你发现自己想要使用 repo 的文件路径来做某事都可能是错误的。
-
您考虑过
no precompilation移相器吗?这将使它在每次程序启动时重新编译,并且使用这个模块的其他模块可能也不会被预编译,但这个脚本应该运行得足够快,我认为 -
我不知道移相器的存在!
-
.oO (Pragmatically 说,我提到 timotimo 与
precompilation相关的小错误很可能phase 那些不明白我为什么要评论它的人,并让那些这样做的人为我糟糕的幽默感而呻吟,所以我想我最好还是给自己听)