Determine whether a shared library is available to be loaded by Perl 6
use LibraryCheck;
if !library-exists('sndfile', v1) {
die "Cannot load sndfile";
}
This module provides a mechanism that will determine whether a named shared library is available and can be used by NativeCall.
It exports a single function 'library-exists' that returns a boolean to indicate whether the named shared library can be loaded and used.
This can be used in a builder to determine whether a module has a chance of working (and possibly aborting the build,) or in tests to cause the tests that may rely on a shared library to be skipped, but other use-cases are possible.
use LibraryCheck;
if !library-exists('sndfile', v1) {
die "Cannot load sndfile";
}
The case above can be more simply written as:
library-check('sndfile',v1, :exception);
Which will throw an X::NoLibrary
exception rather than return False.
The implementation is somewhat of a hack currently and definitely shouldn't be taken as an example of nice Perl 6 code.
Assuming you have a working Rakudo perl6 installation you should be able to install this with zef :
# From the source directory
zef install .
# Remote installation
zef install LibraryCheck
Other install mechanisms may be become available in the future.
Suggestions/patches are welcomed via github at https://github.com/jonathanstowe/LibraryCheck/issues
I'd be particularly interested in having it work properly on all the platforms that rakudo will work on.
Please see the LICENCEi file in the distribution
© Jonathan Stowe 2015, 2016, 2017