Reputation: 2125
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
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