line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Term::Encoding; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
186672
|
use strict; |
|
3
|
|
|
|
|
23
|
|
|
3
|
|
|
|
|
141
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
18
|
use base qw(Exporter); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
498
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw(term_encoding); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
*term_encoding = \&get_encoding; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub get_encoding { |
12
|
3
|
|
|
3
|
|
19
|
no warnings 'uninitialized'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
957
|
|
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
6
|
0
|
3982
|
my($locale, $encoding); |
15
|
6
|
|
|
|
|
8
|
local $@; |
16
|
|
|
|
|
|
|
|
17
|
6
|
|
|
|
|
8
|
eval { |
18
|
|
|
|
|
|
|
# try I18N::Langinfo to get encoding from system |
19
|
6
|
|
|
|
|
26
|
require I18N::Langinfo; |
20
|
6
|
|
|
|
|
18
|
$encoding = I18N::Langinfo::langinfo(I18N::Langinfo::CODESET()); |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
6
|
50
|
|
|
|
24
|
if ($^O eq 'MSWin32') { |
24
|
|
|
|
|
|
|
# if it's running on win32 ... try Win32::Console |
25
|
0
|
|
|
|
|
0
|
eval { |
26
|
0
|
|
|
|
|
0
|
require Win32::Console; |
27
|
0
|
|
|
|
|
0
|
$encoding = 'cp'.Win32::Console::OutputCP(); |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Still no luck ... use environment variables to get locale and encoding |
32
|
6
|
50
|
|
|
|
13
|
if (!$encoding) { |
33
|
6
|
|
|
|
|
12
|
foreach my $key (qw( LANGUAGE LC_ALL LC_MESSAGES LANG )) { |
34
|
6
|
50
|
|
|
|
33
|
$ENV{$key} =~ /^([^.]+)\.([^.:]+)/ or next; |
35
|
6
|
|
|
|
|
17
|
($locale, $encoding) = ($1, $2); |
36
|
6
|
|
|
|
|
9
|
last; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# deal with EUC asian variants |
41
|
6
|
100
|
66
|
|
|
57
|
if (defined $encoding && |
|
|
|
66
|
|
|
|
|
42
|
|
|
|
|
|
|
lc($encoding) eq 'euc' && |
43
|
|
|
|
|
|
|
defined $locale) { |
44
|
3
|
100
|
|
|
|
14
|
if ($locale =~ /^ja_JP|japan(?:ese)?$/i) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
45
|
2
|
|
|
|
|
5
|
$encoding = 'euc-jp'; |
46
|
|
|
|
|
|
|
} elsif ($locale =~ /^ko_KR|korean?$/i) { |
47
|
1
|
|
|
|
|
2
|
$encoding = 'euc-kr'; |
48
|
|
|
|
|
|
|
} elsif ($locale =~ /^zh_CN|chin(?:a|ese)?$/i) { |
49
|
0
|
|
|
|
|
0
|
$encoding = 'euc-cn'; |
50
|
|
|
|
|
|
|
} elsif ($locale =~ /^zh_TW|taiwan(?:ese)?$/i) { |
51
|
0
|
|
|
|
|
0
|
$encoding = 'euc-tw'; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
6
|
|
|
|
|
18
|
return lc($encoding); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
__END__ |