Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an installed module to recognize changes to config files

I have a package that uses config.json for some settings it uses. I keep the package locally rather than installing it from CPAN. My problem is when I make changes to config.json, the package doesn't recognize the changes since the config file's cached elsewhere, forcing me to run zef install --force-install or delete precomp. How can I ensure that the package always recognizes updates to the config file?

like image 845
Kaiepi Avatar asked Apr 23 '18 21:04

Kaiepi


1 Answers

When you install packages using zef, it keeps them in the filesystem, but their names are converted into sha1, something like

/home/jmerelo/.rakudobrew/moar-2018.03/install/share/perl6/site/sources/81436475BD18D66BFD96BBCEE07CCCDC0F368879

zef keeps track of them, however, and you can locate them using zef locate, for instance:

zef locate lib/Zef/CLI.pm6

You can run that from a program, for instance this way:

sub MAIN( Str $file ) {
    my $location = qqx/zef locate $file/;
    my $sha1 = ($location ~~ /\s+ \=\> \s+ (.+)/);
    say "$file → $sha1[0]";
}

which will return pretty much the same, except it will give you the first location of the file you give it at the command line:

lib/Zef/CLI.pm6 → /home/jmerelo/.rakudobrew/moar-2018.03/install/share/perl6/site/sources/81436475BD18D66BFD96BBCEE07CCCDC0F368879

You probably need to install your config.json file in a resources directory (which is the preferred location) and then use something like that.

That said, probably actually installing a module you're testing is not the best strategy. If you're still testing things, it's probably better if you just keep it in the directory you're working with and use perl6 -I<that directory> or else use lib <that directory> is probably a better option. You can just delete that when you release, or keep it, since that only adds another directory to the search path and will not harm the released module.

like image 69
jjmerelo Avatar answered Oct 18 '22 21:10

jjmerelo