Merge tag 'upstream/1.05'
Upstream version 1.05
Florian Schlichting
8 years ago
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 | ||
0 | 31 | ## 2012-01-11 Release 1.03 |
1 | 32 | |
2 | 33 | Documentation spelling fixes and tweaks to improve testing on Windows. |
2 | 2 | Makefile.PL |
3 | 3 | MANIFEST This list of files |
4 | 4 | README |
5 | t/alias.t | |
5 | 6 | t/arg.t |
6 | 7 | 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' | |
4 | 2 | 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' | |
8 | 7 | 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' | |
12 | 22 | requires: |
13 | Encode: 2 | |
14 | Encode::Alias: 0 | |
15 | perl: 5.008 | |
23 | Encode: '2' | |
24 | Encode::Alias: '0' | |
25 | perl: '5.008' | |
16 | 26 | 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' |
17 | 17 | }, |
18 | 18 | recommends => { |
19 | 19 | 'I18N::Langinfo' => 0, |
20 | 'Win32::Console' => 0, | |
20 | ($^O eq 'MSWin32' | |
21 | ? ('Win32::Console' => 0) | |
22 | : ()), | |
21 | 23 | }, |
22 | 24 | }, |
23 | BUILD_REQUIRES => { | |
24 | Test => 0, | |
25 | TEST_REQUIRES => { | |
26 | 'Test::More' => 0, | |
25 | 27 | }, |
26 | 28 | ); |
27 | 29 | |
34 | 36 | META_ADD => 6.45, |
35 | 37 | MIN_PERL_VERSION => 6.48, |
36 | 38 | BUILD_REQUIRES => 6.56, |
39 | TEST_REQUIRES => 6.64, | |
37 | 40 | ); |
38 | 41 | undef(*WriteMakefile); |
39 | 42 | *WriteMakefile = sub { |
40 | 43 | 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 | } | |
41 | 51 | for (keys %mm_req) { |
42 | 52 | unless (eval { ExtUtils::MakeMaker->VERSION($mm_req{$_}) }) { |
43 | 53 | warn "$_ $@" if $developer; |
0 | 0 | package Encode::Locale; |
1 | 1 | |
2 | 2 | use strict; |
3 | our $VERSION = "1.03"; | |
3 | our $VERSION = "1.05"; | |
4 | 4 | |
5 | 5 | use base 'Exporter'; |
6 | 6 | our @EXPORT_OK = qw( |
25 | 25 | # Try to obtain what the Windows ANSI code page is |
26 | 26 | eval { |
27 | 27 | unless (defined &GetACP) { |
28 | require Win32; | |
29 | eval { Win32::GetACP() }; | |
30 | *GetACP = sub { &Win32::GetACP } unless $@; | |
31 | } | |
32 | unless (defined &GetACP) { | |
28 | 33 | require Win32::API; |
29 | 34 | Win32::API->Import('kernel32', 'int GetACP()'); |
30 | }; | |
35 | } | |
31 | 36 | if (defined &GetACP) { |
32 | 37 | my $cp = GetACP(); |
33 | 38 | $ENCODING_LOCALE = "cp$cp" if $cp; |
36 | 41 | } |
37 | 42 | |
38 | 43 | 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 | } | |
51 | 73 | } |
74 | my $cp = GetInputCP(); | |
75 | $ENCODING_CONSOLE_IN = "cp$cp" if $cp; | |
76 | $cp = GetOutputCP(); | |
77 | $ENCODING_CONSOLE_OUT = "cp$cp" if $cp; | |
52 | 78 | } |
53 | 79 | } |
54 | 80 | |
205 | 231 | under the C<Encode> aliases "console_in" and "console_out". For systems where |
206 | 232 | we can't determine the terminal encoding these will be aliased as the same |
207 | 233 | 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. | |
210 | 235 | |
211 | 236 | In addition to arranging for various Encode aliases the following functions and |
212 | 237 | variables are provided: |
265 | 290 | |
266 | 291 | =item $ENCODING_LOCALE_FS |
267 | 292 | |
268 | The encoding name determined to be suiteable for file system interfaces | |
293 | The encoding name determined to be suitable for file system interfaces | |
269 | 294 | involving file names. |
270 | 295 | L<Encode> know this encoding as "locale_fs". |
271 | 296 | |
335 | 360 | |
336 | 361 | =head1 SEE ALSO |
337 | 362 | |
338 | L<I18N::Langinfo>, L<Encode> | |
363 | L<I18N::Langinfo>, L<Encode>, L<Term::Encoding> | |
339 | 364 | |
340 | 365 | =head1 AUTHOR |
341 | 366 |
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'; |
0 | 0 | #!perl -w |
1 | 1 | |
2 | 2 | use strict; |
3 | use Test; | |
4 | plan tests => 1; | |
3 | use warnings; | |
4 | use Test::More; | |
5 | 5 | |
6 | 6 | use Encode::Locale qw($ENCODING_LOCALE decode_argv); |
7 | use Encode; | |
8 | use utf8; | |
7 | 9 | |
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 | ||
9 | 17 | decode_argv(); |
10 | 18 | |
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)) { | |
15 | 33 | if (ord() > 32 && ord() < 128) { |
16 | print $_; | |
34 | push @r, $_; | |
17 | 35 | } |
18 | 36 | elsif (ord() < 256) { |
19 | printf "\\x%02X", ord(); | |
37 | push @r, sprintf "\\x%02X", ord(); | |
20 | 38 | } |
21 | 39 | else { |
22 | printf "\\x{%04X}", ord(); | |
40 | push @r, sprintf "\\x{%04X}", ord(); | |
23 | 41 | } |
24 | 42 | } |
25 | print "\"\n"; | |
43 | join '', @r; | |
26 | 44 | } |
27 | ||
28 | # fake it :-) | |
29 | ok(1); |
0 | 0 | #!perl -w |
1 | 1 | |
2 | 2 | use strict; |
3 | use Test; | |
4 | plan tests => 13; | |
3 | use warnings; | |
4 | use Test::More tests => 13; | |
5 | 5 | |
6 | 6 | use Encode::Locale qw(env); |
7 | 7 | |
8 | 8 | $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'; | |
16 | 16 | |
17 | 17 | Encode::Locale::reinit("cp1252"); |
18 | 18 | $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'; |