DateTimeX/Lite/Locale.pm

filter: Statementstmt 77.3% 167 / 216 Branchbran 66.1% 45 / 68 Conditioncond 50.0% 4 / 8 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 62.9% 39 / 62 Podpod 0.0% 0 / 41 totaltotal 64.2% 257 / 400 CC 40 SCAR 14.0
CC
40
Cov
74%
_convert_to_strftime
12.0
_cldr_to_strftime
12.0
_convert
12.0
CRAP 4.1
« DateTimeX/Lite/Overload.pm ↑ Summary DateTimeX/Lite/Duration.pm »
1 # $Id: Locale.pm 30361 2009-02-20 08:13:39Z tokuhirom $
2  
3 package DateTimeX::Lite::Locale;
4 62 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 62 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 62 ▶use File::ShareDir qw(dist_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 62 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 62 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 62 our %CachedLocales;
11 62 our %Aliases;
12  
13 {
14 62 my $db = dist_file('DateTimeX-Lite', 'DateTimeX/Lite/Locale/Aliases.dat');
15 62 ▶ my $aliases = do $db
Branch: 1 branch
BranchTrueFalseTotal
my $aliases = do $db or die "cannot load alias database" 62 0 62
16 or die "cannot load alias database";
17 62 %Aliases = %$aliases;
18 }
19  
20 508 ▶sub _load_locale {
Subroutine _load_locale: called CC=10 SCAR=23.0
21 508 my $name = shift;
22  
23 # XXX - original comment as follows:
24 # Support RFC 3066 language tags, which use '-' instead of '_'
25 508 $name =~ tr/-/_/;
26  
27 # Strip off charset for LC_* ids : en_GB.UTF-8 etc
28 508 $name =~ s/\..*$//;
29  
30 508 my $original = $name;
31 508 ▶ while (exists $Aliases{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $DateTimeX::Lite::Locale::Aliases{$name}) 10 508 518
32 10 $name = $Aliases{$name};
33 }
34  
35 508 my ($language, $script, $territory, $variant ) = _parse_id($name);
36  
37 508 my @guesses;
38  
39 508 ▶ if ( defined $script )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $script) 61 447 508
40 {
41 61 my $guess = join '_', lc $language, ucfirst lc $script;
42  
43 61 push @guesses, $guess;
44  
45 61 ▶ $guess .= '_' . uc $territory if defined $territory;
Branch: 1 branch
BranchTrueFalseTotal
if defined $territory 38 23 61
46  
47 # version with script comes first
48 61 unshift @guesses, $guess;
49 }
50  
51 508 ▶ if ( defined $variant )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $variant) 5 503 508
52 {
53 5 push @guesses,
54 join '_', lc $language, uc $territory, uc $variant;
55 }
56  
57 508 ▶ if ( defined $territory )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $territory) 333 175 508
58 {
59 333 push @guesses,
60 join '_', lc $language, uc $territory;
61 }
62  
63 508 push @guesses, lc $language;
64  
65 508 foreach my $id (@guesses) {
66 508 my $h;
67 508 $h = do "DateTimeX/Lite/Locale/$id.dat";
68 508 ▶ if (! $@ && $h) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $@ and $h) 506 2 508
Condition66%2/3
not $@ and $h
!ll&&!rl&&r
02506
MC/DC50%1/2
not $@ and $h
not $@ $h
Truth table66%2/3
not(A) and B
A= not $@B= $h
ABresult
0X0
100
111
69 506 ▶ $h->{id} = $original if $original ne $name;
Branch: 1 branch
BranchTrueFalseTotal
if $original ne $name 8 498 506
70 506 return $h;
71 }
72 }
73 2 return ();
74 }
75  
76 5084 ▶sub load {
Subroutine load: called CC=3 SCAR=11.0
Pod undocumented
77 5084 my ($class, $name) = @_;
78  
79 5084 ▶ return $CachedLocales{$name} if $CachedLocales{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $DateTimeX::Lite::Locale::CachedLocales{$name} 4576 508 5084
80  
81 508 my $conf = _load_locale($name);
82 508 ▶ if (! $conf) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conf) 2 506 508
83 2 Carp::croak("Invalid locale name or id: locale $name not found");
84 }
85 506 return $CachedLocales{$name} = $class->new(%$conf);
86 }
87  
88 62 ▶use List::MoreUtils ();
Subroutine BEGIN: called CC=1 SCAR=0.0
89  
90 BEGIN
91 62 ▶{
Subroutine BEGIN: called CC=2 SCAR=6.9
92 62 foreach my $field ( qw( id en_complete_name native_complete_name
93 en_language en_script en_territory en_variant
94 native_language native_script native_territory native_variant
95 )
96 )
97 {
98 # remove leading 'en_' for method name
99 682 (my $meth_name = $field) =~ s/^en_//;
100  
101 # also remove 'complete_'
102 682 $meth_name =~ s/complete_//;
103  
104 62 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
105 682 ▶ *{$meth_name} = sub { $_[0]->{$field} } }
Subroutine __ANON__: called CC=1 SCAR=0.0
106 }
107  
108 sub new
109 506 ▶{
Subroutine new: called CC=5 SCAR=16.1
Pod undocumented
110 506 my $class = shift;
111  
112 # By making the default format lengths part of the object's hash
113 # key, it allows them to be settable.
114 506 my $self = bless { @_,
115 default_date_format_length => 'medium',
116 default_time_format_length => 'medium',
117 }, $class;
118  
119 $self->{native_language} = $self->{en_language}
120 506 ▶ unless exists $self->{native_language};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"native_language"} 42 464 506
121
122 506 my @en_pieces;
123 my @native_pieces;
124 506 foreach my $p ( qw( language script territory variant ) )
125 {
126 2024 ▶ push @en_pieces, $self->{"en_$p"} if exists $self->{"en_$p"};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$self{"en_$p"} 934 1090 2024
127 2024 ▶ push @native_pieces, $self->{"native_$p"} if exists $self->{"native_$p"};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$self{"native_$p"} 861 1163 2024
128 }
129  
130 506 $self->{en_complete_name} = join ' ', @en_pieces;
131 506 $self->{native_complete_name} = join ' ', @native_pieces;
132  
133 506 return $self;
134 }
135  
136 3 ▶sub language_id { ( DateTimeX::Lite::Locale::_parse_id( $_[0]->id ) )[0] }
Subroutine language_id: called CC=1 SCAR=0.0
Pod undocumented
137 1 ▶sub script_id { ( DateTimeX::Lite::Locale::_parse_id( $_[0]->id ) )[1] }
Subroutine script_id: called CC=1 SCAR=0.0
Pod undocumented
138 4 ▶sub territory_id { ( DateTimeX::Lite::Locale::_parse_id( $_[0]->id ) )[2] }
Subroutine territory_id: called CC=1 SCAR=0.0
Pod undocumented
139 3 ▶sub variant_id { ( DateTimeX::Lite::Locale::_parse_id( $_[0]->id ) )[3] }
Subroutine variant_id: called CC=1 SCAR=0.0
Pod undocumented
140 sub _parse_id
141 519 ▶{
Subroutine _parse_id: called CC=1 SCAR=0.0
142 519 $_[0] =~ /([a-z]+) # id
143 (?: _([A-Z][a-z]+) )? # script - Title Case - optional
144 (?: _([A-Z]+) )? # territory - ALL CAPS - optional
145 (?: _([A-Z]+) )? # variant - ALL CAPS - optional
146 /x;
147  
148 519 return $1, $2, $3, $4;
149 }
150  
151  
152 62 my @FormatLengths = qw( short medium long full );
153  
154 3 ▶sub date_format_default {
Subroutine date_format_default: called CC=2 SCAR=7.4
Pod undocumented
155 3 my $default = $_[0]->default_date_format_length();
156 3 ▶ if (! $default) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($default) 0 3 3
157 0 die sprintf("DateTimeX::Lite::Locale %s did not return a proper value from default_date_format_length()", $_[0]->{id});
158 }
159 3 my $meth = "date_format_$default";
160 3 $_[0]->$meth();
161 }
162  
163 sub date_formats
164 448 ▶{
Subroutine date_formats: called CC=1 SCAR=0.0
Pod undocumented
165 return
166 448 { map { my $meth = 'date_format_' . $_;
167 1792 $_ => $_[0]->$meth() } @FormatLengths }
168 }
169  
170 sub time_format_default
171 3 ▶{
Subroutine time_format_default: called CC=2 SCAR=7.4
Pod undocumented
172 3 my $default = $_[0]->default_time_format_length();
173 3 ▶ if (! $default) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($default) 0 3 3
174 0 die sprintf("DateTimeX::Lite::Locale %s did not return a proper value from default_time_format_length()", $_[0]->{name});
175 }
176 3 my $meth = "time_format_$default";
177 3 $_[0]->$meth();
178 }
179  
180 sub time_formats
181 448 ▶{
Subroutine time_formats: called CC=1 SCAR=0.0
Pod undocumented
182 return
183 448 { map { my $meth = 'time_format_' . $_;
184 1792 $_ => $_[0]->$meth() } @FormatLengths }
185 }
186  
187 sub format_for
188 44 ▶{
Subroutine format_for: called CC=2 SCAR=7.0
Pod undocumented
189 44 my $self = shift;
190 44 my $for = shift;
191  
192 44 my $meth = '_format_for_' . $for;
193  
194 44 ▶ return unless $self->can($meth);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($meth) 0 44 44
195  
196 44 return $self->$meth();
197 }
198  
199 sub available_formats
200 0 ▶{
Subroutine available_formats: not called CC=2 SCAR=17.9
Pod undocumented
201 0 my $self = shift;
202  
203 # The various parens seem to be necessary to force uniq() to see
204 # the caller's list context. Go figure.
205 0 ▶ my @uniq = List::MoreUtils::uniq( map { keys %{ $_->_available_formats() || {} } }
Condition0%0/2
$_->_available_formats || {}
l!l
00
MC/DC0%0/1
$_->_available_formats || {}
$_->_available_formats
Truth table0%0/2
A
A= $_->_available_formats
Aresult
11
00
206 Class::ISA::self_and_super_path( ref $self )
207 );
208  
209 # Doing the sort in the same expression doesn't work under 5.6.x.
210 0 return sort @uniq;
211 }
212  
213 # Just needed for the above method.
214 0 ▶sub _available_formats { }
Subroutine _available_formats: not called CC=1 SCAR=0.0
215  
216 8 ▶sub default_date_format_length { $_[0]->{default_date_format_length} }
Subroutine default_date_format_length: called CC=1 SCAR=0.0
Pod undocumented
217  
218 sub set_default_date_format_length
219 1 ▶{
Subroutine set_default_date_format_length: called CC=2 SCAR=7.1
Pod undocumented
220 1 my ($self, $l) = @_;
221 1 ▶ die unless $l =~ /^(?:full|long|medium|short)$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $l =~ /^(?:full|long|medium|short)$/i 0 1 1
222  
223 1 $self->{default_date_format_length} = lc $l;
224 }
225  
226 8 ▶sub default_time_format_length { $_[0]->{default_time_format_length} }
Subroutine default_time_format_length: called CC=1 SCAR=0.0
Pod undocumented
227  
228 sub set_default_time_format_length
229 1 ▶{
Subroutine set_default_time_format_length: called CC=2 SCAR=7.1
Pod undocumented
230 1 my ($self, $l) = @_;
231 1 ▶ die unless $l =~ /^(?:full|long|medium|short)$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $l =~ /^(?:full|long|medium|short)$/i 0 1 1
232  
233 1 $self->{default_time_format_length} = lc $l;
234 }
235  
236 62 for my $length ( qw( full long medium short ) )
237 {
238 248 my $key = 'datetime_format_' . $length;
239  
240 my $sub =
241 4 ▶ sub { my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
242  
243 4 ▶ return $self->{$key} if exists $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{$key} 0 4 4
244  
245 4 my $date_meth = 'date_format_' . $length;
246 4 my $time_meth = 'time_format_' . $length;
247  
248 4 return $self->{$key} = $self->_make_datetime_format( $date_meth, $time_meth );
249 248 };
250  
251 62 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
252 248 *{$key} = $sub;
253 }
254  
255 sub datetime_format_default
256 3 ▶{
Subroutine datetime_format_default: called CC=1 SCAR=0.0
Pod undocumented
257 3 my $self = shift;
258  
259 3 my $date_meth = 'date_format_' . $self->default_date_format_length();
260 3 my $time_meth = 'time_format_' . $self->default_time_format_length();
261  
262 3 return $self->_make_datetime_format( $date_meth, $time_meth );
263 }
264  
265 sub _make_datetime_format
266 7 ▶{
Subroutine _make_datetime_format: called CC=1 SCAR=0.0
267 7 my $self = shift;
268 7 my $date_meth = shift;
269 7 my $time_meth = shift;
270  
271 7 my $dt_format = $self->datetime_format();
272  
273 7 my $time = $self->$time_meth();
274 7 my $date = $self->$date_meth();
275  
276 7 $dt_format =~ s/\{0\}/$time/g;
277 7 $dt_format =~ s/\{1\}/$date/g;
278  
279 7 return $dt_format;
280 }
281  
282 sub prefers_24_hour_time
283 3 ▶{
Subroutine prefers_24_hour_time: called CC=3 SCAR=11.0
Pod undocumented
284 3 my $self = shift;
285  
286 return $self->{prefers_24_hour_time}
287 3 ▶ if exists $self->{prefers_24_hour_time};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"prefers_24_hour_time"} 1 2 3
288  
289 $self->{prefers_24_hour_time} =
290 2 ▶ $self->time_format_short() =~ /h|K/ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->time_format_short =~ /h|K/ ? : 1 1 2
291 }
292  
293 sub date_before_time
294 0 ▶{
Subroutine date_before_time: not called CC=2 SCAR=17.9
Pod undocumented
295 0 my $self = shift;
296  
297 0 my $dt_format = $self->datetime_format();
298  
299 0 ▶ return $dt_format =~ /\{1\}.*\{0\}/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$dt_format =~ /\{1\}.*\{0\}/ ? : 0 0 0
300 }
301  
302 sub date_parts_order
303 0 ▶{
Subroutine date_parts_order: not called CC=1 SCAR=6.9
Pod undocumented
304 0 my $self = shift;
305  
306 0 my $short = $self->date_format_short();
307  
308 0 $short =~ tr{dmyDMY}{}cd;
309 0 $short =~ tr{dmyDMY}{dmydmy}s;
310  
311 0 return $short;
312 }
313  
314 0 ▶sub full_date_format { $_[0]->_convert_to_strftime( $_[0]->date_format_full() ) }
Subroutine full_date_format: not called CC=1 SCAR=6.9
Pod undocumented
315 0 ▶sub long_date_format { $_[0]->_convert_to_strftime( $_[0]->date_format_long() ) }
Subroutine long_date_format: not called CC=1 SCAR=6.9
Pod undocumented
316 0 ▶sub medium_date_format { $_[0]->_convert_to_strftime( $_[0]->date_format_medium() ) }
Subroutine medium_date_format: not called CC=1 SCAR=6.9
Pod undocumented
317 0 ▶sub short_date_format { $_[0]->_convert_to_strftime( $_[0]->date_format_short() ) }
Subroutine short_date_format: not called CC=1 SCAR=6.9
Pod undocumented
318 0 ▶sub default_date_format { $_[0]->_convert_to_strftime( $_[0]->date_format_default() ) }
Subroutine default_date_format: not called CC=1 SCAR=6.9
Pod undocumented
319  
320 0 ▶sub full_time_format { $_[0]->_convert_to_strftime( $_[0]->time_format_full() ) }
Subroutine full_time_format: not called CC=1 SCAR=6.9
Pod undocumented
321 0 ▶sub long_time_format { $_[0]->_convert_to_strftime( $_[0]->time_format_long() ) }
Subroutine long_time_format: not called CC=1 SCAR=6.9
Pod undocumented
322 0 ▶sub medium_time_format { $_[0]->_convert_to_strftime( $_[0]->time_format_medium() ) }
Subroutine medium_time_format: not called CC=1 SCAR=6.9
Pod undocumented
323 0 ▶sub short_time_format { $_[0]->_convert_to_strftime( $_[0]->time_format_short() ) }
Subroutine short_time_format: not called CC=1 SCAR=6.9
Pod undocumented
324 0 ▶sub default_time_format { $_[0]->_convert_to_strftime( $_[0]->time_format_default() ) }
Subroutine default_time_format: not called CC=1 SCAR=6.9
Pod undocumented
325  
326 0 ▶sub full_datetime_format { $_[0]->_convert_to_strftime( $_[0]->datetime_format_full() ) }
Subroutine full_datetime_format: not called CC=1 SCAR=6.9
Pod undocumented
327 0 ▶sub long_datetime_format { $_[0]->_convert_to_strftime( $_[0]->datetime_format_long() ) }
Subroutine long_datetime_format: not called CC=1 SCAR=6.9
Pod undocumented
328 0 ▶sub medium_datetime_format { $_[0]->_convert_to_strftime( $_[0]->datetime_format_medium() ) }
Subroutine medium_datetime_format: not called CC=1 SCAR=6.9
Pod undocumented
329 0 ▶sub short_datetime_format { $_[0]->_convert_to_strftime( $_[0]->datetime_format_short() ) }
Subroutine short_datetime_format: not called CC=1 SCAR=6.9
Pod undocumented
330 0 ▶sub default_datetime_format { $_[0]->_convert_to_strftime( $_[0]->datetime_format_default() ) }
Subroutine default_datetime_format: not called CC=1 SCAR=6.9
Pod undocumented
331  
332 # Older versions of DateTime.pm will not pass in the $cldr_ok flag, so
333 # we will give them the converted-to-strftime pattern (bugs and all).
334 sub _convert_to_strftime
335 0 ▶{
Subroutine _convert_to_strftime: not called CC=3 SCAR=24.8
336 0 my $self = shift;
337 0 my $pattern = shift;
338 0 my $cldr_ok = shift;
339  
340 0 ▶ return $pattern if $cldr_ok;
Branch: 1 branch
BranchTrueFalseTotal
if $cldr_ok 0 0 0
341  
342 return $self->{_converted_patterns}{$pattern}
343 0 ▶ if exists $self->{_converted_patterns}{$pattern};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_converted_patterns"}{$pattern} 0 0 0
344  
345 0 return $self->{_converted_patterns}{$pattern} = $self->_cldr_to_strftime($pattern);
346 }
347  
348 {
349 62 my @JavaPatterns =
350 ( qr/G/ => '{era}',
351 qr/yyyy/ => '{ce_year}',
352 qr/y/ => 'y',
353 qr/u/ => 'Y',
354 qr/MMMM/ => 'B',
355 qr/MMM/ => 'b',
356 qr/MM/ => 'm',
357 qr/M/ => '{month}',
358 qr/dd/ => 'd',
359 qr/d/ => '{day}',
360 qr/hh/ => 'l',
361 qr/h/ => '{hour_12}',
362 qr/HH/ => 'H',
363 qr/H/ => '{hour}',
364 qr/mm/ => 'M',
365 qr/m/ => '{minute}',
366 qr/ss/ => 'S',
367 qr/s/ => '{second}',
368 qr/S/ => 'N',
369 qr/EEEE/ => 'A',
370 qr/E/ => 'a',
371 qr/D/ => 'j',
372 qr/F/ => '{weekday_of_month}',
373 qr/w/ => 'V',
374 qr/W/ => '{week_month}',
375 qr/a/ => 'p',
376 qr/k/ => '{hour_1}',
377 qr/K/ => '{hour_12_0}',
378 qr/z/ => '{time_zone_long_name}',
379 );
380  
381 sub _cldr_to_strftime
382 0 ▶ {
Subroutine _cldr_to_strftime: not called CC=3 SCAR=24.8
383 0 shift;
384 0 my $simple = shift;
385  
386 0 $simple =~
387 s/(G+|y+|u+|M+|d+|h+|H+|m+|s+|S+|E+|D+|F+|w+|W+|a+|k+|K+|z+)|'((?:[^']|'')*)'/
388 0 ▶ $2 ? _stringify($2) : $1 ? _convert($1) : "'"/eg;
Branch: 2 branches
BranchTrueFalseTotal
$2 ? : 0 0 0
$1 ? : 0 0 0
389  
390 0 return $simple;
391 }
392  
393 sub _convert
394 0 ▶ {
Subroutine _convert: not called CC=3 SCAR=24.8
395 0 my $simple = shift;
396  
397 0 ▶ for ( my $x = 0; $x < @JavaPatterns; $x += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($x < @JavaPatterns) 0 0 0
398 {
399 0 ▶ return '%' . $JavaPatterns[ $x + 1 ] if $simple =~ /$JavaPatterns[$x]/;
Branch: 1 branch
BranchTrueFalseTotal
if $simple =~ /$JavaPatterns[$x]/ 0 0 0
400 }
401  
402 0 die "**Dont know $simple***";
403 }
404  
405 sub _stringify
406 0 ▶ {
Subroutine _stringify: not called CC=1 SCAR=6.9
407 0 my $string = shift;
408  
409 0 $string =~ s/%(?:[^%])/%%/g;
410 0 $string =~ s/\'\'/\'/g;
411  
412 0 return $string;
413 }
414 }
415  
416 62 foreach my $field (qw(
417 am_pm_abbreviated
418 date_format_full
419 date_format_long
420 date_format_medium
421 date_format_short
422 datetime_format
423 day_format_abbreviated
424 day_format_narrow
425 day_format_wide
426 day_stand_alone_abbreviated
427 day_stand_alone_narrow
428 day_stand_alone_wide
429 era_abbreviated
430 era_narrow
431 era_wide
432 first_day_of_week
433 month_format_abbreviated
434 month_format_narrow
435 month_format_wide
436 month_stand_alone_abbreviated
437 month_stand_alone_narrow
438 month_stand_alone_wide
439 quarter_format_abbreviated
440 quarter_format_narrow
441 quarter_format_wide
442 quarter_stand_alone_abbreviated
443 quarter_stand_alone_narrow
444 quarter_stand_alone_wide
445 time_format_full
446 time_format_long
447 time_format_medium
448 time_format_short
449 _format_for_Hm
450 _format_for_Hms
451 _format_for_M
452 _format_for_MEd
453 _format_for_MMM
454 _format_for_MMMEd
455 _format_for_MMMMEd
456 _format_for_MMMMd
457 _format_for_MMMd
458 _format_for_MMdd
459 _format_for_Md
460 _format_for_d
461 _format_for_hm
462 _format_for_ms
463 _format_for_y
464 _format_for_yM
465 _format_for_yMEd
466 _format_for_yMMM
467 _format_for_yMMMEd
468 _format_for_yMMMM
469 _format_for_yQ
470 _format_for_yQQQ
471 _format_for_yyMMM
472 _format_for_yyyyMM
473 _format_for_yyyyMMMM
474 )) {
475 62 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
476 3534 ▶ *{$field} = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
477 31383 my $v = $_[0]->{$field};
478 # XXX - This SUCKS. I need to fix up update-locale.pl to return
479 # the value from the other aliases method
480 31383 ▶ if (defined $v && $v =~ /^alias:([^:]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v and $v =~ /^alias:([^:]+)$/) 1117 30266 31383
Condition66%2/3
defined $v and $v =~ /^alias:([^:]+)$/
!ll&&!rl&&r
0302661117
MC/DC50%1/2
defined $v and $v =~ /^alias:([^:]+)$/
defined $v $v =~ /^alias:([^:]+)$/
Truth table66%2/3
A and B
A= defined $vB= $v =~ /^alias:([^:]+)$/
ABresult
0X0
100
111
481 1117 return $_[0]->$1;
482 }
483 30266 return $v;
484 }
485 3534 }
486  
487 5376 ▶sub month_name { $_[0]->month_format_wide()->[ $_[1]->month - 1 ] }
Subroutine month_name: called CC=1 SCAR=0.0
Pod undocumented
488 5376 ▶sub month_abbreviation { $_[0]->month_format_abbreviated()->[ $_[1]->month - 1 ] }
Subroutine month_abbreviation: called CC=1 SCAR=0.0
Pod undocumented
489 3136 ▶sub day_name { $_[0]->day_format_wide()->[ $_[1]->day_of_week - 1 ] }
Subroutine day_name: called CC=1 SCAR=0.0
Pod undocumented
490 3136 ▶sub day_abbreviation { $_[0]->day_format_abbreviated->[ $_[1]->day_of_week - 1 ] }
Subroutine day_abbreviation: called CC=1 SCAR=0.0
Pod undocumented
491  
492  
493 4 ▶sub add_aliases {
Subroutine add_aliases: called CC=6 SCAR=18.0
Pod undocumented
494 4 my $self = shift;
495 4 ▶ my $aliases = ref $_[0] ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 4 4
496  
497 4 ▶ while ( my ( $alias, $id ) = each %$aliases )
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$aliases) 4 3 7
498 {
499 4 ▶ die "Can't alias an id to itself"
Branch: 1 branch
BranchTrueFalseTotal
if $alias eq $id 0 4 4
500 if $alias eq $id;
501  
502 # check for overwrite?
503  
504 4 my %seen = ( $alias => 1, $id => 1 );
505 4 my $copy = $id;
506 4 ▶ while ( $copy = $Aliases{$copy} )
Branch: 1 branch
BranchTrueFalseTotal
if ($copy = $DateTimeX::Lite::Locale::Aliases{$copy}) 4 3 7
507 {
508 die "Creating an alias from $alias to $id would create a loop.\n"
509 4 ▶ if $seen{$copy};
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$copy} 1 3 4
510  
511 3 $seen{$copy} = 1;
512 }
513 3 $Aliases{$alias} = $id;
514 }
515 }
516  
517 1 ▶sub remove_alias {
Subroutine remove_alias: called CC=1 SCAR=0.0
Pod undocumented
518 1 my ($self, $id) = @_;
519 1 delete $CachedLocales{$id};
520 1 delete $Aliases{$id};
521 }
522  
523  
524 62 1;
525  
526 __END__
« DateTimeX/Lite/Overload.pm ↑ Summary DateTimeX/Lite/Duration.pm »