summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Fredric <kentnl@gentoo.org>2017-01-24 12:48:09 +1300
committerKent Fredric <kentnl@gentoo.org>2017-04-22 09:30:56 +1200
commit6841f6f95fdef73a52468e105a48ad15c5c4548e (patch)
tree3494a12e6130a3f37c08f3743cd13b4a7e866384
parentperl-functions.eclass: Add perl_has_module (diff)
downloadgentoo-6841f6f95fdef73a52468e105a48ad15c5c4548e.tar.gz
gentoo-6841f6f95fdef73a52468e105a48ad15c5c4548e.tar.bz2
gentoo-6841f6f95fdef73a52468e105a48ad15c5c4548e.zip
perl-functions.eclass: add perl_has_module_version
This is a utility for runtime checking if a module of a given version is installed from the perspective of Perl, whos opinion could be different than portage in the event of perl-core/* dual life effects shortly after a major Perl upgrade. Use this only if perl_has_module is insufficient, as the overheads and risk of side effects from this approach are high, given the module has to be actually loaded for the version comparison to happen. exits "true" if Perl has the given module installed at the given version ( or later ), exits "false" otherwise.
-rw-r--r--eclass/perl-functions.eclass33
1 files changed, 33 insertions, 0 deletions
diff --git a/eclass/perl-functions.eclass b/eclass/perl-functions.eclass
index 77e1ffca8067..de22f4757a44 100644
--- a/eclass/perl-functions.eclass
+++ b/eclass/perl-functions.eclass
@@ -346,3 +346,36 @@ perl_has_module() {
exit 1' "$@";
}
+# @FUNCTION: perl_has_module_version
+# @USAGE: perl_has_module_version "Test::Tester" "0.017"
+# @DESCRIPTION:
+# Query the installed system Perl to see if a given module is installed
+# and is at least a given version.
+#
+# This requires more caution to use than perl_has_module as it requires
+# loading the module in question to determine version compatibility,
+# which can be SLOW, and can have side effects (ie: compilation fails in
+# require due to some dependency, resulting in a "Fail")
+#
+# Also take care to note the module version is a *minimum*, *must* be
+# written in upstream versions format and should be a a legal upstream version
+#
+# returns a true exit code if the module is both available and is at least
+# the specified version
+
+perl_has_module_version() {
+ debug-print-function $FUNCNAME "$@"
+
+ [[ $# -gt 0 ]] || die "${FUNCNAME}: No module name provided"
+ [[ $# -gt 1 ]] || die "${FUNCNAME}: No module version provided"
+ [[ $# -lt 3 ]] || die "${FUNCNAME}: Too many parameters ($#)"
+
+ perl -we 'my $mn = $ARGV[0];
+ $mn =~ s{(::|\x{27})}{/}g;
+ exit ( eval {
+ require qq[${mn}.pm];
+ $ARGV[0]->VERSION($ARGV[1]);
+ 1
+ } ? 0 : 1 )' "$@"
+}
+