Richard Hainsworth
Richard Hainsworth

Reputation: 2125

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

Upvotes: 6

Views: 156

Answers (1)

moritz
moritz

Reputation: 12842

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.

Upvotes: 4

Related Questions