X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Debbugs%2FCommon.pm;h=cf53b07e0e35344c35823496315585cd958df8ca;hb=e26e4c2c8243d3e6f9f461f5b59e4abb3b761f84;hp=279893c135bb98a4fda11d8dbd652cb2ffc64e10;hpb=9dd18b2a38fae81a660504da29147937596ba206;p=debbugs.git diff --git a/Debbugs/Common.pm b/Debbugs/Common.pm index 279893c..cf53b07 100644 --- a/Debbugs/Common.pm +++ b/Debbugs/Common.pm @@ -75,6 +75,7 @@ use Storable qw(dclone); use Params::Validate qw(validate_with :types); use Fcntl qw(:DEFAULT :flock); +use Encode qw(is_utf8 decode_utf8); our $DEBUG_FH = \*STDERR if not defined $DEBUG_FH; @@ -816,6 +817,10 @@ Will carp if given a scalar which isn't a scalarref or a glob (or globref), and return /dev/null. May return undef if IO::Scalar or IO::File fails. (Check $!) +The scalar will fill with octets, not perl's internal encoding, so you +must use decode_utf8() after on the scalar, and encode_utf8() on it +before. This appears to be a bug in the underlying modules. + =cut sub globify_scalar { @@ -825,6 +830,10 @@ sub globify_scalar { if (defined ref($scalar)) { if (ref($scalar) eq 'SCALAR' and not UNIVERSAL::isa($scalar,'GLOB')) { + if (is_utf8(${$scalar})) { + ${$scalar} = decode_utf8(${$scalar}); + carp(q(\$scalar must not be in perl's internal encoding)); + } open $handle, '>:scalar:utf8', $scalar; return $handle; } @@ -839,7 +848,7 @@ sub globify_scalar { carp "Given a non-scalar reference, non-glob to globify_scalar; returning /dev/null handle"; } } - return IO::File->new('/dev/null','>:utf8'); + return IO::File->new('/dev/null','>:encoding(UTF-8)'); } =head2 cleanup_eval_fail()