Skip to content

Commit

Permalink
Update bundled Encode::Locale to CPAN 1.04
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Jan 18, 2015
1 parent 170beb6 commit 1e2f087
Showing 1 changed file with 49 additions and 21 deletions.
70 changes: 49 additions & 21 deletions lib/ExtUtils/MakeMaker/Locale.pm
Expand Up @@ -25,31 +25,60 @@ sub _init {
unless ($ENCODING_LOCALE) {
# Try to obtain what the Windows ANSI code page is
eval {
unless (defined &GetACP) {
unless (defined &GetConsoleCP) {
require Win32;
# no point falling back to Win32::GetConsoleCP from this
# as added same time, 0.45
eval { Win32::GetConsoleCP() };
# manually "import" it since Win32->import refuses
*GetConsoleCP = sub { &Win32::GetConsoleCP } unless $@;
}
unless (defined &GetConsoleCP) {
require Win32::API;
Win32::API->Import('kernel32', 'int GetACP()');
};
if (defined &GetACP) {
my $cp = GetACP();
Win32::API->Import('kernel32', 'int GetConsoleCP()');
}
if (defined &GetConsoleCP) {
my $cp = GetConsoleCP();
$ENCODING_LOCALE = "cp$cp" if $cp;
}
};
}

unless ($ENCODING_CONSOLE_IN) {
# If we have the Win32::Console module installed we can ask
# it for the code set to use
eval {
require Win32::Console;
my $cp = Win32::Console::InputCP();
$ENCODING_CONSOLE_IN = "cp$cp" if $cp;
$cp = Win32::Console::OutputCP();
$ENCODING_CONSOLE_OUT = "cp$cp" if $cp;
};
# Invoking the 'chcp' program might also work
if (!$ENCODING_CONSOLE_IN && (qx(chcp) || '') =~ /^Active code page: (\d+)/) {
$ENCODING_CONSOLE_IN = "cp$1";
# only test one since set together
unless (defined &GetInputCP) {
eval {
require Win32;
eval { Win32::GetConsoleCP() };
# manually "import" it since Win32->import refuses
*GetInputCP = sub { &Win32::GetConsoleCP } unless $@;
*GetOutputCP = sub { &Win32::GetConsoleOutputCP } unless $@;
};
unless (defined &GetInputCP) {
eval {
# try Win32::Console module for codepage to use
require Win32::Console;
eval { Win32::Console::InputCP() };
*GetInputCP = sub { &Win32::Console::InputCP }
unless $@;
*GetOutputCP = sub { &Win32::Console::OutputCP }
unless $@;
};
}
unless (defined &GetInputCP) {
# final fallback
*GetInputCP = *GetOutputCP = sub {
# another fallback that could work is:
# reg query HKLM\System\CurrentControlSet\Control\Nls\CodePage /v ACP
((qx(chcp) || '') =~ /^Active code page: (\d+)/)
? $1 : ();
};
}
}
my $cp = GetInputCP();
$ENCODING_CONSOLE_IN = "cp$cp" if $cp;
$cp = GetOutputCP();
$ENCODING_CONSOLE_OUT = "cp$cp" if $cp;
}
}

Expand Down Expand Up @@ -206,8 +235,7 @@ C<Encode::Locale> will do that if available and make these encodings known
under the C<Encode> aliases "console_in" and "console_out". For systems where
we can't determine the terminal encoding these will be aliased as the same
encoding as "locale". The advice is to use "console_in" for input known to
come from the terminal and "console_out" for output known to go from the
terminal.
come from the terminal and "console_out" for output to the terminal.
In addition to arranging for various Encode aliases the following functions and
variables are provided:
Expand Down Expand Up @@ -266,7 +294,7 @@ L<Encode> know this encoding as "locale".
=item $ENCODING_LOCALE_FS
The encoding name determined to be suiteable for file system interfaces
The encoding name determined to be suitable for file system interfaces
involving file names.
L<Encode> know this encoding as "locale_fs".
Expand Down Expand Up @@ -336,7 +364,7 @@ Users are advised to always specify UTF-8 as the locale charset.
=head1 SEE ALSO
L<I18N::Langinfo>, L<Encode>
L<I18N::Langinfo>, L<Encode>, L<Term::Encoding>
=head1 AUTHOR
Expand Down

0 comments on commit 1e2f087

Please sign in to comment.