Codebase list libencode-locale-perl / f1fad76
Merge tag 'upstream/1.05' Upstream version 1.05 Florian Schlichting 8 years ago
11 changed file(s) with 274 addition(s) and 76 deletion(s). Raw diff Collapse all Expand all
0 ## 2015-06-09 Release 1.05
1
2 Mats Peterson (1):
3 Use GetACP() to get the ANSI code page like before
4
5 Thomas Sibley (1):
6 Conditionalize the Win32::Console recommendation
7
8
9
10 ## 2015-01-12 Release 1.04
11
12 Ed J (5):
13
14 * Actually include all the tests in the MANIFEST
15 * use Test::More and warnings
16 * Tidy t/alias.t
17 * t/arg.t TODO some actual ARGV testing
18 * Use Win32::GetConsoleCP/GetConsoleOutputCP if available
19
20 Gisle Aas (3):
21
22 * Documentation spell fix
23 * SEE ALSO Term::Encoding [RT#98138]
24
25 David Steinbrunner (1):
26
27 * typo fix
28
29
30
031 ## 2012-01-11 Release 1.03
132
233 Documentation spelling fixes and tweaks to improve testing on Windows.
22 Makefile.PL
33 MANIFEST This list of files
44 README
5 t/alias.t
56 t/arg.t
67 t/env.t
7 META.yml Module meta-data (added by MakeMaker)
8 t/tain.t
9 t/warn_once.t
10 META.yml Module YAML meta-data (added by MakeMaker)
11 META.json Module JSON meta-data (added by MakeMaker)
0 {
1 "abstract" : "Determine the locale encoding",
2 "author" : [
3 "Gisle Aas <gisle@activestate.com>"
4 ],
5 "dynamic_config" : 1,
6 "generated_by" : "ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150001",
7 "license" : [
8 "perl_5"
9 ],
10 "meta-spec" : {
11 "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
12 "version" : "2"
13 },
14 "name" : "Encode-Locale",
15 "no_index" : {
16 "directory" : [
17 "t",
18 "inc"
19 ]
20 },
21 "prereqs" : {
22 "build" : {
23 "requires" : {
24 "ExtUtils::MakeMaker" : "0",
25 "Test::More" : "0"
26 }
27 },
28 "configure" : {
29 "requires" : {
30 "ExtUtils::MakeMaker" : "0"
31 }
32 },
33 "runtime" : {
34 "recommends" : {
35 "I18N::Langinfo" : "0"
36 },
37 "requires" : {
38 "Encode" : "2",
39 "Encode::Alias" : "0",
40 "perl" : "5.008"
41 }
42 }
43 },
44 "release_status" : "stable",
45 "resources" : {
46 "repository" : {
47 "url" : "http://github.com/gisle/encode-locale"
48 }
49 },
50 "version" : "1.05"
51 }
0 --- #YAML:1.0
1 name: Encode-Locale
2 version: 1.03
3 abstract: Determine the locale encoding
0 ---
1 abstract: 'Determine the locale encoding'
42 author:
5 - Gisle Aas <gisle@activestate.com>
6 license: perl
7 distribution_type: module
3 - 'Gisle Aas <gisle@activestate.com>'
4 build_requires:
5 ExtUtils::MakeMaker: '0'
6 Test::More: '0'
87 configure_requires:
9 ExtUtils::MakeMaker: 0
10 build_requires:
11 Test: 0
8 ExtUtils::MakeMaker: '0'
9 dynamic_config: 1
10 generated_by: 'ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150001'
11 license: perl
12 meta-spec:
13 url: http://module-build.sourceforge.net/META-spec-v1.4.html
14 version: '1.4'
15 name: Encode-Locale
16 no_index:
17 directory:
18 - t
19 - inc
20 recommends:
21 I18N::Langinfo: '0'
1222 requires:
13 Encode: 2
14 Encode::Alias: 0
15 perl: 5.008
23 Encode: '2'
24 Encode::Alias: '0'
25 perl: '5.008'
1626 resources:
17 repository: http://github.com/gisle/encode-locale
18 no_index:
19 directory:
20 - t
21 - inc
22 generated_by: ExtUtils::MakeMaker version 6.57_05
23 meta-spec:
24 url: http://module-build.sourceforge.net/META-spec-v1.4.html
25 version: 1.4
26 recommends:
27 I18N::Langinfo: 0
28 Win32::Console: 0
27 repository: http://github.com/gisle/encode-locale
28 version: '1.05'
1717 },
1818 recommends => {
1919 'I18N::Langinfo' => 0,
20 'Win32::Console' => 0,
20 ($^O eq 'MSWin32'
21 ? ('Win32::Console' => 0)
22 : ()),
2123 },
2224 },
23 BUILD_REQUIRES => {
24 Test => 0,
25 TEST_REQUIRES => {
26 'Test::More' => 0,
2527 },
2628 );
2729
3436 META_ADD => 6.45,
3537 MIN_PERL_VERSION => 6.48,
3638 BUILD_REQUIRES => 6.56,
39 TEST_REQUIRES => 6.64,
3740 );
3841 undef(*WriteMakefile);
3942 *WriteMakefile = sub {
4043 my %arg = @_;
44 unless (eval { ExtUtils::MakeMaker->VERSION($mm_req{TEST_REQUIRES}) }) {
45 warn "Downgrading TEST_REQUIRES" if $developer;
46 $arg{BUILD_REQUIRES} = {
47 %{ $arg{BUILD_REQUIRES} },
48 %{ delete $arg{TEST_REQUIRES} },
49 };
50 }
4151 for (keys %mm_req) {
4252 unless (eval { ExtUtils::MakeMaker->VERSION($mm_req{$_}) }) {
4353 warn "$_ $@" if $developer;
00 package Encode::Locale;
11
22 use strict;
3 our $VERSION = "1.03";
3 our $VERSION = "1.05";
44
55 use base 'Exporter';
66 our @EXPORT_OK = qw(
2525 # Try to obtain what the Windows ANSI code page is
2626 eval {
2727 unless (defined &GetACP) {
28 require Win32;
29 eval { Win32::GetACP() };
30 *GetACP = sub { &Win32::GetACP } unless $@;
31 }
32 unless (defined &GetACP) {
2833 require Win32::API;
2934 Win32::API->Import('kernel32', 'int GetACP()');
30 };
35 }
3136 if (defined &GetACP) {
3237 my $cp = GetACP();
3338 $ENCODING_LOCALE = "cp$cp" if $cp;
3641 }
3742
3843 unless ($ENCODING_CONSOLE_IN) {
39 # If we have the Win32::Console module installed we can ask
40 # it for the code set to use
41 eval {
42 require Win32::Console;
43 my $cp = Win32::Console::InputCP();
44 $ENCODING_CONSOLE_IN = "cp$cp" if $cp;
45 $cp = Win32::Console::OutputCP();
46 $ENCODING_CONSOLE_OUT = "cp$cp" if $cp;
47 };
48 # Invoking the 'chcp' program might also work
49 if (!$ENCODING_CONSOLE_IN && (qx(chcp) || '') =~ /^Active code page: (\d+)/) {
50 $ENCODING_CONSOLE_IN = "cp$1";
44 # only test one since set together
45 unless (defined &GetInputCP) {
46 eval {
47 require Win32;
48 eval { Win32::GetConsoleCP() };
49 # manually "import" it since Win32->import refuses
50 *GetInputCP = sub { &Win32::GetConsoleCP } unless $@;
51 *GetOutputCP = sub { &Win32::GetConsoleOutputCP } unless $@;
52 };
53 unless (defined &GetInputCP) {
54 eval {
55 # try Win32::Console module for codepage to use
56 require Win32::Console;
57 eval { Win32::Console::InputCP() };
58 *GetInputCP = sub { &Win32::Console::InputCP }
59 unless $@;
60 *GetOutputCP = sub { &Win32::Console::OutputCP }
61 unless $@;
62 };
63 }
64 unless (defined &GetInputCP) {
65 # final fallback
66 *GetInputCP = *GetOutputCP = sub {
67 # another fallback that could work is:
68 # reg query HKLM\System\CurrentControlSet\Control\Nls\CodePage /v ACP
69 ((qx(chcp) || '') =~ /^Active code page: (\d+)/)
70 ? $1 : ();
71 };
72 }
5173 }
74 my $cp = GetInputCP();
75 $ENCODING_CONSOLE_IN = "cp$cp" if $cp;
76 $cp = GetOutputCP();
77 $ENCODING_CONSOLE_OUT = "cp$cp" if $cp;
5278 }
5379 }
5480
205231 under the C<Encode> aliases "console_in" and "console_out". For systems where
206232 we can't determine the terminal encoding these will be aliased as the same
207233 encoding as "locale". The advice is to use "console_in" for input known to
208 come from the terminal and "console_out" for output known to go from the
209 terminal.
234 come from the terminal and "console_out" for output to the terminal.
210235
211236 In addition to arranging for various Encode aliases the following functions and
212237 variables are provided:
265290
266291 =item $ENCODING_LOCALE_FS
267292
268 The encoding name determined to be suiteable for file system interfaces
293 The encoding name determined to be suitable for file system interfaces
269294 involving file names.
270295 L<Encode> know this encoding as "locale_fs".
271296
335360
336361 =head1 SEE ALSO
337362
338 L<I18N::Langinfo>, L<Encode>
363 L<I18N::Langinfo>, L<Encode>, L<Term::Encoding>
339364
340365 =head1 AUTHOR
341366
0 #!perl -w
1
2 use strict;
3 use warnings;
4 use Test::More tests => 8;
5
6 use Encode::Locale;
7 use Encode qw(find_encoding);
8
9 sub cmp_encoding {
10 my ($arg, $var) = @_;
11 my $lcarg = lc $arg;
12 is find_encoding($lcarg), find_encoding(${ $Encode::Locale::{$var} }),
13 "$lcarg eq $var";
14 is find_encoding($arg), find_encoding(${ $Encode::Locale::{$var} }),
15 "$arg eq $var";
16 }
17
18 cmp_encoding 'Locale', 'ENCODING_LOCALE';
19 cmp_encoding 'Locale_FS', 'ENCODING_LOCALE_FS';
20 cmp_encoding 'Console_IN', 'ENCODING_CONSOLE_IN';
21 cmp_encoding 'Console_OUT', 'ENCODING_CONSOLE_OUT';
00 #!perl -w
11
22 use strict;
3 use Test;
4 plan tests => 1;
3 use warnings;
4 use Test::More;
55
66 use Encode::Locale qw($ENCODING_LOCALE decode_argv);
7 use Encode;
8 use utf8;
79
8 print "# ENCODING_LOCALE is $ENCODING_LOCALE\n";
10 diag "ENCODING_LOCALE is $ENCODING_LOCALE\n";
11 my @chars = qw(funny chars š ™);
12 my @octets = map { Encode::encode(locale => $_) } @chars;
13 @ARGV = @octets;
14
15 plan tests => scalar(@ARGV);
16
917 decode_argv();
1018
11 my $i;
12 for my $arg (@ARGV) {
13 print "# ", ++$i, ": \"";
14 for (split(//, $arg)) {
19 TODO: {
20 local $TODO = "ARGV decoding";
21 for (my $i = 0; $i < @ARGV; $i++) {
22 is $chars[$i], $ARGV[$i],
23 "chars(" . prettify($chars[$i]) .
24 ") octets(" . prettify($octets[$i]) .
25 ") argv(" . prettify($ARGV[$i]) . ")";
26 }
27 }
28
29 sub prettify {
30 my $text = shift;
31 my @r;
32 for (split(//, $text)) {
1533 if (ord() > 32 && ord() < 128) {
16 print $_;
34 push @r, $_;
1735 }
1836 elsif (ord() < 256) {
19 printf "\\x%02X", ord();
37 push @r, sprintf "\\x%02X", ord();
2038 }
2139 else {
22 printf "\\x{%04X}", ord();
40 push @r, sprintf "\\x{%04X}", ord();
2341 }
2442 }
25 print "\"\n";
43 join '', @r;
2644 }
27
28 # fake it :-)
29 ok(1);
00 #!perl -w
11
22 use strict;
3 use Test;
4 plan tests => 13;
3 use warnings;
4 use Test::More tests => 13;
55
66 use Encode::Locale qw(env);
77
88 $ENV{foo} = "bar";
9 ok(env("foo"), "bar");
10 ok(env("foo", "baz"), "bar");
11 ok(env("foo"), "baz");
12 ok($ENV{foo}, "baz");
13 ok(env("foo", undef), "baz");
14 ok(env("foo"), undef);
15 ok(!exists $ENV{foo});
9 is env("foo"), "bar", 'env read';
10 is env("foo", "baz"), "bar", 'env write retval old value';
11 is env("foo"), "baz", 'env write worked';
12 is $ENV{foo}, "baz", 'env affected %ENV';
13 is env("foo", undef), "baz", 'env write retval old value';
14 is env("foo"), undef, 'env write worked';
15 ok !exists $ENV{foo}, 'env write undef deletes from %ENV';
1616
1717 Encode::Locale::reinit("cp1252");
1818 $ENV{"m\xf6ney"} = "\x80uro";
19 ok(env("m\xf6ney", "\x{20AC}"), "\x{20AC}uro");
20 ok(env("m\xf6ney"), "\x{20AC}");
21 ok($ENV{"m\xf6ney"}, "\x80");
22 ok(env("\x{20AC}", 1), undef);
23 ok(env("\x{20AC}"), 1);
24 ok($ENV{"\x80"}, 1);
19 is env("m\xf6ney", "\x{20AC}"), "\x{20AC}uro", 'env write retval encoded';
20 is env("m\xf6ney"), "\x{20AC}", 'env write worked';
21 is $ENV{"m\xf6ney"}, "\x80", 'env affected %ENV';
22 is env("\x{20AC}", 1), undef, 'env write retval old value';
23 is env("\x{20AC}"), 1, 'env write worked';
24 is $ENV{"\x80"}, 1, 'env affected %ENV';
0 #!perl -Tw
1
2 use strict;
3 use warnings;
4
5 # taint mode testing as seen in WWW::Mechanize
6
7 use Test::More tests => 1;
8 my @warns;
9 BEGIN {
10 $SIG{__WARN__} = sub { push @warns, @_ };
11 }
12 BEGIN {
13 delete @ENV{qw( PATH IFS CDPATH ENV BASH_ENV )}; # Placates taint-unsafe Cwd.pm in 5.6.1
14 }
15
16 require Encode::Locale;
17
18 is "@warns", "", 'no warnings';
0 #!perl -w
1
2 use strict;
3 use warnings;
4
5 use Test::More tests => 2;
6 my @warns;
7 BEGIN {
8 $SIG{__WARN__} = sub { push @warns, @_ };
9 }
10
11 use Encode::Locale;
12
13 BEGIN {
14 use Encode;
15 my $a = encode("UTF-8", "foo\xFF");
16 ok $a, "foo\xC3\xBF";
17 }
18
19 is "@warns", "", 'no warnings';