summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Fredric <kentnl@gentoo.org>2016-08-03 15:17:54 +1200
committerKent Fredric <kentnl@gentoo.org>2017-04-22 09:30:52 +1200
commitc489d9313da67805cccbd50934861a31c792e42b (patch)
tree87cf518f5be22a52ebe5aec687a8ca1dd9554599 /eclass/perl-functions.eclass
parentdev-libs/libbson: version bump. (diff)
downloadgentoo-c489d9313da67805cccbd50934861a31c792e42b.tar.gz
gentoo-c489d9313da67805cccbd50934861a31c792e42b.tar.bz2
gentoo-c489d9313da67805cccbd50934861a31c792e42b.zip
perl-functions.eclass: Add perl_has_module
This is an incredibly fast way to check if Perl considers a module of the given name installed in any capacity, including broken. As long as "Foo.pm" is somewhere in @INC, `perl_has_module Foo` will return true. Even `perl_has_module threads` will return true on non-threaded perls, due to that module still being present, and the module only fataling when loaded. Whereas `perl_has_module_version threads 0` will always fail on non-threaded perls.
Diffstat (limited to 'eclass/perl-functions.eclass')
-rw-r--r--eclass/perl-functions.eclass28
1 files changed, 28 insertions, 0 deletions
diff --git a/eclass/perl-functions.eclass b/eclass/perl-functions.eclass
index 81dcc0066db..77e1ffca806 100644
--- a/eclass/perl-functions.eclass
+++ b/eclass/perl-functions.eclass
@@ -318,3 +318,31 @@ perl_doexamples() {
# is there a way to undo "docinto" ?
}
+
+# @FUNCTION: perl_has_module
+# @USAGE: perl_has_module "Test::Tester"
+# @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
+
+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' "$@";
+}
+