lib/ExtUtils/MakeMaker/Locale.pm

filter: Statementstmt 52.5% 63 / 120 Branchbran 15.2% 11 / 72 Conditioncond 35.7% 10 / 28 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 57.1% 12 / 21 Podpod 100% 3 / 3 totaltotal 37.7% 99 / 262 CC 49 SCAR 61.1
CC
49
Cov
38%
_init
769.7
env
20.0
__ANON__
12.0
CRAP 448.9
« lib/ExtUtils/Liblist/Kid.pm ↑ Summary lib/ExtUtils/MM_VMS.pm »
1 package ExtUtils::MakeMaker::Locale;
2  
3 96 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 96 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 96 our $VERSION = "7.78";
6 96 $VERSION =~ tr/_//d;
7  
8 96 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 96 our @EXPORT_OK = qw(
10 decode_argv env
11 $ENCODING_LOCALE $ENCODING_LOCALE_FS
12 $ENCODING_CONSOLE_IN $ENCODING_CONSOLE_OUT
13 );
14  
15 96 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 96 ▶use Encode::Alias ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 96 our $ENCODING_LOCALE;
19 96 our $ENCODING_LOCALE_FS;
20 96 our $ENCODING_CONSOLE_IN;
21 96 our $ENCODING_CONSOLE_OUT;
22  
23 sub DEBUG () { 0 }
24  
25 192 ▶sub _init {
Subroutine _init: called CC=40 SCAR=66.5
26 192 ▶ if ($^O eq "MSWin32") {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 192 192
27 0 ▶ unless ($ENCODING_LOCALE) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ExtUtils::MakeMaker::Locale::ENCODING_LOCALE) 0 0 0
28 # Try to obtain what the Windows ANSI code page is
29 0 eval {
30 0 ▶ unless (defined &GetConsoleCP) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &ExtUtils::MakeMaker::Locale::GetConsoleCP) 0 0 0
31 0 require Win32;
32 # manually "import" it since Win32->import refuses
33 0 ▶ *GetConsoleCP = sub { &Win32::GetConsoleCP } if defined &Win32::GetConsoleCP;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if defined &Win32::GetConsoleCP 0 0 0
34 }
35 0 ▶ unless (defined &GetConsoleCP) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &ExtUtils::MakeMaker::Locale::GetConsoleCP) 0 0 0
36 0 require Win32::API;
37 0 Win32::API->Import('kernel32', 'int GetConsoleCP()');
38 }
39 0 ▶ if (defined &GetConsoleCP) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &ExtUtils::MakeMaker::Locale::GetConsoleCP) 0 0 0
40 0 my $cp = GetConsoleCP();
41 0 ▶ $ENCODING_LOCALE = "cp$cp" if $cp;
Branch: 1 branch
BranchTrueFalseTotal
if $cp 0 0 0
42 }
43 };
44 }
45  
46 0 ▶ unless ($ENCODING_CONSOLE_IN) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN) 0 0 0
47 # only test one since set together
48 0 ▶ unless (defined &GetInputCP) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &ExtUtils::MakeMaker::Locale::GetInputCP) 0 0 0
49 0 eval {
50 0 require Win32;
51 0 eval {
52 0 ▶ local $SIG{__WARN__} = sub {} if ( "$]" < 5.014 ); # suppress deprecation warning for inherited AUTOLOAD of Win32::GetConsoleCP()
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if "$]" < "5.014" 0 0 0
53 0 Win32::GetConsoleCP();
54 };
55 # manually "import" it since Win32->import refuses
56 0 ▶ *GetInputCP = sub { &Win32::GetConsoleCP } if defined &Win32::GetConsoleCP;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if defined &Win32::GetConsoleCP 0 0 0
57 0 ▶ *GetOutputCP = sub { &Win32::GetConsoleOutputCP } if defined &Win32::GetConsoleOutputCP;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if defined &Win32::GetConsoleOutputCP 0 0 0
58 };
59 0 ▶ unless (defined &GetInputCP) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &ExtUtils::MakeMaker::Locale::GetInputCP) 0 0 0
60 0 eval {
61 # try Win32::Console module for codepage to use
62 0 require Win32::Console;
63 0 ▶ *GetInputCP = sub { &Win32::Console::InputCP }
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 0 ▶ if defined &Win32::Console::InputCP;
Branch: 1 branch
BranchTrueFalseTotal
if defined &Win32::Console::InputCP 0 0 0
65 0 ▶ *GetOutputCP = sub { &Win32::Console::OutputCP }
Subroutine __ANON__: not called CC=1 SCAR=6.9
66 0 ▶ if defined &Win32::Console::OutputCP;
Branch: 1 branch
BranchTrueFalseTotal
if defined &Win32::Console::OutputCP 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 0 ▶ *GetInputCP = *GetOutputCP = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
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+)/)
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 192 ▶ unless ($ENCODING_LOCALE) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ExtUtils::MakeMaker::Locale::ENCODING_LOCALE) 96 96 192
87 96 eval {
88 96 require I18N::Langinfo;
89 96 $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 96 ▶ $ENCODING_LOCALE = "ascii" if $ENCODING_LOCALE eq "646";
Branch: 1 branch
BranchTrueFalseTotal
if $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq 646 0 96 96
96  
97 # https://rt.cpan.org/Ticket/Display.html?id=66373
98 96 ▶ $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 96 96
Condition33%1/3
$^O eq "hpux" and $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "roman8"
!ll&&!rl&&r
9600
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 96 ▶ $ENCODING_LOCALE ||= $ENCODING_CONSOLE_IN;
Condition33%1/3
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE ||= $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN
l!l&&r!l&&!r
9600
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 # Workaround of Encode < v2.71 for "cp65000" and "cp65001"
104 # The "cp65000" and "cp65001" aliases were added in [Encode v2.71](https://github.com/dankogai/p5-encode/commit/7874bd95aa10967a3b5dbae333d16bcd703ac6c6)
105 # via commit <https://github.com/dankogai/p5-encode/commit/84b9c1101d5251d37e226f80d1c6781718779047>.
106 # This will avoid test failures for Win32 machines using the UTF-7 or UTF-8 code pages.
107 192 ▶ $ENCODING_LOCALE = 'UTF-7' if $ENCODING_LOCALE && lc($ENCODING_LOCALE) eq "cp65000";
Branch: 1 branch
BranchTrueFalseTotal
if $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE and lc $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "cp65000" 0 192 192
Condition33%1/3
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE and lc $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "cp65000"
!ll&&!rl&&r
01920
MC/DC0%0/2
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE and lc $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "cp65000"
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE lc $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "cp65000"
Truth table33%1/3
A and B
A= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALEB= lc $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "cp65000"
ABresult
0X0
100
111
108 192 ▶ $ENCODING_LOCALE = 'utf-8-strict' if $ENCODING_LOCALE && lc($ENCODING_LOCALE) eq "cp65001";
Branch: 1 branch
BranchTrueFalseTotal
if $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE and lc $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "cp65001" 0 192 192
Condition33%1/3
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE and lc $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "cp65001"
!ll&&!rl&&r
01920
MC/DC0%0/2
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE and lc $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "cp65001"
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE lc $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "cp65001"
Truth table33%1/3
A and B
A= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALEB= lc $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "cp65001"
ABresult
0X0
100
111
109  
110 192 ▶ if ($^O eq "darwin") {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "darwin") 0 192 192
111 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
112 }
113  
114 # final fallback
115 192 ▶ $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
19200
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
116 192 ▶ $ENCODING_LOCALE_FS ||= $ENCODING_LOCALE;
Condition33%1/3
$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE_FS ||= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE
l!l&&r!l&&!r
01920
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
117 192 ▶ $ENCODING_CONSOLE_IN ||= $ENCODING_LOCALE;
Condition66%2/3
$ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN ||= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE
l!l&&r!l&&!r
96960
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 table66%2/3
A ||= B
A= $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_INB= $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE
ABresult
1X1
011
000
118 192 ▶ $ENCODING_CONSOLE_OUT ||= $ENCODING_CONSOLE_IN;
Condition66%2/3
$ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_OUT ||= $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN
l!l&&r!l&&!r
96960
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 table66%2/3
A ||= B
A= $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_OUTB= $ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN
ABresult
1X1
011
000
119  
120 192 ▶ unless (Encode::find_encoding($ENCODING_LOCALE)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&Encode::find_encoding($ExtUtils::MakeMaker::Locale::ENCODING_LOCALE)) 0 192 192
121 0 my $foundit;
122 0 ▶ if (lc($ENCODING_LOCALE) eq "gb18030") {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq "gb18030") 0 0 0
123 0 eval {
124 0 require Encode::HanExtra;
125 };
126 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
127 0 die "Need Encode::HanExtra to be installed to support locale codeset ($ENCODING_LOCALE), stopped";
128 }
129 0 ▶ $foundit++ if Encode::find_encoding($ENCODING_LOCALE);
Branch: 1 branch
BranchTrueFalseTotal
if &Encode::find_encoding($ExtUtils::MakeMaker::Locale::ENCODING_LOCALE) 0 0 0
130 }
131 0 ▶ die "The locale codeset ($ENCODING_LOCALE) isn't one that perl can decode, stopped"
Branch: 1 branch
BranchTrueFalseTotal
unless $foundit 0 0 0
132 unless $foundit;
133  
134 }
135  
136 # use Data::Dump; ddx $ENCODING_LOCALE, $ENCODING_LOCALE_FS, $ENCODING_CONSOLE_IN, $ENCODING_CONSOLE_OUT;
137 }
138  
139 96 _init();
140 436 ▶Encode::Alias::define_alias(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
141 96 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
142 96 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
143 436 return ${"ENCODING_" . uc(shift)};
144 96 }, "locale");
145  
146 96 ▶sub _flush_aliases {
Subroutine _flush_aliases: called CC=3 SCAR=11.0
147 96 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
148 96 for my $a (sort keys %Encode::Alias::Alias) {
149 384 ▶ if (defined ${"ENCODING_" . uc($a)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined ${'ENCODING_' . uc($a);}) 96 288 384
150 96 delete $Encode::Alias::Alias{$a};
151 96 warn "Flushed alias cache for $a" if DEBUG;
152 }
153 }
154 }
155  
156 96 ▶sub reinit {
Subroutine reinit: called CC=1 SCAR=0.0
Pod documented
157 96 $ENCODING_LOCALE = shift;
158 96 $ENCODING_LOCALE_FS = shift;
159 96 $ENCODING_CONSOLE_IN = $ENCODING_LOCALE;
160 96 $ENCODING_CONSOLE_OUT = $ENCODING_LOCALE;
161 96 _init();
162 96 _flush_aliases();
163 }
164  
165 0 ▶sub decode_argv {
Subroutine decode_argv: not called CC=3 SCAR=24.8
Pod documented
166 0 ▶ die if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 0 0 0
167 0 for (@ARGV) {
168 0 $_ = Encode::decode(locale => $_, @_);
169 }
170 }
171  
172 0 ▶sub env {
Subroutine env: not called CC=4 SCAR=30.0
Pod documented
173 0 my $k = Encode::encode(locale => shift);
174 0 my $old = $ENV{$k};
175 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
176 0 my $v = shift;
177 0 ▶ if (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) { } 0 0 0
178 0 $ENV{$k} = Encode::encode(locale => $v);
179 }
180 else {
181 0 delete $ENV{$k};
182 }
183 }
184 0 ▶ return Encode::decode(locale => $old) if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 0 0 0
185 }
186  
187 96 1;
188  
189 __END__
« lib/ExtUtils/Liblist/Kid.pm ↑ Summary lib/ExtUtils/MM_VMS.pm »