Skip to content

Commit 0a8e67e

Browse files
committed
::Doc handle non-ASCII docs - #545
1 parent ce739c7 commit 0a8e67e

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

lib/PDL/Doc.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ use File::Basename;
457457
use File::Spec::Functions qw(file_name_is_absolute abs2rel rel2abs catdir catfile);
458458
use Cwd (); # to help Debian packaging
459459
use Config;
460+
use Encode;
460461
461462
our $pager = $ENV{PERLDOC_PAGER} // $ENV{PAGER} // $Config{pager};
462463
@@ -781,6 +782,7 @@ sub decodedb {
781782
while (read $fh, my $plen, 2) {
782783
my ($len) = unpack "v", $plen;
783784
read $fh, my($txt), $len;
785+
$txt = Encode::decode('UTF-8', $txt);
784786
my ($sym, $module, @a) = split chr(0), $txt;
785787
push @a, "" if @a % 2; # Add null string at end if necessary -- solves bug with missing REF section.
786788
$hash{$sym}{$module} = { @a, Dbfile => $filename }; # keep the origin pdldoc.db path
@@ -825,7 +827,7 @@ sub encodedb {
825827
#store paths to *.pm files relative to pdldoc.db
826828
if file_name_is_absolute($fi) && -f $fi;
827829
delete $val->{Dbfile}; # no need to store Dbfile
828-
my $txt = join(chr(0),$name,$module,map +($_=>$val->{$_}), sort keys %$val);
830+
my $txt = Encode::encode('UTF-8', join chr(0),$name,$module,map +($_=>$val->{$_}), sort keys %$val);
829831
print $fh pack("v",length($txt)).$txt;
830832
}
831833
}

lib/PDL/Doc/Perldl.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ sub finddoc {
245245
}
246246

247247
# print out the matches
248-
249248
open my $out, "| pod2text | $PDL::Doc::pager";
249+
binmode $out, ':encoding(UTF-8)';
250250

251251
if($subfield) {
252252
if($subfield <= @match) {

t/doc.t

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,42 @@ PDL::Doc::getfuncdocs('funcparen', $pod_fh, $func_fh);
218218
$func_text =~ s#\n+\z#\n#;
219219
is $func_text, $m_also_text;
220220

221+
my $canary_text = <<EOF;
222+
=encoding utf8
223+
224+
=head1 NAME
225+
226+
PDL::Trans - Trans stuff
227+
228+
=head1 FUNCTIONS
229+
230+
=head2 ctrsqrt
231+
232+
=for ref
233+
234+
Uses a recurrence of Bj\x{f6}rck and Hammarling.
235+
EOF
236+
my $canary_got = PDL::Doc::scantext(Encode::encode('UTF-8', $canary_text), 'Trans.pm');
237+
is_deeply $canary_got, {
238+
'PDL::Trans' => {
239+
'PDL::Trans' => {
240+
'File' => 'Trans.pm',
241+
'Ref' => 'Module: Trans stuff'
242+
}
243+
},
244+
'ctrsqrt' => {
245+
'PDL::Trans' => {
246+
'File' => 'Trans.pm',
247+
'Module' => 'PDL::Trans',
248+
'Ref' => "Uses a recurrence of Bj\x{f6}rck and Hammarling.",
249+
}
250+
}
251+
} or diag explain $canary_got;
252+
open $fh, '>', \$encoded_text;
253+
PDL::Doc::encodedb($canary_got, $fh, 'DIRNAME');
254+
open $fh, '<', \$encoded_text;
255+
$decode_hash = PDL::Doc::decodedb($fh, 'FILENAME');
256+
for my $val (values %$decode_hash) { delete $_->{Dbfile} for values %$val }
257+
is_deeply $decode_hash, $canary_got or diag explain $decode_hash;
258+
221259
done_testing;

0 commit comments

Comments
 (0)