lib/ExtUtils/MakeMaker/Locale.pm

filter: Statementstmt 39.8% 47 / 118 Branchbran 9.0% 6 / 66 Conditioncond 27.2% 6 / 22 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 47.3% 9 / 19 Podpod 100% 3 / 3 totaltotal 29.3% 71 / 242 CC 44 SCAR 59.9
CC
44
Cov
29%
_init
699.6
env
20.0
__ANON__
12.0
CRAP 398.3
« lib/ExtUtils/MM_VMS.pm ↑ Summary lib/ExtUtils/Mksymlists.pm »
1 package ExtUtils::MakeMaker::Locale;
2  
3 50 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 50 our $VERSION = "7.13_01";
5 50 $VERSION = eval $VERSION;
6  
7 50 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 50 our @EXPORT_OK = qw(
9 decode_argv env
10 $ENCODING_LOCALE $ENCODING_LOCALE_FS
11 $ENCODING_CONSOLE_IN $ENCODING_CONSOLE_OUT
12 );
13  
14 50 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 50 ▶use Encode::Alias ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 50 our $ENCODING_LOCALE;
18 50 our $ENCODING_LOCALE_FS;
19 50 our $ENCODING_CONSOLE_IN;
20 50 our $ENCODING_CONSOLE_OUT;
21  
22 sub DEBUG () { 0 }
23  
24 sub _init {
25 50 ▶ if ($^O eq "MSWin32") {
Subroutine _init: called CC=35 SCAR=65.5
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 50 50
26 0 ▶ unless ($ENCODING_LOCALE) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ExtUtils::MakeMaker::Locale::ENCODING_LOCALE) 0 0 0
27 # Try to obtain what the Windows ANSI code page is
28 0 eval {
29 0 ▶ unless (defined &GetConsoleCP) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &ExtUtils::MakeMaker::Locale::GetConsoleCP) 0 0 0
30 0 require Win32;
31 # no point falling back to Win32::GetConsoleCP from this
32 # as added same time, 0.45
33 0 eval { Win32::GetConsoleCP() };
34 # manually "import" it since Win32->import refuses
35 0 ▶ *GetConsoleCP = sub { &Win32::GetConsoleCP } unless $@;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 0 0
36 }
37 0 ▶ unless (defined &GetConsoleCP) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &ExtUtils::MakeMaker::Locale::GetConsoleCP) 0 0 0
38 0 require Win32::API;
39 0 Win32::API->Import('kernel32', 'int GetConsoleCP()');
40 }
41 0 ▶ if (defined &GetConsoleCP) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &ExtUtils::MakeMaker::Locale::GetConsoleCP) 0 0 0
42 0 my $cp = GetConsoleCP();
43 0 ▶ $ENCODING_LOCALE = "cp$cp" if $cp;
Branch: 1 branch
BranchTrueFalseTotal
if $cp 0 0 0
44 }
45 };
46 }
47  
48 0 ▶ unless ($ENCODING_CONSOLE_IN) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN) 0 0 0
49 # only test one since set together
50 0 ▶ unless (defined &GetInputCP) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &ExtUtils::MakeMaker::Locale::GetInputCP) 0 0 0
51 0 eval {
52 0 require Win32;
53 0 eval { Win32::GetConsoleCP() };
54 # manually "import" it since Win32->import refuses
55 0 ▶ *GetInputCP = sub { &Win32::GetConsoleCP } unless $@;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 0 0
56 0 ▶ *GetOutputCP = sub { &Win32::GetConsoleOutputCP } unless $@;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 0 0
57 };
58 0 ▶ unless (defined &GetInputCP) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &ExtUtils::MakeMaker::Locale::GetInputCP) 0 0 0
59 0 eval {
60 # try Win32::Console module for codepage to use
61 0 require Win32::Console;
62 0 eval { Win32::Console::InputCP() };
63 0 ▶ *GetInputCP = sub { &Win32::Console::InputCP }
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 0 ▶ unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 0 0
65 0 ▶ *GetOutputCP = sub { &Win32::Console::OutputCP }
Subroutine __ANON__: not called CC=1 SCAR=6.9
66 0 ▶ unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 0 0
67 };
68 }
69 0 ▶ unless (defined &GetInputCP) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &ExtUtils::MakeMaker::Locale::GetInputCP) 0 0 0
70 # final fallback
71 *GetInputCP = *GetOutputCP = sub {
72 # another fallback that could work is:
73 # reg query HKLM\System\CurrentControlSet\Control\Nls\CodePage /v ACP
74 0 ▶ ((qx(chcp) || '') =~ /^Active code page: (\d+)/)
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
(`chcp` || '') =~ /^Active code page: (\d+)/ ? : 0 0 0
Condition0%0/2
`chcp` || ''
l!l
00
MC/DC0%0/1
`chcp` || ''
`chcp`
Truth table0%0/2
A
A= `chcp`
Aresult
11
00
75 ? $1 : ();
76 0 };
77 }
78 }
79 0 my $cp = GetInputCP();
80 0 ▶ $ENCODING_CONSOLE_IN = "cp$cp" if $cp;
Branch: 1 branch
BranchTrueFalseTotal
if $cp 0 0 0
81 0 $cp = GetOutputCP();
82 0 ▶ $ENCODING_CONSOLE_OUT = "cp$cp" if $cp;
Branch: 1 branch
BranchTrueFalseTotal
if $cp 0 0 0
83 }
84 }
85  
86 50 ▶ unless ($ENCODING_LOCALE) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ExtUtils::MakeMaker::Locale::ENCODING_LOCALE) 50 0 50
87 50 eval {
88 50 require I18N::Langinfo;
89 50 $ENCODING_LOCALE = I18N::Langinfo::langinfo(I18N::Langinfo::CODESET());
90  
91 # Workaround of Encode < v2.25. The "646" encoding alias was
92 # introduced in Encode-2.25, but we don't want to require that version
93 # quite yet. Should avoid the CPAN testers failure reported from
94 # openbsd-4.7/perl-5.10.0 combo.
95 50 ▶ $ENCODING_LOCALE = "ascii" if $ENCODING_LOCALE eq "646";
Branch: 1 branch
BranchTrueFalseTotal
if $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq 646 0 50 50
96  
97 # https://rt.cpan.org/Ticket/Display.html?id=66373
98 50 ▶ $ENCODING_LOCALE = "hp-roman8" if $^O eq "hpux" && $ENCODING_LOCALE eq "roman8";
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "hpux" and $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "roman8" 0 50 50
Condition33%1/3
$^O eq "hpux" and $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "roman8"
!ll&&!rl&&r
5000
MC/DC0%0/2
$^O eq "hpux" and $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "roman8"
$^O eq "hpux" $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "roman8"
Truth table33%1/3
A and B
A= $^O eq "hpux"B= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "roman8"
ABresult
0X0
100
111
99 };
100 50 ▶ $ENCODING_LOCALE ||= $ENCODING_CONSOLE_IN;
Condition33%1/3
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE ||= $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN
l!l&&r!l&&!r
5000
MC/DC0%0/2
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE ||= $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN
Truth table33%1/3
A ||= B
A= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALEB= $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN
ABresult
1X1
011
000
101 }
102  
103 50 ▶ if ($^O eq "darwin") {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "darwin") 0 50 50
104 0 ▶ $ENCODING_LOCALE_FS ||= "UTF-8";
Condition0%0/2
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE_FS ||= "UTF-8"
l!l
00
MC/DC0%0/1
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE_FS ||= "UTF-8"
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE_FS
Truth table0%0/2
A
A= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE_FS
Aresult
11
00
105 }
106  
107 # final fallback
108 50 ▶ $ENCODING_LOCALE ||= $^O eq "MSWin32" ? "cp1252" : "UTF-8";
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
Condition33%1/3
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE ||= $^O eq "MSWin32" ? "cp1252" : "UTF-8"
l!l&&r!l&&!r
5000
MC/DC0%0/2
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE ||= $^O eq "MSWin32" ? "cp1252" : "UTF-8"
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE $^O eq "MSWin32" ? "cp1252" : "UTF-8"
Truth table33%1/3
A ||= B
A= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALEB= $^O eq "MSWin32" ? "cp1252" : "UTF-8"
ABresult
1X1
011
000
109 50 ▶ $ENCODING_LOCALE_FS ||= $ENCODING_LOCALE;
Condition33%1/3
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE_FS ||= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE
l!l&&r!l&&!r
0500
MC/DC0%0/2
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE_FS ||= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE_FS $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE
Truth table33%1/3
A ||= B
A= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE_FSB= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE
ABresult
1X1
011
000
110 50 ▶ $ENCODING_CONSOLE_IN ||= $ENCODING_LOCALE;
Condition33%1/3
$ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN ||= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE
l!l&&r!l&&!r
0500
MC/DC0%0/2
$ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN ||= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE
$ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE
Truth table33%1/3
A ||= B
A= $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_INB= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE
ABresult
1X1
011
000
111 50 ▶ $ENCODING_CONSOLE_OUT ||= $ENCODING_CONSOLE_IN;
Condition33%1/3
$ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_OUT ||= $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN
l!l&&r!l&&!r
0500
MC/DC0%0/2
$ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_OUT ||= $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN
$ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_OUT $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN
Truth table33%1/3
A ||= B
A= $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_OUTB= $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN
ABresult
1X1
011
000
112  
113 50 ▶ unless (Encode::find_encoding($ENCODING_LOCALE)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&Encode::find_encoding($ExtUtils::MakeMaker::Locale::ENCODING_LOCALE)) 0 50 50
114 0 my $foundit;
115 0 ▶ if (lc($ENCODING_LOCALE) eq "gb18030") {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "gb18030") 0 0 0
116 0 eval {
117 0 require Encode::HanExtra;
118 };
119 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
120 0 die "Need Encode::HanExtra to be installed to support locale codeset ($ENCODING_LOCALE), stopped";
121 }
122 0 ▶ $foundit++ if Encode::find_encoding($ENCODING_LOCALE);
Branch: 1 branch
BranchTrueFalseTotal
if &Encode::find_encoding($ExtUtils::MakeMaker::Locale::ENCODING_LOCALE) 0 0 0
123 }
124 0 ▶ die "The locale codeset ($ENCODING_LOCALE) isn't one that perl can decode, stopped"
Branch: 1 branch
BranchTrueFalseTotal
unless $foundit 0 0 0
125 unless $foundit;
126  
127 }
128  
129 # use Data::Dump; ddx $ENCODING_LOCALE, $ENCODING_LOCALE_FS, $ENCODING_CONSOLE_IN, $ENCODING_CONSOLE_OUT;
130 }
131  
132 50 _init();
133 Encode::Alias::define_alias(sub {
134 50 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
135 50 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
136 162 ▶ return ${"ENCODING_" . uc(shift)};
Subroutine __ANON__: called CC=1 SCAR=0.0
137 50 }, "locale");
138  
139 sub _flush_aliases {
140 50 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
141 0 ▶ for my $a (sort keys %Encode::Alias::Alias) {
Subroutine _flush_aliases: not called CC=3 SCAR=24.8
142 0 ▶ if (defined ${"ENCODING_" . uc($a)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined ${'ENCODING_' . uc($a);}) 0 0 0
143 0 delete $Encode::Alias::Alias{$a};
144 0 warn "Flushed alias cache for $a" if DEBUG;
145 }
146 }
147 }
148  
149 sub reinit {
150 0 ▶ $ENCODING_LOCALE = shift;
Subroutine reinit: not called CC=1 SCAR=6.9
Pod documented
151 0 $ENCODING_LOCALE_FS = shift;
152 0 $ENCODING_CONSOLE_IN = $ENCODING_LOCALE;
153 0 $ENCODING_CONSOLE_OUT = $ENCODING_LOCALE;
154 0 _init();
155 0 _flush_aliases();
156 }
157  
158 sub decode_argv {
159 0 ▶ die if defined wantarray;
Subroutine decode_argv: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 0 0 0
160 0 for (@ARGV) {
161 0 $_ = Encode::decode(locale => $_, @_);
162 }
163 }
164  
165 sub env {
166 0 ▶ my $k = Encode::encode(locale => shift);
Subroutine env: not called CC=4 SCAR=30.0
Pod documented
167 0 my $old = $ENV{$k};
168 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
169 0 my $v = shift;
170 0 ▶ if (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) { } 0 0 0
171 0 $ENV{$k} = Encode::encode(locale => $v);
172 }
173 else {
174 0 delete $ENV{$k};
175 }
176 }
177 0 ▶ return Encode::decode(locale => $old) if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 0 0 0
178 }
179  
180 50 1;
181  
182 __END__
« lib/ExtUtils/MM_VMS.pm ↑ Summary lib/ExtUtils/Mksymlists.pm »