| Filename | /usr/share/perl5/DateTime/Locale.pm |
| Statements | Executed 14999 statements in 82.2ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 466 | 1 | 1 | 28.3ms | 57.7ms | DateTime::Locale::_register |
| 1 | 1 | 1 | 11.1ms | 11.2ms | DateTime::Locale::BEGIN@11 |
| 1 | 1 | 1 | 4.71ms | 21.4ms | DateTime::Locale::add_aliases |
| 422 | 1 | 1 | 4.34ms | 16.7ms | DateTime::Locale::_registered_id |
| 1 | 1 | 1 | 4.26ms | 61.9ms | DateTime::Locale::register |
| 1 | 1 | 1 | 3.98ms | 4.47ms | DateTime::Locale::BEGIN@10 |
| 466 | 1 | 1 | 766µs | 766µs | DateTime::Locale::CORE:match (opcode) |
| 1 | 1 | 1 | 539µs | 7.33ms | DateTime::Locale::_load_class_from_id |
| 1 | 1 | 1 | 99µs | 83.7ms | DateTime::Locale::BEGIN@140 |
| 1 | 1 | 1 | 61µs | 61µs | DateTime::Locale::BEGIN@6 |
| 1 | 1 | 1 | 37µs | 7.42ms | DateTime::Locale::load |
| 1 | 1 | 1 | 20µs | 387µs | DateTime::Locale::BEGIN@12 |
| 1 | 1 | 1 | 18µs | 23µs | DateTime::Locale::BEGIN@3 |
| 1 | 1 | 1 | 10µs | 25µs | DateTime::Locale::BEGIN@4 |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::_guess_id |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::_parse_id |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::ids |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::names |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::native_names |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::remove_alias |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package DateTime::Locale; | ||||
| 2 | |||||
| 3 | 3 | 29µs | 2 | 28µs | # spent 23µs (18+5) within DateTime::Locale::BEGIN@3 which was called:
# once (18µs+5µs) by DateTime::BEGIN@40 at line 3 # spent 23µs making 1 call to DateTime::Locale::BEGIN@3
# spent 5µs making 1 call to strict::import |
| 4 | 3 | 28µs | 2 | 40µs | # spent 25µs (10+15) within DateTime::Locale::BEGIN@4 which was called:
# once (10µs+15µs) by DateTime::BEGIN@40 at line 4 # spent 25µs making 1 call to DateTime::Locale::BEGIN@4
# spent 15µs making 1 call to warnings::import |
| 5 | |||||
| 6 | 3 | 142µs | 1 | 61µs | # spent 61µs within DateTime::Locale::BEGIN@6 which was called:
# once (61µs+0s) by DateTime::BEGIN@40 at line 6 # spent 61µs making 1 call to DateTime::Locale::BEGIN@6 |
| 7 | |||||
| 8 | # Loading this here isn't necessary, but it makes it easier to catch | ||||
| 9 | # syntax errors when testing. | ||||
| 10 | 3 | 143µs | 2 | 4.48ms | # spent 4.47ms (3.98+492µs) within DateTime::Locale::BEGIN@10 which was called:
# once (3.98ms+492µs) by DateTime::BEGIN@40 at line 10 # spent 4.47ms making 1 call to DateTime::Locale::BEGIN@10
# spent 5µs making 1 call to UNIVERSAL::import |
| 11 | 3 | 258µs | 2 | 11.2ms | # spent 11.2ms (11.1+93µs) within DateTime::Locale::BEGIN@11 which was called:
# once (11.1ms+93µs) by DateTime::BEGIN@40 at line 11 # spent 11.2ms making 1 call to DateTime::Locale::BEGIN@11
# spent 7µs making 1 call to UNIVERSAL::import |
| 12 | 3 | 711µs | 2 | 754µs | # spent 387µs (20+367) within DateTime::Locale::BEGIN@12 which was called:
# once (20µs+367µs) by DateTime::BEGIN@40 at line 12 # spent 387µs making 1 call to DateTime::Locale::BEGIN@12
# spent 367µs making 1 call to Exporter::import |
| 13 | |||||
| 14 | 1 | 800ns | our $VERSION = '0.45'; | ||
| 15 | |||||
| 16 | 1 | 300ns | my %Class; | ||
| 17 | 1 | 200ns | my %DataForID; | ||
| 18 | 1 | 100ns | my %NameToID; | ||
| 19 | 1 | 200ns | my %NativeNameToID; | ||
| 20 | 1 | 200ns | my %AliasToID; | ||
| 21 | 1 | 200ns | my %IDToExtra; | ||
| 22 | |||||
| 23 | 1 | 100ns | my %LoadCache; | ||
| 24 | |||||
| 25 | # spent 61.9ms (4.26+57.7) within DateTime::Locale::register which was called:
# once (4.26ms+57.7ms) by DateTime::Locale::BEGIN@140 at line 141 | ||||
| 26 | 1 | 2µs | my $class = shift; | ||
| 27 | |||||
| 28 | 1 | 1µs | %LoadCache = (); | ||
| 29 | |||||
| 30 | 1 | 4.04ms | 466 | 57.7ms | if ( ref $_[0] ) { # spent 57.7ms making 466 calls to DateTime::Locale::_register, avg 124µs/call |
| 31 | $class->_register(%$_) foreach @_; | ||||
| 32 | } | ||||
| 33 | else { | ||||
| 34 | $class->_register(@_); | ||||
| 35 | } | ||||
| 36 | } | ||||
| 37 | |||||
| 38 | # spent 57.7ms (28.3+29.4) within DateTime::Locale::_register which was called 466 times, avg 124µs/call:
# 466 times (28.3ms+29.4ms) by DateTime::Locale::register at line 30, avg 124µs/call | ||||
| 39 | 466 | 413µs | my $class = shift; | ||
| 40 | |||||
| 41 | 466 | 39.6ms | 466 | 28.6ms | my %p = validate( # spent 28.6ms making 466 calls to Params::Validate::_validate, avg 61µs/call # spent 2.20ms executing statements in 466 string evals (merged) |
| 42 | @_, { | ||||
| 43 | id => { type => SCALAR }, | ||||
| 44 | |||||
| 45 | en_language => { type => SCALAR }, | ||||
| 46 | en_script => { type => SCALAR, optional => 1 }, | ||||
| 47 | en_territory => { type => SCALAR, optional => 1 }, | ||||
| 48 | en_variant => { type => SCALAR, optional => 1 }, | ||||
| 49 | |||||
| 50 | native_language => { type => SCALAR, optional => 1 }, | ||||
| 51 | native_script => { type => SCALAR, optional => 1 }, | ||||
| 52 | native_territory => { type => SCALAR, optional => 1 }, | ||||
| 53 | native_variant => { type => SCALAR, optional => 1 }, | ||||
| 54 | |||||
| 55 | class => { type => SCALAR, optional => 1 }, | ||||
| 56 | replace => { type => SCALAR, default => 0 }, | ||||
| 57 | } | ||||
| 58 | ); | ||||
| 59 | |||||
| 60 | 466 | 465µs | my $id = $p{id}; | ||
| 61 | |||||
| 62 | 466 | 2.28ms | 466 | 766µs | die "'\@' or '=' are not allowed in locale ids" # spent 766µs making 466 calls to DateTime::Locale::CORE:match, avg 2µs/call |
| 63 | if $id =~ /[\@=]/; | ||||
| 64 | |||||
| 65 | 466 | 841µs | die | ||
| 66 | "You cannot replace an existing locale ('$id') unless you also specify the 'replace' parameter as true\n" | ||||
| 67 | if !delete $p{replace} && exists $DataForID{$id}; | ||||
| 68 | |||||
| 69 | 466 | 301µs | $p{native_language} = $p{en_language} | ||
| 70 | unless exists $p{native_language}; | ||||
| 71 | |||||
| 72 | 466 | 147µs | my @en_pieces; | ||
| 73 | 466 | 104µs | my @native_pieces; | ||
| 74 | 466 | 742µs | foreach my $p (qw( language script territory variant )) { | ||
| 75 | 1864 | 1.84ms | push @en_pieces, $p{"en_$p"} if exists $p{"en_$p"}; | ||
| 76 | 1864 | 2.38ms | push @native_pieces, $p{"native_$p"} if exists $p{"native_$p"}; | ||
| 77 | } | ||||
| 78 | |||||
| 79 | 466 | 929µs | $p{en_complete_name} = join ' ', @en_pieces; | ||
| 80 | 466 | 733µs | $p{native_complete_name} = join ' ', @native_pieces; | ||
| 81 | |||||
| 82 | 466 | 726µs | $DataForID{$id} = \%p; | ||
| 83 | |||||
| 84 | 466 | 781µs | $NameToID{ $p{en_complete_name} } = $id; | ||
| 85 | 466 | 750µs | $NativeNameToID{ $p{native_complete_name} } = $id; | ||
| 86 | |||||
| 87 | 466 | 2.68ms | $Class{$id} = $p{class} if defined exists $p{class}; | ||
| 88 | } | ||||
| 89 | |||||
| 90 | # spent 16.7ms (4.34+12.4) within DateTime::Locale::_registered_id which was called 422 times, avg 40µs/call:
# 422 times (4.34ms+12.4ms) by DateTime::Locale::add_aliases at line 108, avg 40µs/call | ||||
| 91 | 422 | 170µs | shift; | ||
| 92 | 422 | 13.6ms | 422 | 12.4ms | my ($id) = validate_pos( @_, { type => SCALAR } ); # spent 12.4ms making 422 calls to Params::Validate::_validate_pos, avg 29µs/call # spent 1.53ms executing statements in 422 string evals (merged) |
| 93 | |||||
| 94 | 422 | 292µs | return 1 if $AliasToID{$id}; | ||
| 95 | 422 | 1.50ms | return 1 if $DataForID{$id}; | ||
| 96 | |||||
| 97 | return 0; | ||||
| 98 | } | ||||
| 99 | |||||
| 100 | # spent 21.4ms (4.71+16.7) within DateTime::Locale::add_aliases which was called:
# once (4.71ms+16.7ms) by DateTime::Locale::BEGIN@140 at line 142 | ||||
| 101 | 1 | 1µs | shift; | ||
| 102 | |||||
| 103 | 1 | 2µs | %LoadCache = (); | ||
| 104 | |||||
| 105 | 1 | 220µs | my $aliases = ref $_[0] ? $_[0] : {@_}; | ||
| 106 | |||||
| 107 | 1 | 958µs | while ( my ( $alias, $id ) = each %$aliases ) { | ||
| 108 | 422 | 953µs | 422 | 16.7ms | die # spent 16.7ms making 422 calls to DateTime::Locale::_registered_id, avg 40µs/call |
| 109 | "Unregistered locale '$id' cannot be used as an alias target for $alias" | ||||
| 110 | unless __PACKAGE__->_registered_id($id); | ||||
| 111 | |||||
| 112 | 422 | 281µs | die "Can't alias an id to itself" | ||
| 113 | if $alias eq $id; | ||||
| 114 | |||||
| 115 | # check for overwrite? | ||||
| 116 | |||||
| 117 | 422 | 696µs | my %seen = ( $alias => 1, $id => 1 ); | ||
| 118 | 422 | 140µs | my $copy = $id; | ||
| 119 | 422 | 474µs | while ( $copy = $AliasToID{$copy} ) { | ||
| 120 | die "Creating an alias from $alias to $id would create a loop.\n" | ||||
| 121 | if $seen{$copy}; | ||||
| 122 | |||||
| 123 | $seen{$copy} = 1; | ||||
| 124 | } | ||||
| 125 | |||||
| 126 | 422 | 564µs | $AliasToID{$alias} = $id; | ||
| 127 | } | ||||
| 128 | } | ||||
| 129 | |||||
| 130 | sub remove_alias { | ||||
| 131 | shift; | ||||
| 132 | |||||
| 133 | %LoadCache = (); | ||||
| 134 | |||||
| 135 | my ($alias) = validate_pos( @_, { type => SCALAR } ); | ||||
| 136 | |||||
| 137 | return delete $AliasToID{$alias}; | ||||
| 138 | } | ||||
| 139 | |||||
| 140 | # spent 83.7ms (99µs+83.6) within DateTime::Locale::BEGIN@140 which was called:
# once (99µs+83.6ms) by DateTime::BEGIN@40 at line 143 | ||||
| 141 | 1 | 62µs | 2 | 62.0ms | __PACKAGE__->register( DateTime::Locale::Catalog->Locales() ); # spent 61.9ms making 1 call to DateTime::Locale::register
# spent 28µs making 1 call to DateTime::Locale::Catalog::Locales |
| 142 | 1 | 29µs | 2 | 21.6ms | __PACKAGE__->add_aliases( DateTime::Locale::Catalog->Aliases() ); # spent 21.4ms making 1 call to DateTime::Locale::add_aliases
# spent 239µs making 1 call to DateTime::Locale::Catalog::Aliases |
| 143 | 1 | 948µs | 1 | 83.7ms | } # spent 83.7ms making 1 call to DateTime::Locale::BEGIN@140 |
| 144 | |||||
| 145 | sub ids { wantarray ? keys %DataForID : [ keys %DataForID ] } | ||||
| 146 | sub names { wantarray ? keys %NameToID : [ keys %NameToID ] } | ||||
| 147 | |||||
| 148 | sub native_names { | ||||
| 149 | wantarray ? keys %NativeNameToID : [ keys %NativeNameToID ]; | ||||
| 150 | } | ||||
| 151 | |||||
| 152 | # These are hardcoded for backwards comaptibility with the | ||||
| 153 | # DateTime::Language code. | ||||
| 154 | 1 | 15µs | my %OldAliases = ( | ||
| 155 | 'Afar' => 'aa', | ||||
| 156 | 'Amharic' => 'am_ET', | ||||
| 157 | 'Austrian' => 'de_AT', | ||||
| 158 | 'Brazilian' => 'pt_BR', | ||||
| 159 | 'Czech' => 'cs_CZ', | ||||
| 160 | 'Danish' => 'da_DK', | ||||
| 161 | 'Dutch' => 'nl_NL', | ||||
| 162 | 'English' => 'en_US', | ||||
| 163 | 'French' => 'fr_FR', | ||||
| 164 | |||||
| 165 | # 'Gedeo' => undef, # XXX | ||||
| 166 | 'German' => 'de_DE', | ||||
| 167 | 'Italian' => 'it_IT', | ||||
| 168 | 'Norwegian' => 'no_NO', | ||||
| 169 | 'Oromo' => 'om_ET', # Maybe om_KE or plain om ? | ||||
| 170 | 'Portugese' => 'pt_PT', | ||||
| 171 | 'Sidama' => 'sid', | ||||
| 172 | 'Somali' => 'so_SO', | ||||
| 173 | 'Spanish' => 'es_ES', | ||||
| 174 | 'Swedish' => 'sv_SE', | ||||
| 175 | 'Tigre' => 'tig', | ||||
| 176 | 'TigrinyaEthiopian' => 'ti_ET', | ||||
| 177 | 'TigrinyaEritrean' => 'ti_ER', | ||||
| 178 | ); | ||||
| 179 | |||||
| 180 | # spent 7.42ms (37µs+7.39) within DateTime::Locale::load which was called:
# once (37µs+7.39ms) by DateTime::DefaultLocale at line 99 of DateTime.pm | ||||
| 181 | 1 | 1µs | my $class = shift; | ||
| 182 | 1 | 68µs | 1 | 60µs | my ($name) = validate_pos( @_, { type => SCALAR } ); # spent 60µs making 1 call to Params::Validate::_validate_pos # spent 8µs executing statements in string eval |
| 183 | |||||
| 184 | # Support RFC 3066 language tags, which use '-' instead of '_'. | ||||
| 185 | 1 | 2µs | $name =~ tr/-/_/; | ||
| 186 | |||||
| 187 | 1 | 800ns | my $key = $name; | ||
| 188 | |||||
| 189 | 1 | 1µs | return $LoadCache{$key} if exists $LoadCache{$key}; | ||
| 190 | |||||
| 191 | # Custom class registered by user | ||||
| 192 | 1 | 3µs | if ( $Class{$name} ) { | ||
| 193 | return $LoadCache{$key} | ||||
| 194 | = $class->_load_class_from_id( $name, $Class{$name} ); | ||||
| 195 | } | ||||
| 196 | |||||
| 197 | # special case for backwards compatibility with DT::Language | ||||
| 198 | 1 | 1µs | $name = $OldAliases{$name} if exists $OldAliases{$name}; | ||
| 199 | |||||
| 200 | 1 | 12µs | 1 | 7.33ms | if ( exists $DataForID{$name} || exists $AliasToID{$name} ) { # spent 7.33ms making 1 call to DateTime::Locale::_load_class_from_id |
| 201 | return $LoadCache{$key} = $class->_load_class_from_id($name); | ||||
| 202 | } | ||||
| 203 | |||||
| 204 | foreach my $h ( \%NameToID, \%NativeNameToID ) { | ||||
| 205 | return $LoadCache{$key} = $class->_load_class_from_id( $h->{$name} ) | ||||
| 206 | if exists $h->{$name}; | ||||
| 207 | } | ||||
| 208 | |||||
| 209 | if ( my $id = $class->_guess_id($name) ) { | ||||
| 210 | return $LoadCache{$key} = $class->_load_class_from_id($id); | ||||
| 211 | } | ||||
| 212 | |||||
| 213 | die "Invalid locale name or id: $name\n"; | ||||
| 214 | } | ||||
| 215 | |||||
| 216 | sub _guess_id { | ||||
| 217 | my $class = shift; | ||||
| 218 | my $name = shift; | ||||
| 219 | |||||
| 220 | # Strip off charset for LC_* ids : en_GB.UTF-8 etc | ||||
| 221 | $name =~ s/\..*$//; | ||||
| 222 | |||||
| 223 | my ( $language, $script, $territory, $variant ) = _parse_id($name); | ||||
| 224 | |||||
| 225 | my @guesses; | ||||
| 226 | |||||
| 227 | if ( defined $script ) { | ||||
| 228 | my $guess = join '_', lc $language, ucfirst lc $script; | ||||
| 229 | |||||
| 230 | push @guesses, $guess; | ||||
| 231 | |||||
| 232 | $guess .= '_' . uc $territory if defined $territory; | ||||
| 233 | |||||
| 234 | # version with script comes first | ||||
| 235 | unshift @guesses, $guess; | ||||
| 236 | } | ||||
| 237 | |||||
| 238 | if ( defined $variant ) { | ||||
| 239 | push @guesses, join '_', lc $language, uc $territory, uc $variant; | ||||
| 240 | } | ||||
| 241 | |||||
| 242 | if ( defined $territory ) { | ||||
| 243 | push @guesses, join '_', lc $language, uc $territory; | ||||
| 244 | } | ||||
| 245 | |||||
| 246 | push @guesses, lc $language; | ||||
| 247 | |||||
| 248 | foreach my $id (@guesses) { | ||||
| 249 | return $id | ||||
| 250 | if exists $DataForID{$id} || exists $AliasToID{$id}; | ||||
| 251 | } | ||||
| 252 | } | ||||
| 253 | |||||
| 254 | sub _parse_id { | ||||
| 255 | $_[0] =~ /([a-z]+) # id | ||||
| 256 | (?: _([A-Z][a-z]+) )? # script - Title Case - optional | ||||
| 257 | (?: _([A-Z]+) )? # territory - ALL CAPS - optional | ||||
| 258 | (?: _([A-Z]+) )? # variant - ALL CAPS - optional | ||||
| 259 | /x; | ||||
| 260 | |||||
| 261 | return $1, $2, $3, $4; | ||||
| 262 | } | ||||
| 263 | |||||
| 264 | # spent 7.33ms (539µs+6.79) within DateTime::Locale::_load_class_from_id which was called:
# once (539µs+6.79ms) by DateTime::Locale::load at line 200 | ||||
| 265 | 1 | 900ns | my $class = shift; | ||
| 266 | 1 | 800ns | my $id = shift; | ||
| 267 | 1 | 500ns | my $real_class = shift; | ||
| 268 | |||||
| 269 | # We want the first alias for which there is data, even if it has | ||||
| 270 | # no corresponding .pm file. There may be multiple levels of | ||||
| 271 | # alias to go through. | ||||
| 272 | 1 | 500ns | my $data_id = $id; | ||
| 273 | 1 | 2µs | while ( exists $AliasToID{$data_id} && !exists $DataForID{$data_id} ) { | ||
| 274 | $data_id = $AliasToID{$data_id}; | ||||
| 275 | } | ||||
| 276 | |||||
| 277 | 1 | 2µs | $real_class ||= "DateTime::Locale::$data_id"; | ||
| 278 | |||||
| 279 | 1 | 12µs | 1 | 2µs | unless ( $real_class->can('new') ) { # spent 2µs making 1 call to UNIVERSAL::can |
| 280 | 1 | 28µs | eval "require $real_class"; # spent 115µs executing statements in string eval | ||
| 281 | |||||
| 282 | 1 | 1µs | die $@ if $@; | ||
| 283 | } | ||||
| 284 | |||||
| 285 | my $locale = $real_class->new( | ||||
| 286 | 1 | 32µs | 1 | 706µs | %{ $DataForID{$data_id} }, # spent 706µs making 1 call to DateTime::Locale::Base::new |
| 287 | id => $id, | ||||
| 288 | ); | ||||
| 289 | |||||
| 290 | 1 | 700ns | return $locale if $DateTime::Locale::InGenerator; | ||
| 291 | |||||
| 292 | 1 | 14µs | 1 | 3µs | if ( $locale->can('cldr_version') ) { # spent 3µs making 1 call to UNIVERSAL::can |
| 293 | 1 | 2µs | 1 | 1µs | my $object_version = $locale->cldr_version(); # spent 1µs making 1 call to DateTime::Locale::en_US::cldr_version |
| 294 | 1 | 6µs | 1 | 3µs | my $catalog_version = DateTime::Locale::Catalog->CLDRVersion(); # spent 3µs making 1 call to DateTime::Locale::Catalog::CLDRVersion |
| 295 | |||||
| 296 | 1 | 2µs | if ( $object_version ne $catalog_version ) { | ||
| 297 | warn | ||||
| 298 | "Loaded $real_class, which is from an older version ($object_version)" | ||||
| 299 | . "of the CLDR database than this installation of" | ||||
| 300 | . "DateTime::Locale ($catalog_version).\n"; | ||||
| 301 | } | ||||
| 302 | } | ||||
| 303 | |||||
| 304 | 1 | 6µs | return $locale; | ||
| 305 | } | ||||
| 306 | |||||
| 307 | 1 | 11µs | 1; | ||
| 308 | |||||
| 309 | __END__ | ||||
# spent 766µs within DateTime::Locale::CORE:match which was called 466 times, avg 2µs/call:
# 466 times (766µs+0s) by DateTime::Locale::_register at line 62, avg 2µs/call |