summaryrefslogtreecommitdiff
path: root/eclass/perl-functions.eclass
diff options
context:
space:
mode:
Diffstat (limited to 'eclass/perl-functions.eclass')
-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 )' "$@"
+}
+