| 1 | package DateTime::Locale; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use 5.008004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 17 | our $VERSION = '1.47'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 17 | ▶ | use DateTime::Locale::Data; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 17 | ▶ | use DateTime::Locale::FromData; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 17 | ▶ | use DateTime::Locale::Util qw( parse_locale_code ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 17 | ▶ | use Params::ValidationCompiler 0.13 qw( validation_for ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 17 | ▶ | use Specio::Library::String; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 17 | my %Class; | |||||||||||||||||||||||||||
| 18 | my %DataForCode; | ||||||||||||||||||||||||||||
| 19 | 17 | my %NameToCode; | |||||||||||||||||||||||||||
| 20 | 17 | my %NativeNameToCode; | |||||||||||||||||||||||||||
| 21 | 17 | my %UserDefinedAlias; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 17 | my %LoadCache; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 8 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 8 | my $class = shift; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 8 | %LoadCache = (); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 8 | ▶ | if ( ref $_[0] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 2 | $class->_register(%$_) foreach @_; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | else { | ||||||||||||||||||||||||||||
| 34 | 6 | $class->_register(@_); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 9 | ▶ | sub _register { | ||||||||||||||||||||||||||
|
Subroutine
_register: called CC=9 SCAR=22.3
| |||||||||||||||||||||||||||||
| 39 | 9 | shift; | |||||||||||||||||||||||||||
| 40 | 9 | my %p = @_; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 9 | my $id = $p{id}; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 9 | ▶ | die q{'\@' or '=' are not allowed in locale ids} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | if $id =~ /[\@=]/; | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | die | ||||||||||||||||||||||||||||
| 48 | "You cannot replace an existing locale ('$id') unless you also specify the 'replace' parameter as true\n" | ||||||||||||||||||||||||||||
| 49 | 7 | ▶ | if !delete $p{replace} && exists $DataForCode{$id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not delete $p{"replace"} and exists $DataForCode{$id}
MC/DC0%0/2
not delete $p{"replace"} and exists $DataForCode{$id}
not delete $p{"replace"}
exists $DataForCode{$id}
Truth table33%1/3
not(A) and B
A= not delete $p{"replace"}B= exists $DataForCode{$id}
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | $p{native_language} = $p{en_language} | ||||||||||||||||||||||||||||
| 52 | 7 | ▶ | unless exists $p{native_language}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 7 | my @en_pieces; | |||||||||||||||||||||||||||
| 55 | my @native_pieces; | ||||||||||||||||||||||||||||
| 56 | 7 | foreach my $p (qw( language script territory variant )) { | |||||||||||||||||||||||||||
| 57 | 28 | ▶ | push @en_pieces, $p{"en_$p"} if exists $p{"en_$p"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 28 | ▶ | push @native_pieces, $p{"native_$p"} if exists $p{"native_$p"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 7 | $p{en_complete_name} = join q{ }, @en_pieces; | |||||||||||||||||||||||||||
| 62 | 7 | $p{native_complete_name} = join q{ }, @native_pieces; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 7 | $id =~ s/_/-/g; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 7 | $DataForCode{$id} = \%p; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 7 | $NameToCode{ $p{en_complete_name} } = $id; | |||||||||||||||||||||||||||
| 69 | 7 | $NativeNameToCode{ $p{native_complete_name} } = $id; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 7 | ▶ | $Class{$id} = $p{class} if defined exists $p{class}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1 | ▶ | sub register_from_data { | ||||||||||||||||||||||||||
|
Subroutine
register_from_data: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 1 | shift; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | %LoadCache = (); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | my %p = ref $_[0] ? %{ $_[0] } : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | my $code = $p{code}; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 1 | ▶ | die q{'\@' or '=' are not allowed in locale codes} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | if $code =~ /[\@=]/; | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 1 | $code =~ s/_/-/g; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1 | DateTime::Locale::Data::add_locale( $code, \%p ); | |||||||||||||||||||||||||||
| 89 | 1 | return $LoadCache{$code} = DateTime::Locale::FromData->new( \%p ); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 5 | ▶ | sub add_aliases { | ||||||||||||||||||||||||||
|
Subroutine
add_aliases: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 93 | 5 | shift; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 5 | %LoadCache = (); | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 5 | ▶ | my $aliases = ref $_[0] ? $_[0] : {@_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 5 | for my $alias ( keys %{$aliases} ) { | |||||||||||||||||||||||||||
| 100 | 5 | my $code = $aliases->{$alias}; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 5 | ▶ | die q{Can't alias an id to itself} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | if $alias eq $code; | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # check for overwrite? | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 4 | my %seen = ( $alias => 1, $code => 1 ); | |||||||||||||||||||||||||||
| 108 | 4 | my $copy = $code; | |||||||||||||||||||||||||||
| 109 | 4 | ▶ | while ( $copy = $UserDefinedAlias{$copy} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | die | ||||||||||||||||||||||||||||
| 111 | "Creating an alias from $alias to $code would create a loop.\n" | ||||||||||||||||||||||||||||
| 112 | 4 | ▶ | if $seen{$copy}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 3 | $seen{$copy} = 1; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 3 | $UserDefinedAlias{$alias} = $code; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 1 | ▶ | sub remove_alias { | ||||||||||||||||||||||||||
|
Subroutine
remove_alias: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 122 | 1 | shift; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1 | %LoadCache = (); | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 1 | my $alias = shift; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 1 | return delete $UserDefinedAlias{$alias}; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | # deprecated | ||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub ids { | ||||||||||||||||||||||||||
|
Subroutine
ids: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 133 | 0 | shift->codes; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | ## no critic (Variables::ProhibitPackageVars) | ||||||||||||||||||||||||||||
| 137 | 2 | ▶ | sub codes { | ||||||||||||||||||||||||||
|
Subroutine
codes: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | wantarray | ||||||||||||||||||||||||||||
| 139 | 2 | ▶ | ? keys %DateTime::Locale::Data::Codes | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | : [ keys %DateTime::Locale::Data::Codes ]; | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 1 | ▶ | sub names { | ||||||||||||||||||||||||||
|
Subroutine
names: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 144 | wantarray | ||||||||||||||||||||||||||||
| 145 | 1 | ▶ | ? keys %DateTime::Locale::Data::Names | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | : [ keys %DateTime::Locale::Data::Names ]; | ||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub native_names { | ||||||||||||||||||||||||||
|
Subroutine
native_names: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 150 | wantarray | ||||||||||||||||||||||||||||
| 151 | 0 | ▶ | ? keys %DateTime::Locale::Data::NativeNames | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | : [ keys %DateTime::Locale::Data::NativeNames ]; | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # These are hard-coded for backwards compatibility with the DateTime::Language | ||||||||||||||||||||||||||||
| 156 | # code. | ||||||||||||||||||||||||||||
| 157 | 17 | my %DateTimeLanguageAliases = ( | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | # 'Afar' => 'aa', | ||||||||||||||||||||||||||||
| 160 | 'Amharic' => 'am-ET', | ||||||||||||||||||||||||||||
| 161 | 'Austrian' => 'de-AT', | ||||||||||||||||||||||||||||
| 162 | 'Brazilian' => 'pt-BR', | ||||||||||||||||||||||||||||
| 163 | 'Czech' => 'cs-CZ', | ||||||||||||||||||||||||||||
| 164 | 'Danish' => 'da-DK', | ||||||||||||||||||||||||||||
| 165 | 'Dutch' => 'nl-NL', | ||||||||||||||||||||||||||||
| 166 | 'English' => 'en-US', | ||||||||||||||||||||||||||||
| 167 | 'French' => 'fr-FR', | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # 'Gedeo' => undef, # XXX | ||||||||||||||||||||||||||||
| 170 | 'German' => 'de-DE', | ||||||||||||||||||||||||||||
| 171 | 'Italian' => 'it-IT', | ||||||||||||||||||||||||||||
| 172 | 'Norwegian' => 'no-NO', | ||||||||||||||||||||||||||||
| 173 | 'Oromo' => 'om-ET', # Maybe om-KE or plain om ? | ||||||||||||||||||||||||||||
| 174 | 'Portuguese' => 'pt-PT', | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | # 'Sidama' => 'sid', | ||||||||||||||||||||||||||||
| 177 | 'Somali' => 'so-SO', | ||||||||||||||||||||||||||||
| 178 | 'Spanish' => 'es-ES', | ||||||||||||||||||||||||||||
| 179 | 'Swedish' => 'sv-SE', | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | # 'Tigre' => 'tig', | ||||||||||||||||||||||||||||
| 182 | 'TigrinyaEthiopian' => 'ti-ET', | ||||||||||||||||||||||||||||
| 183 | 'TigrinyaEritrean' => 'ti-ER', | ||||||||||||||||||||||||||||
| 184 | ); | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 17 | my %POSIXAliases = ( | |||||||||||||||||||||||||||
| 187 | C => 'en-US', | ||||||||||||||||||||||||||||
| 188 | POSIX => 'en-US', | ||||||||||||||||||||||||||||
| 189 | ); | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||
| 192 | 17 | my $validator = validation_for( | |||||||||||||||||||||||||||
| 193 | name => '_check_load_params', | ||||||||||||||||||||||||||||
| 194 | name_is_optional => 1, | ||||||||||||||||||||||||||||
| 195 | params => [ | ||||||||||||||||||||||||||||
| 196 | { type => t('NonEmptyStr') }, | ||||||||||||||||||||||||||||
| 197 | ], | ||||||||||||||||||||||||||||
| 198 | ); | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 993 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||
| 201 | 993 | my $class = shift; | |||||||||||||||||||||||||||
| 202 | 993 | my ($code) = $validator->(@_); | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | # We used to use underscores in codes instead of dashes. We want to | ||||||||||||||||||||||||||||
| 205 | # support both indefinitely. | ||||||||||||||||||||||||||||
| 206 | 993 | $code =~ tr/_/-/; | |||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | # Strip off charset for LC_* codes : en_GB.UTF-8 etc | ||||||||||||||||||||||||||||
| 209 | 993 | $code =~ s/\..*$//; | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 993 | ▶ | return $LoadCache{$code} if exists $LoadCache{$code}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 980 | ▶ | while ( exists $UserDefinedAlias{$code} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 3 | $code = $UserDefinedAlias{$code}; | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | $code = $DateTimeLanguageAliases{$code} | ||||||||||||||||||||||||||||
| 218 | 980 | ▶ | if exists $DateTimeLanguageAliases{$code}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | 980 | ▶ | $code = $POSIXAliases{$code} if exists $POSIXAliases{$code}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | $code = $DateTime::Locale::Data::ISO639Aliases{$code} | ||||||||||||||||||||||||||||
| 221 | 980 | ▶ | if exists $DateTime::Locale::Data::ISO639Aliases{$code}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 980 | ▶ | if ( exists $DateTime::Locale::Data::Codes{$code} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | 962 | return $class->_locale_object_for($code); | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 18 | ▶ | if ( exists $DateTime::Locale::Data::Names{$code} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | return $class->_locale_object_for( | ||||||||||||||||||||||||||||
| 229 | 2 | $DateTime::Locale::Data::Names{$code} ); | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 16 | ▶ | if ( exists $DateTime::Locale::Data::NativeNames{$code} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | return $class->_locale_object_for( | ||||||||||||||||||||||||||||
| 234 | 1 | $DateTime::Locale::Data::NativeNames{$code} ); | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 15 | ▶ | if ( my $locale = $class->_registered_locale_for($code) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 7 | return $locale; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 8 | ▶ | if ( my $guessed = $class->_guess_code($code) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | 6 | return $class->_locale_object_for($guessed); | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 2 | die "Invalid locale code or name: $code\n"; | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 17 | ▶ | sub _guess_code { | ||||||||||||||||||||||||||
|
Subroutine
_guess_code: called CC=8 SCAR=21.0
| |||||||||||||||||||||||||||||
| 250 | 8 | shift; | |||||||||||||||||||||||||||
| 251 | 8 | my $code = shift; | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 8 | my %codes = parse_locale_code($code); | |||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 8 | my @guesses; | |||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 8 | ▶ | if ( $codes{script} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | 1 | my $guess = join q{-}, $codes{language}, $codes{script}; | |||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 1 | push @guesses, $guess; | |||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 1 | ▶ | $guess .= q{-} . $codes{territory} if defined $codes{territory}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | # version with script comes first | ||||||||||||||||||||||||||||
| 265 | 1 | unshift @guesses, $guess; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 8 | ▶ | if ( $codes{variant} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | push @guesses, join q{-}, $codes{language}, $codes{territory}, | ||||||||||||||||||||||||||||
| 270 | 0 | $codes{variant}; | |||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 8 | ▶ | if ( $codes{territory} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 274 | 5 | push @guesses, join q{-}, $codes{language}, $codes{territory}; | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 8 | push @guesses, $codes{language}; | |||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 8 | for my $code (@guesses) { | |||||||||||||||||||||||||||
| 280 | return $code | ||||||||||||||||||||||||||||
| 281 | if exists $DateTime::Locale::Data::Codes{$code} | ||||||||||||||||||||||||||||
| 282 | 9 | ▶ | || exists $DateTime::Locale::Data::Names{$code}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $DateTime::Locale::Data::Codes{$code} or exists $DateTime::Locale::Data::Names{$code}
MC/DC50%1/2
exists $DateTime::Locale::Data::Codes{$code} or exists $DateTime::Locale::Data::Names{$code}
exists $DateTime::Locale::Data::Codes{$code}
exists $DateTime::Locale::Data::Names{$code}
Truth table66%2/3
A or B
A= exists $DateTime::Locale::Data::Codes{$code}B= exists $DateTime::Locale::Data::Names{$code}
| |||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 971 | ▶ | sub _locale_object_for { | ||||||||||||||||||||||||||
|
Subroutine
_locale_object_for: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 287 | 971 | shift; | |||||||||||||||||||||||||||
| 288 | 971 | my $code = shift; | |||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 971 | ▶ | my $data = DateTime::Locale::Data::locale_data($code) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | or return; | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | # We want to make a copy of the data just in case ... | ||||||||||||||||||||||||||||
| 294 | 971 | return $LoadCache{$code} = DateTime::Locale::FromData->new( \%{$data} ); | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 15 | ▶ | sub _registered_locale_for { | ||||||||||||||||||||||||||
|
Subroutine
_registered_locale_for: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||
| 298 | 15 | my $class = shift; | |||||||||||||||||||||||||||
| 299 | 15 | my $code = shift; | |||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | # Custom locale registered by user | ||||||||||||||||||||||||||||
| 302 | 15 | ▶ | if ( $Class{$code} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 303 | return $LoadCache{$code} | ||||||||||||||||||||||||||||
| 304 | 2 | = $class->_load_class_from_code( $code, $Class{$code} ); | |||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 13 | ▶ | if ( $DataForCode{$code} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | 5 | return $LoadCache{$code} = $class->_load_class_from_code($code); | |||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 8 | ▶ | if ( $NameToCode{$code} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | return $LoadCache{$code} | ||||||||||||||||||||||||||||
| 313 | 0 | = $class->_load_class_from_code( $NameToCode{$code} ); | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 8 | ▶ | if ( $NativeNameToCode{$code} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | return $LoadCache{$code} | ||||||||||||||||||||||||||||
| 318 | 0 | = $class->_load_class_from_code( $NativeNameToCode{$code} ); | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 7 | ▶ | sub _load_class_from_code { | ||||||||||||||||||||||||||
|
Subroutine
_load_class_from_code: called CC=8 SCAR=22.8
| |||||||||||||||||||||||||||||
| 323 | 7 | my $class = shift; | |||||||||||||||||||||||||||
| 324 | 7 | my $code = shift; | |||||||||||||||||||||||||||
| 325 | 7 | my $real_class = shift; | |||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | # We want the first alias for which there is data, even if it has | ||||||||||||||||||||||||||||
| 328 | # no corresponding .pm file. There may be multiple levels of | ||||||||||||||||||||||||||||
| 329 | # alias to go through. | ||||||||||||||||||||||||||||
| 330 | 7 | my $data_code = $code; | |||||||||||||||||||||||||||
| 331 | 7 | ▶ | while ( exists $UserDefinedAlias{$data_code} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $UserDefinedAlias{$data_code} and not exists $DataForCode{$data_code}
MC/DC0%0/2
exists $UserDefinedAlias{$data_code} and not exists $DataForCode{$data_code}
exists $UserDefinedAlias{$data_code}
not exists $DataForCode{$data_code}
Truth table33%1/3
A and not(B)
A= exists $UserDefinedAlias{$data_code}B= not exists $DataForCode{$data_code}
| |||||||||||||||||||||||||||||
| 332 | && !exists $DataForCode{$data_code} ) { | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 0 | $data_code = $UserDefinedAlias{$data_code}; | |||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 7 | ( my $underscore_code = $data_code ) =~ s/-/_/g; | |||||||||||||||||||||||||||
| 338 | 7 | ▶ | $real_class ||= "DateTime::Locale::$underscore_code"; | ||||||||||||||||||||||||||
|
Condition100%2/2
$real_class ||= "DateTime::Locale::$underscore_code"
MC/DC100%1/1
$real_class ||= "DateTime::Locale::$underscore_code"
$real_class
Truth table100%2/2
A
A= $real_class
| |||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 7 | ▶ | unless ( $real_class->can('new') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 341 | ## no critic (BuiltinFunctions::ProhibitStringyEval, ErrorHandling::RequireCheckingReturnValueOfEval) | ||||||||||||||||||||||||||||
| 342 | 0 | eval "require $real_class"; | |||||||||||||||||||||||||||
| 343 | 0 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | ## use critic | ||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | my $locale = $real_class->new( | ||||||||||||||||||||||||||||
| 348 | 7 | %{ $DataForCode{$data_code} }, | |||||||||||||||||||||||||||
| 349 | code => $code, | ||||||||||||||||||||||||||||
| 350 | ); | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 7 | ▶ | if ( $locale->can('cldr_version') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 353 | 1 | my $object_version = $locale->cldr_version; | |||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 1 | ▶ | if ( $object_version ne $DateTime::Locale::Data::CLDRVersion ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 356 | 1 | warn | |||||||||||||||||||||||||||
| 357 | "Loaded $real_class, which is from an older version ($object_version)" | ||||||||||||||||||||||||||||
| 358 | . ' of the CLDR database than this installation of' | ||||||||||||||||||||||||||||
| 359 | . " DateTime::Locale ($DateTime::Locale::Data::CLDRVersion).\n"; | ||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 7 | return $locale; | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | ## use critic | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | 17 | 1; | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | # ABSTRACT: Localization support for DateTime.pm | ||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | __END__ | ||||||||||||||||||||||||||||