line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Term::Encoding; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
77898
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
173
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
16
|
use base qw(Exporter); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
506
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw(term_encoding); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
*term_encoding = \&get_encoding; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub get_encoding { |
12
|
3
|
|
|
3
|
|
27
|
no warnings 'uninitialized'; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
1327
|
|
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
6
|
0
|
506196
|
my($locale, $encoding); |
15
|
6
|
|
|
|
|
10
|
local $@; |
16
|
|
|
|
|
|
|
|
17
|
6
|
|
|
|
|
9
|
eval { |
18
|
|
|
|
|
|
|
# try I18N::Langinfo to get encoding from system |
19
|
6
|
|
|
|
|
176
|
require I18N::Langinfo; |
20
|
6
|
|
|
|
|
21
|
$encoding = I18N::Langinfo::langinfo(I18N::Langinfo::CODESET()); |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
6
|
50
|
|
|
|
36
|
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
|
|
|
|
15
|
if (!$encoding) { |
33
|
6
|
|
|
|
|
11
|
foreach my $key (qw( LANGUAGE LC_ALL LC_MESSAGES LANG )) { |
34
|
6
|
50
|
|
|
|
46
|
$ENV{$key} =~ /^([^.]+)\.([^.:]+)/ or next; |
35
|
6
|
|
|
|
|
46
|
($locale, $encoding) = ($1, $2); |
36
|
6
|
|
|
|
|
12
|
last; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# deal with EUC asian variants |
41
|
6
|
100
|
66
|
|
|
42
|
if (defined $encoding && |
|
|
|
66
|
|
|
|
|
42
|
|
|
|
|
|
|
lc($encoding) eq 'euc' && |
43
|
|
|
|
|
|
|
defined $locale) { |
44
|
3
|
100
|
|
|
|
16
|
if ($locale =~ /^ja_JP|japan(?:ese)?$/i) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
45
|
2
|
|
|
|
|
4
|
$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
|
|
|
|
|
17
|
return lc($encoding); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
__END__ |