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

Viewed 126

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'?

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.

Related