Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Raku - How can a program verify if a module is installed locally

How would I discover whether a Raku module has been installed locally? If some module is not installed, eg. a GUI, then a CLI would be used. Eg.

if is-installed('GTK::Simple') { gui-response } else { cli-response };

What should be the body of 'is-installed'?

like image 555
Richard Hainsworth Avatar asked Aug 10 '20 10:08

Richard Hainsworth


1 Answers

Here's one option:

sub is-installed(Str $module-name) {
    try {
        require ::($module-name);
        return True;
    }
    False;
}

Check the documentation for require for more background information.

like image 117
moritz Avatar answered Sep 28 '22 08:09

moritz