Skip to content

Commit d169f09

Browse files
committed
Use ExtUtils::MakeMaker::Locale
Use bundled local module to determine windows codepage instead.
1 parent 720fd7a commit d169f09

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

lib/ExtUtils/MakeMaker.pm

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,12 @@ sub prompt ($;$) { ## no critic
216216
print "$def\n";
217217
}
218218
else {
219-
my $codepage;
220-
if ($Is_Win32) {
221-
require Win32::Console;
222-
require Encode;
223-
$codepage = Win32::GetConsoleCP(); # get the input code page
224-
}
225219
$ans = <STDIN>;
226220
if( defined $ans ) {
227221
$ans =~ s{\015?\012$}{};
228-
if ($Is_Win32 and defined $codepage and length $codepage) {
229-
$ans = Encode::decode("cp". $codepage, $ans);
222+
if ($Is_Win32 and $CAN_DECODE) {
223+
my $codepage = $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN;
224+
$ans = Encode::decode($codepage, $ans);
230225
}
231226
}
232227
else { # user hit ctrl-D

t/prompt.t

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,16 @@ ok( !-t STDIN, 'STDIN not a tty' );
4444

4545
is( prompt("Foo?", 'Bar!'), 'From STDIN', 'from STDIN' );
4646
like( $stdout->read, qr/^Foo\? \[Bar!\]\s*$/, ' question' );
47+
48+
{
49+
my $CAN_DECODE = eval { require ExtUtils::MakeMaker::Locale; };
50+
SKIP: {
51+
skip 'Encode not available', 1 unless $CAN_DECODE;
52+
skip 'Not MSWin32', 1 unless $^O eq 'MSWin32';
53+
local $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN = "cp850";
54+
$ENV{PERL_MM_USE_DEFAULT} = 0;
55+
$stdin->write("\x{86}\x{91}"); # åæ in cp850
56+
is( prompt("Foo?", 'Bar!'), "\x{e5}\x{e6}",
57+
'read cp850 encoded letters from STDIN' );
58+
}
59+
}

0 commit comments

Comments
 (0)