1 |
From: Kent Fredric <kentnl@g.o> |
2 |
|
3 |
This is a utility for runtime checking if a module of a given version |
4 |
is installed from the perspective of Perl, whos opinion could be |
5 |
different than portage in the event of perl-core/* dual life effects |
6 |
shortly after a major Perl upgrade. |
7 |
|
8 |
Use this only if perl_has_module is insufficient, as the overheads |
9 |
and risk of side effects from this approach are high, given the module |
10 |
has to be actually loaded for the version comparison to happen. |
11 |
|
12 |
exits "true" if Perl has the given module installed at the given |
13 |
version ( or later ), exits "false" otherwise. |
14 |
--- |
15 |
eclass/perl-functions.eclass | 33 +++++++++++++++++++++++++++++++++ |
16 |
1 file changed, 33 insertions(+) |
17 |
|
18 |
diff --git a/eclass/perl-functions.eclass b/eclass/perl-functions.eclass |
19 |
index 10d19e859d..c3a0e1ee30 100644 |
20 |
--- a/eclass/perl-functions.eclass |
21 |
+++ b/eclass/perl-functions.eclass |
22 |
@@ -347,3 +347,36 @@ perl_has_module() { |
23 |
exit 1' "$@"; |
24 |
} |
25 |
|
26 |
+# @FUNCTION: perl_has_module_version |
27 |
+# @USAGE: perl_has_module_version "Test::Tester" "0.017" |
28 |
+# @DESCRIPTION: |
29 |
+# Query the installed system Perl to see if a given module is installed |
30 |
+# and is at least a given version. |
31 |
+# |
32 |
+# This requires more caution to use than perl_has_module as it requires |
33 |
+# loading the module in question to determine version compatibility, |
34 |
+# which can be SLOW, and can have side effects (ie: compilation fails in |
35 |
+# require due to some dependency, resulting in a "Fail") |
36 |
+# |
37 |
+# Also take care to note the module version is a *minimum*, *must* be |
38 |
+# written in upstream versions format and should be a a legal upstream version |
39 |
+# |
40 |
+# returns a true exit code if the module is both available and is at least |
41 |
+# the specified version |
42 |
+ |
43 |
+perl_has_module_version() { |
44 |
+ debug-print-function $FUNCNAME "$@" |
45 |
+ |
46 |
+ [[ $# -gt 0 ]] || die "${FUNCNAME}: No module name provided" |
47 |
+ [[ $# -gt 1 ]] || die "${FUNCNAME}: No module version provided" |
48 |
+ [[ $# -lt 3 ]] || die "${FUNCNAME}: Too many parameters ($#)" |
49 |
+ |
50 |
+ perl -we 'my $mn = $ARGV[0]; |
51 |
+ $mn =~ s{(::|\x{27})}{/}g; |
52 |
+ exit ( eval { |
53 |
+ require qq[${mn}.pm]; |
54 |
+ $ARGV[0]->VERSION($ARGV[1]); |
55 |
+ 1 |
56 |
+ } ? 0 : 1 )' "$@" |
57 |
+} |
58 |
+ |
59 |
-- |
60 |
2.11.0 |