| Filename | /usr/share/perl/5.36/ExtUtils/MakeMaker/Locale.pm |
| Statements | Executed 40 statements in 873µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 242µs | 526µs | ExtUtils::MakeMaker::Locale::_init |
| 1 | 1 | 1 | 12µs | 25µs | ExtUtils::MakeMaker::Locale::BEGIN@142 |
| 1 | 1 | 1 | 10µs | 12µs | ExtUtils::MakeMaker::Locale::BEGIN@3 |
| 1 | 1 | 1 | 6µs | 10µs | ExtUtils::MakeMaker::Locale::BEGIN@141 |
| 1 | 1 | 1 | 5µs | 46µs | ExtUtils::MakeMaker::Locale::BEGIN@8 |
| 1 | 1 | 1 | 4µs | 7µs | ExtUtils::MakeMaker::Locale::BEGIN@147 |
| 1 | 1 | 1 | 4µs | 23µs | ExtUtils::MakeMaker::Locale::BEGIN@4 |
| 2 | 2 | 1 | 3µs | 3µs | ExtUtils::MakeMaker::Locale::__ANON__[:144] |
| 1 | 1 | 1 | 3µs | 3µs | ExtUtils::MakeMaker::Locale::BEGIN@15 |
| 1 | 1 | 1 | 2µs | 2µs | ExtUtils::MakeMaker::Locale::BEGIN@16 |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MakeMaker::Locale::__ANON__[:33] |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MakeMaker::Locale::__ANON__[:52] |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MakeMaker::Locale::__ANON__[:56] |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MakeMaker::Locale::__ANON__[:57] |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MakeMaker::Locale::__ANON__[:63] |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MakeMaker::Locale::__ANON__[:65] |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MakeMaker::Locale::__ANON__[:76] |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MakeMaker::Locale::_flush_aliases |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MakeMaker::Locale::decode_argv |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MakeMaker::Locale::env |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MakeMaker::Locale::reinit |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package ExtUtils::MakeMaker::Locale; | ||||
| 2 | |||||
| 3 | 2 | 20µs | 2 | 13µs | # spent 12µs (10+2) within ExtUtils::MakeMaker::Locale::BEGIN@3 which was called:
# once (10µs+2µs) by IPC::Cmd::can_run at line 3 # spent 12µs making 1 call to ExtUtils::MakeMaker::Locale::BEGIN@3
# spent 2µs making 1 call to strict::import |
| 4 | 2 | 30µs | 2 | 42µs | # spent 23µs (4+19) within ExtUtils::MakeMaker::Locale::BEGIN@4 which was called:
# once (4µs+19µs) by IPC::Cmd::can_run at line 4 # spent 23µs making 1 call to ExtUtils::MakeMaker::Locale::BEGIN@4
# spent 19µs making 1 call to warnings::import |
| 5 | 1 | 300ns | our $VERSION = "7.64"; | ||
| 6 | 1 | 900ns | $VERSION =~ tr/_//d; | ||
| 7 | |||||
| 8 | 2 | 29µs | 2 | 86µs | # spent 46µs (5+40) within ExtUtils::MakeMaker::Locale::BEGIN@8 which was called:
# once (5µs+40µs) by IPC::Cmd::can_run at line 8 # spent 46µs making 1 call to ExtUtils::MakeMaker::Locale::BEGIN@8
# spent 40µs making 1 call to base::import |
| 9 | 1 | 900ns | our @EXPORT_OK = qw( | ||
| 10 | decode_argv env | ||||
| 11 | $ENCODING_LOCALE $ENCODING_LOCALE_FS | ||||
| 12 | $ENCODING_CONSOLE_IN $ENCODING_CONSOLE_OUT | ||||
| 13 | ); | ||||
| 14 | |||||
| 15 | 2 | 15µs | 1 | 3µs | # spent 3µs within ExtUtils::MakeMaker::Locale::BEGIN@15 which was called:
# once (3µs+0s) by IPC::Cmd::can_run at line 15 # spent 3µs making 1 call to ExtUtils::MakeMaker::Locale::BEGIN@15 |
| 16 | 2 | 428µs | 1 | 2µs | # spent 2µs within ExtUtils::MakeMaker::Locale::BEGIN@16 which was called:
# once (2µs+0s) by IPC::Cmd::can_run at line 16 # spent 2µs making 1 call to ExtUtils::MakeMaker::Locale::BEGIN@16 |
| 17 | |||||
| 18 | our $ENCODING_LOCALE; | ||||
| 19 | our $ENCODING_LOCALE_FS; | ||||
| 20 | our $ENCODING_CONSOLE_IN; | ||||
| 21 | our $ENCODING_CONSOLE_OUT; | ||||
| 22 | |||||
| 23 | sub DEBUG () { 0 } | ||||
| 24 | |||||
| 25 | # spent 526µs (242+284) within ExtUtils::MakeMaker::Locale::_init which was called:
# once (242µs+284µs) by IPC::Cmd::can_run at line 139 | ||||
| 26 | 1 | 800ns | if ($^O eq "MSWin32") { | ||
| 27 | unless ($ENCODING_LOCALE) { | ||||
| 28 | # Try to obtain what the Windows ANSI code page is | ||||
| 29 | eval { | ||||
| 30 | unless (defined &GetConsoleCP) { | ||||
| 31 | require Win32; | ||||
| 32 | # manually "import" it since Win32->import refuses | ||||
| 33 | *GetConsoleCP = sub { &Win32::GetConsoleCP } if defined &Win32::GetConsoleCP; | ||||
| 34 | } | ||||
| 35 | unless (defined &GetConsoleCP) { | ||||
| 36 | require Win32::API; | ||||
| 37 | Win32::API->Import('kernel32', 'int GetConsoleCP()'); | ||||
| 38 | } | ||||
| 39 | if (defined &GetConsoleCP) { | ||||
| 40 | my $cp = GetConsoleCP(); | ||||
| 41 | $ENCODING_LOCALE = "cp$cp" if $cp; | ||||
| 42 | } | ||||
| 43 | }; | ||||
| 44 | } | ||||
| 45 | |||||
| 46 | unless ($ENCODING_CONSOLE_IN) { | ||||
| 47 | # only test one since set together | ||||
| 48 | unless (defined &GetInputCP) { | ||||
| 49 | eval { | ||||
| 50 | require Win32; | ||||
| 51 | eval { | ||||
| 52 | local $SIG{__WARN__} = sub {} if ( "$]" < 5.014 ); # suppress deprecation warning for inherited AUTOLOAD of Win32::GetConsoleCP() | ||||
| 53 | Win32::GetConsoleCP(); | ||||
| 54 | }; | ||||
| 55 | # manually "import" it since Win32->import refuses | ||||
| 56 | *GetInputCP = sub { &Win32::GetConsoleCP } if defined &Win32::GetConsoleCP; | ||||
| 57 | *GetOutputCP = sub { &Win32::GetConsoleOutputCP } if defined &Win32::GetConsoleOutputCP; | ||||
| 58 | }; | ||||
| 59 | unless (defined &GetInputCP) { | ||||
| 60 | eval { | ||||
| 61 | # try Win32::Console module for codepage to use | ||||
| 62 | require Win32::Console; | ||||
| 63 | *GetInputCP = sub { &Win32::Console::InputCP } | ||||
| 64 | if defined &Win32::Console::InputCP; | ||||
| 65 | *GetOutputCP = sub { &Win32::Console::OutputCP } | ||||
| 66 | if defined &Win32::Console::OutputCP; | ||||
| 67 | }; | ||||
| 68 | } | ||||
| 69 | unless (defined &GetInputCP) { | ||||
| 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 | ((qx(chcp) || '') =~ /^Active code page: (\d+)/) | ||||
| 75 | ? $1 : (); | ||||
| 76 | }; | ||||
| 77 | } | ||||
| 78 | } | ||||
| 79 | my $cp = GetInputCP(); | ||||
| 80 | $ENCODING_CONSOLE_IN = "cp$cp" if $cp; | ||||
| 81 | $cp = GetOutputCP(); | ||||
| 82 | $ENCODING_CONSOLE_OUT = "cp$cp" if $cp; | ||||
| 83 | } | ||||
| 84 | } | ||||
| 85 | |||||
| 86 | 1 | 100ns | unless ($ENCODING_LOCALE) { | ||
| 87 | 1 | 200ns | eval { | ||
| 88 | 1 | 91µs | require I18N::Langinfo; | ||
| 89 | 1 | 8µs | 2 | 4µs | $ENCODING_LOCALE = I18N::Langinfo::langinfo(I18N::Langinfo::CODESET()); # spent 3µs making 1 call to I18N::Langinfo::langinfo
# spent 400ns making 1 call to 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 | 1 | 200ns | $ENCODING_LOCALE = "ascii" if $ENCODING_LOCALE eq "646"; | ||
| 96 | |||||
| 97 | # https://rt.cpan.org/Ticket/Display.html?id=66373 | ||||
| 98 | 1 | 800ns | $ENCODING_LOCALE = "hp-roman8" if $^O eq "hpux" && $ENCODING_LOCALE eq "roman8"; | ||
| 99 | }; | ||||
| 100 | 1 | 200ns | $ENCODING_LOCALE ||= $ENCODING_CONSOLE_IN; | ||
| 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 | 1 | 500ns | $ENCODING_LOCALE = 'UTF-7' if $ENCODING_LOCALE && lc($ENCODING_LOCALE) eq "cp65000"; | ||
| 108 | 1 | 200ns | $ENCODING_LOCALE = 'utf-8-strict' if $ENCODING_LOCALE && lc($ENCODING_LOCALE) eq "cp65001"; | ||
| 109 | |||||
| 110 | 1 | 200ns | if ($^O eq "darwin") { | ||
| 111 | $ENCODING_LOCALE_FS ||= "UTF-8"; | ||||
| 112 | } | ||||
| 113 | |||||
| 114 | # final fallback | ||||
| 115 | 1 | 0s | $ENCODING_LOCALE ||= $^O eq "MSWin32" ? "cp1252" : "UTF-8"; | ||
| 116 | 1 | 300ns | $ENCODING_LOCALE_FS ||= $ENCODING_LOCALE; | ||
| 117 | 1 | 100ns | $ENCODING_CONSOLE_IN ||= $ENCODING_LOCALE; | ||
| 118 | 1 | 200ns | $ENCODING_CONSOLE_OUT ||= $ENCODING_CONSOLE_IN; | ||
| 119 | |||||
| 120 | 1 | 3µs | 1 | 68µs | unless (Encode::find_encoding($ENCODING_LOCALE)) { # spent 68µs making 1 call to Encode::find_encoding |
| 121 | my $foundit; | ||||
| 122 | if (lc($ENCODING_LOCALE) eq "gb18030") { | ||||
| 123 | eval { | ||||
| 124 | require Encode::HanExtra; | ||||
| 125 | }; | ||||
| 126 | if ($@) { | ||||
| 127 | die "Need Encode::HanExtra to be installed to support locale codeset ($ENCODING_LOCALE), stopped"; | ||||
| 128 | } | ||||
| 129 | $foundit++ if Encode::find_encoding($ENCODING_LOCALE); | ||||
| 130 | } | ||||
| 131 | die "The locale codeset ($ENCODING_LOCALE) isn't one that perl can decode, stopped" | ||||
| 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 | 1 | 800ns | 1 | 526µs | _init(); # spent 526µs making 1 call to ExtUtils::MakeMaker::Locale::_init |
| 140 | # spent 3µs within ExtUtils::MakeMaker::Locale::__ANON__[/usr/share/perl/5.36/ExtUtils/MakeMaker/Locale.pm:144] which was called 2 times, avg 2µs/call:
# once (2µs+0s) by Encode::Alias::define_alias at line 89 of Encode/Alias.pm
# once (1µs+0s) by Encode::Alias::find_alias at line 36 of Encode/Alias.pm | ||||
| 141 | 2 | 23µs | 2 | 14µs | # spent 10µs (6+4) within ExtUtils::MakeMaker::Locale::BEGIN@141 which was called:
# once (6µs+4µs) by IPC::Cmd::can_run at line 141 # spent 10µs making 1 call to ExtUtils::MakeMaker::Locale::BEGIN@141
# spent 4µs making 1 call to strict::unimport |
| 142 | 2 | 39µs | 2 | 39µs | # spent 25µs (12+13) within ExtUtils::MakeMaker::Locale::BEGIN@142 which was called:
# once (12µs+13µs) by IPC::Cmd::can_run at line 142 # spent 25µs making 1 call to ExtUtils::MakeMaker::Locale::BEGIN@142
# spent 13µs making 1 call to warnings::unimport |
| 143 | 2 | 5µs | return ${"ENCODING_" . uc(shift)}; | ||
| 144 | 1 | 2µs | 1 | 9µs | }, "locale"); # spent 9µs making 1 call to Encode::Alias::define_alias |
| 145 | |||||
| 146 | sub _flush_aliases { | ||||
| 147 | 2 | 167µs | 2 | 9µs | # spent 7µs (4+3) within ExtUtils::MakeMaker::Locale::BEGIN@147 which was called:
# once (4µs+3µs) by IPC::Cmd::can_run at line 147 # spent 7µs making 1 call to ExtUtils::MakeMaker::Locale::BEGIN@147
# spent 3µs making 1 call to strict::unimport |
| 148 | for my $a (sort keys %Encode::Alias::Alias) { | ||||
| 149 | if (defined ${"ENCODING_" . uc($a)}) { | ||||
| 150 | delete $Encode::Alias::Alias{$a}; | ||||
| 151 | warn "Flushed alias cache for $a" if DEBUG; | ||||
| 152 | } | ||||
| 153 | } | ||||
| 154 | } | ||||
| 155 | |||||
| 156 | sub reinit { | ||||
| 157 | $ENCODING_LOCALE = shift; | ||||
| 158 | $ENCODING_LOCALE_FS = shift; | ||||
| 159 | $ENCODING_CONSOLE_IN = $ENCODING_LOCALE; | ||||
| 160 | $ENCODING_CONSOLE_OUT = $ENCODING_LOCALE; | ||||
| 161 | _init(); | ||||
| 162 | _flush_aliases(); | ||||
| 163 | } | ||||
| 164 | |||||
| 165 | sub decode_argv { | ||||
| 166 | die if defined wantarray; | ||||
| 167 | for (@ARGV) { | ||||
| 168 | $_ = Encode::decode(locale => $_, @_); | ||||
| 169 | } | ||||
| 170 | } | ||||
| 171 | |||||
| 172 | sub env { | ||||
| 173 | my $k = Encode::encode(locale => shift); | ||||
| 174 | my $old = $ENV{$k}; | ||||
| 175 | if (@_) { | ||||
| 176 | my $v = shift; | ||||
| 177 | if (defined $v) { | ||||
| 178 | $ENV{$k} = Encode::encode(locale => $v); | ||||
| 179 | } | ||||
| 180 | else { | ||||
| 181 | delete $ENV{$k}; | ||||
| 182 | } | ||||
| 183 | } | ||||
| 184 | return Encode::decode(locale => $old) if defined wantarray; | ||||
| 185 | } | ||||
| 186 | |||||
| 187 | 1 | 5µs | 1; | ||
| 188 | |||||
| 189 | __END__ |