Subject: | survive when Encode cannot be loaded |
Hi Russ,
it would be nice if Pod::Man didn't bail out straight away if Encode can't be loaded, so that it could be still be used when the utf8 option is not set.
My use case is cross building the perl 5 distribution: the 'installman' phase (that uses Pod::Man without 'utf8') is currently the only one that requires Config.pm for the target perl, with a full perl that can load XS modules. This is an awkward combination; see http://www.nntp.perl.org/group/perl.perl5.porters/2013/01/msg197625.html for some background information.
Having 'installman' work without Encode would enable running it with miniperl (which is built without dynamic loading.)
The attached proposed patch defers loading Encode to the point where Encode::encode() is actually needed. YMMV; it might be useful to output a warning at load time rather than be silent up until a hard failure at runtime?
I'm aware that this would create some expectations of keeping basic things working in the future without XS modules, and you may be consider that somewhat limiting for development. I'd like to point out that Pod::Simple, currently the only real dependency of Pod::Man, also degrades gracefully when Encode doesn't work (although it looks like this is done mainly to support perls built without the Encode extension.) So this isn't quite unheard of.
Please let me know what you think, and thanks for your work as always.
--
Niko Tyni
ntyni@debian.org
Subject: | 0001-Amend-Pod-Man-to-work-with-miniperl-no-dynamic-loadi.patch |
From d052b97c98bea4d2cd8d745bca3e77892095f67c Mon Sep 17 00:00:00 2001
From: Niko Tyni <ntyni@debian.org>
Date: Mon, 11 Jan 2016 18:44:55 +0200
Subject: [PATCH] Amend Pod::Man to work with miniperl (no dynamic loading)
This is to allow cross-compilation builds of the Perl distribution to
run the 'installman' target using a host miniperl instead of the built
Perl binary.
See http://www.nntp.perl.org/group/perl.perl5.porters/2013/01/msg197625.html
for some context.
---
lib/Pod/Man.pm | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/Pod/Man.pm b/lib/Pod/Man.pm
index 24e49a0..7f09381 100644
--- a/lib/Pod/Man.pm
+++ b/lib/Pod/Man.pm
@@ -31,7 +31,6 @@ use subs qw(makespace);
use vars qw(@ISA %ESCAPES $PREAMBLE $VERSION);
use Carp qw(croak);
-use Encode qw(encode);
use Pod::Simple ();
@ISA = qw(Pod::Simple);
@@ -775,6 +774,10 @@ sub start_document {
if ($flag & PerlIO::F_UTF8 ()) {
$$self{ENCODE} = 0;
}
+ };
+ if ($$self{ENCODE}) {
+ eval { require Encode; Encode->import("encode"); 1; }
+ or croak "Encode::encode() needed but could not be loaded: $@"
}
}
--
2.6.4