diff options
author | Tony Cook <tony@develop-help.com> | 2015-05-13 10:28:22 +1000 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2015-05-15 11:47:23 +1000 |
commit | 18fe62667c7b9e1cc19201a7075e74e31b6ae16b (patch) | |
tree | d5bd556c723d5e349837ae083fefe04ac504531e /cpan/ExtUtils-MakeMaker/lib | |
parent | 30aa8e3f58555e9f59c77b031038678310f01473 (diff) | |
download | perl-18fe62667c7b9e1cc19201a7075e74e31b6ae16b.tar.gz |
backport 1e2f0871 from the EUMM repository
Diffstat (limited to 'cpan/ExtUtils-MakeMaker/lib')
-rw-r--r-- | cpan/ExtUtils-MakeMaker/lib/ExtUtils/MakeMaker/Locale.pm | 72 |
1 files changed, 50 insertions, 22 deletions
diff --git a/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MakeMaker/Locale.pm b/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MakeMaker/Locale.pm index f6edcf2d1f..23d0c6ecfe 100644 --- a/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MakeMaker/Locale.pm +++ b/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MakeMaker/Locale.pm @@ -1,7 +1,7 @@ package ExtUtils::MakeMaker::Locale; use strict; -our $VERSION = "7.04"; +our $VERSION = "7.04_01"; use base 'Exporter'; our @EXPORT_OK = qw( @@ -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; } } @@ -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: @@ -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". @@ -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 |