diff options
author | Kent Fredric <kentnl@gentoo.org> | 2017-09-15 17:37:02 +1200 |
---|---|---|
committer | Kent Fredric <kentnl@gentoo.org> | 2017-09-17 12:06:57 +1200 |
commit | 3984850ad5395ea37d38b4a8abc083a856549f3f (patch) | |
tree | 0225d2097e66bfc6894784d7db8f1e253d2d443e /eclass | |
parent | perl-functions.eclass: sync perl_check_env from ::gentoo (diff) | |
download | perl-overlay-3984850ad5395ea37d38b4a8abc083a856549f3f.tar.gz perl-overlay-3984850ad5395ea37d38b4a8abc083a856549f3f.tar.bz2 perl-overlay-3984850ad5395ea37d38b4a8abc083a856549f3f.zip |
perl-functions.eclass: Add perl_has_module
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/perl-functions.eclass | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/eclass/perl-functions.eclass b/eclass/perl-functions.eclass index 342bf276a..b1b408e73 100644 --- a/eclass/perl-functions.eclass +++ b/eclass/perl-functions.eclass @@ -433,3 +433,36 @@ perl_doexamples() { # is there a way to undo "docinto" ? } + +# @FUNCTION: perl_has_module +# @USAGE: <module name> +# @RETURN: 0 if available, non-zero otherwise +# @DESCRIPTION: +# Query the installed system Perl to see if a given module is installed. +# This does **not** load the module in question, only anticipates if it *might* load. +# +# This is primarily for the purposes of dependency weakening so that conditional +# behaviour can be triggered without adding dependencies to portage which would confuse +# a dependency resolver. +# +# returns 'true' if the module is available, returns error if the module is not available +# +# Example: +# @CODE +# perl_has_module "Test::Tester" && echo "Test::Tester installed" +# @CODE + +perl_has_module() { + debug-print-function $FUNCNAME "$@" + + [[ $# -gt 0 ]] || die "${FUNCNAME}: No module name provided" + [[ $# -lt 2 ]] || die "${FUNCNAME}: Too many parameters ($#)" + + perl -we 'my $mn = $ARGV[0]; + $mn =~ s{(::|\x{27})}{/}g; + for(@INC){ + next if ref $_; + exit 0 if -r $_ . q[/] . $mn . q[.pm] + } + exit 1' "$@"; +} |