aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorRichard Levitte <richard@levitte.org>2016-01-22 12:37:31 +0100
committerRichard Levitte <richard@levitte.org>2016-01-22 23:12:22 +0100
commit35c3a562c74aba6e3ac3d577a356b314a151740e (patch)
treec472677d451d8ac4de3fc8ae5f7db04dc224dd2f /util
parent291e94df90aa085ae53b43e52e1cef02efc0ff10 (diff)
downloadopenssl-35c3a562c74aba6e3ac3d577a356b314a151740e.tar.gz
Refactor file writing - arrange for use of bundled Perl modules as fallback
For our own convenience, we need a mechanism to be able to fall back on bundled Perl modules. It's a minimal package that's called like this: use with_fallback qw(Module1 Module2 ...); For each module, it will try to require them from the system installation, and failing that, it will temporarly add external/perl and try to require transfer::{ModuleName}. It requires that each bundled Perl modules is accompanied by a small transfer module (external/perl/transfer/ModuleName.pm in our example) that knows exactly what to load. Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'util')
-rw-r--r--util/with_fallback.pm19
1 files changed, 19 insertions, 0 deletions
diff --git a/util/with_fallback.pm b/util/with_fallback.pm
new file mode 100644
index 0000000000..014f355156
--- /dev/null
+++ b/util/with_fallback.pm
@@ -0,0 +1,19 @@
+#! /usr/bin/perl
+
+package with_fallback;
+
+sub import {
+ use File::Basename;
+ use File::Spec::Functions;
+ foreach (@_) {
+ eval "require $_";
+ if ($@) {
+ unshift @INC, catdir(dirname(__FILE__), "..", "external", "perl");
+ my $transfer = "transfer::$_";
+ eval "require $transfer";
+ shift @INC;
+ warn $@ if $@;
+ }
+ }
+}
+1;