Skip to content

Commit 819d1cd

Browse files
committed
uses =encoding line to get the encoding of a document
1 parent ec8ecff commit 819d1cd

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

lib/Pod/Perldoc.pm

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use File::Spec::Functions qw(catfile catdir splitdir);
1212
use vars qw($VERSION @Pagers $Bindir $Pod2man
1313
$Temp_Files_Created $Temp_File_Lifetime
1414
);
15-
$VERSION = '3.24';
15+
$VERSION = '3.24'; # ++
1616

1717
#..........................................................................
1818

@@ -1043,7 +1043,11 @@ sub search_perlvar {
10431043
open(PVAR, "<", $perlvar) # "Funk is its own reward"
10441044
or $self->die("Can't open $perlvar: $!");
10451045

1046-
binmode(PVAR, ":encoding(UTF-8)");
1046+
my $binmode = $] < 5.008; # to do not call binmode()
1047+
if ( $binmode ) {
1048+
$self->aside("Your old perl doesn't really have proper unicode support.");
1049+
}
1050+
10471051
if ( $opt ne '$0' && $opt =~ /^\$\d+$/ ) { # handle $1, $2, ...
10481052
$opt = '$<I<digits>>';
10491053
}
@@ -1055,6 +1059,8 @@ sub search_perlvar {
10551059
# Skip introduction
10561060
local $_;
10571061
while (<PVAR>) {
1062+
# checks =encoding in some lines from the beginning.
1063+
$binmode ||= /^=encoding\s+(\S+)/ && binmode(PVAR, ":encoding($1)");
10581064
last if /^=over 8/;
10591065
}
10601066
@@ -1112,8 +1118,12 @@ sub search_perlop {
11121118
# XXX FIXME: getting filehandles should probably be done in a single place
11131119
# especially since we need to support UTF8 or other encoding when dealing
11141120
# with perlop, perlfunc, perlapi, perlfaq[1-9]
1121+
11151122
open( PERLOP, '<', $perlop ) or $self->die( "Can't open $perlop: $!" );
1116-
binmode(PERLOP, ":encoding(UTF-8)");
1123+
my $binmode = $] < 5.008;
1124+
if ( $binmode ) {
1125+
$self->aside("Your old perl doesn't really have proper unicode support.");
1126+
}
11171127

11181128
my $thing = $self->opt_f;
11191129

@@ -1123,6 +1133,7 @@ sub search_perlop {
11231133
my $skip = 1;
11241134

11251135
while( my $line = <PERLOP> ) {
1136+
$binmode ||= $line =~ /^=encoding\s+(\S+)/ && binmode(PERLOP, ":encoding($1)");
11261137
# only start search after we hit the operator section
11271138
if ($line =~ m!^X<operator, regexp>!) {
11281139
$skip = 0;
@@ -1198,14 +1209,12 @@ sub search_perlapi {
11981209
print "Going to perlapi-scan for $search_re in $perlapi\n";
11991210

12001211
# Check available translator or backup to default (english)
1212+
my $binmode = $] < 5.008;
12011213
if ( $self->opt_L && defined $self->{'translators'}->[0] ) {
12021214
my $tr = $self->{'translators'}->[0];
1203-
if ( $] < 5.008 ) {
1215+
if ( $binmode ) {
12041216
$self->aside("Your old perl doesn't really have proper unicode support.");
12051217
}
1206-
else {
1207-
binmode(PAPI, ":encoding(UTF-8)");
1208-
}
12091218
}
12101219

12111220
local $_;
@@ -1217,6 +1226,7 @@ sub search_perlapi {
12171226
my @related;
12181227
my $related_re;
12191228
while (<PAPI>) { # "The Mothership Connection is here!"
1229+
$binmode ||= /^=encoding\s+(\S+)/ && binmode(PAPI, ":encoding($1)");
12201230
if ( m/^=item\s+$search_re\b/ ) {
12211231
$found = 1;
12221232
}
@@ -1279,20 +1289,19 @@ sub search_perlfunc {
12791289
my $re = 'Alphabetical Listing of Perl Functions';
12801290

12811291
# Check available translator or backup to default (english)
1292+
my $binmode = $] < 5.008;
12821293
if ( $self->opt_L && defined $self->{'translators'}->[0] ) {
12831294
my $tr = $self->{'translators'}->[0];
12841295
$re = $tr->search_perlfunc_re if $tr->can('search_perlfunc_re');
1285-
if ( $] < 5.008 ) {
1296+
if ( $binmode ) {
12861297
$self->aside("Your old perl doesn't really have proper unicode support.");
12871298
}
1288-
else {
1289-
binmode(PFUNC, ":encoding(UTF-8)");
1290-
}
12911299
}
12921300

12931301
# Skip introduction
12941302
local $_;
12951303
while (<PFUNC>) {
1304+
$binmode ||= /^=encoding\s+(\S+)/ && binmode(PFUNC, ":encoding($1)");
12961305
last if /^=head2 $re/;
12971306
}
12981307
@@ -1381,8 +1390,14 @@ EOD
13811390
$self->die( "invalid file spec: $!" ) if $file =~ /[<>|]/;
13821391
open(INFAQ, "<", $file) # XXX 5.6ism
13831392
or $self->die( "Can't read-open $file: $!\nAborting" );
1384-
binmode(INFAQ, ":encoding(UTF-8)");
1393+
1394+
my $binmode = $] < 5.008;
1395+
if ( $binmode ) {
1396+
$self->aside("Your old perl doesn't really have proper unicode support.");
1397+
}
1398+
13851399
while (<INFAQ>) {
1400+
$binmode ||= /^=encoding\s+(\S+)/ && binmode(INFAQ, ":encoding($1)");
13861401
if ( m/^=head2\s+.*(?:$search_key)/i ) {
13871402
$found = 1;
13881403
push @$pod, "=head1 Found in $file\n\n" unless $found_in{$file}++;

0 commit comments

Comments
 (0)