[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gentoo-dev
Subject:    [gentoo-dev] [PATCH 2/6] perl-functions.eclass: add perl_has_module_version
From:       kentnl () gentoo ! org
Date:       2017-01-24 15:21:57
Message-ID: 20170124152201.15415-3-kentnl () gentoo ! org
[Download RAW message or body]

From: Kent Fredric <kentnl@gentoo.org>

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.
---
 eclass/perl-functions.eclass | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/eclass/perl-functions.eclass b/eclass/perl-functions.eclass
index 10d19e859d..c3a0e1ee30 100644
--- a/eclass/perl-functions.eclass
+++ b/eclass/perl-functions.eclass
@@ -347,3 +347,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 )' "$@"
+}
+
-- 
2.11.0


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic