line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DateTime::Format::Human::Duration::Locale; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# require DateTime::Format::Locale; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
11
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
72
|
|
6
|
3
|
|
|
3
|
|
8
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1328
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub calc_locale { |
9
|
0
|
|
|
0
|
0
|
|
my ($span, $loc) = @_; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# DateTime::Format::Locale:: |
12
|
0
|
|
|
|
|
|
my $final = determine_locale_from({ |
13
|
|
|
|
|
|
|
'base_object' => $span, |
14
|
|
|
|
|
|
|
'get_locale_from' => $loc, |
15
|
|
|
|
|
|
|
'locale_ns_path' => 'DateTime/Format/Human/Duration/Locale', # DateTime::Format::Human::Duration::Locale |
16
|
|
|
|
|
|
|
}); |
17
|
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
|
if ($final) { |
19
|
0
|
0
|
|
|
|
|
return $final if ref $final; # returned 'locale_cache' we created below |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
my $ns = "DateTime::Format::Human::Duration::Locale::$final"; |
22
|
|
|
|
|
|
|
# get_human_span_from_units_array has been deprecated, but we'll |
23
|
|
|
|
|
|
|
# still support it. |
24
|
0
|
0
|
|
|
|
|
if ( $ns->can('get_human_span_from_units_array') ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
$span->{'locale_cache'}{ $final } = $ns; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
elsif ( $ns->can('get_human_span_from_units') ) { |
28
|
0
|
|
|
|
|
|
$span->{'locale_cache'}{ $final } = $ns; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
elsif ( my $sub = $ns->can('get_human_span_hashref') ) { |
31
|
0
|
|
|
|
|
|
$span->{'locale_cache'}{ $final } = $sub->(); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
if ( exists $span->{'locale_cache'}{ $final } ) { |
35
|
0
|
|
|
|
|
|
return $span->{'locale_cache'}{ $final }; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
return ''; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# DateTime::Format::Locale:: |
43
|
|
|
|
|
|
|
sub determine_locale_from { |
44
|
0
|
|
|
0
|
0
|
|
my ($args_hr) = @_; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
return '' if !$args_hr->{'get_locale_from'}; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
if (ref $args_hr->{'get_locale_from'}) { |
49
|
0
|
|
|
|
|
|
my $locale_obj; |
50
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::can($args_hr->{'get_locale_from'}, 'locale')) { |
51
|
0
|
|
|
|
|
|
$locale_obj = $args_hr->{'get_locale_from'}->locale; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
0
|
|
|
|
|
|
$locale_obj = $args_hr->{'get_locale_from'}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::can($locale_obj, 'code')) { |
|
|
0
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$args_hr->{'get_locale_from'} = $locale_obj->code; # DateTime::Locale v1 |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
elsif (UNIVERSAL::can($locale_obj, 'id')) { |
61
|
0
|
|
|
|
|
|
$args_hr->{'get_locale_from'} = $locale_obj->id; # DateTime::Locale v0 |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
0
|
|
|
|
|
|
my $ns = ref($args_hr->{'get_locale_from'}); |
65
|
0
|
|
|
|
|
|
($args_hr->{'get_locale_from'}) = reverse split /::/, $ns; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my ($short) = split(/[-_]+/,$args_hr->{'get_locale_from'}); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $final = ''; |
72
|
0
|
0
|
|
|
|
|
my @try = $args_hr->{'get_locale_from'} eq $short ? ($args_hr->{'get_locale_from'}) : ($args_hr->{'get_locale_from'}, $short); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
NS: |
75
|
0
|
|
|
|
|
|
for my $locale ( @try ) { |
76
|
0
|
0
|
|
|
|
|
if ( exists $args_hr->{'base_object'}{'locale_cache'}{ $locale } ) { |
77
|
0
|
0
|
|
|
|
|
if ( $args_hr->{'base_object'}{'locale_cache'}{ $locale } ) { |
78
|
0
|
|
|
|
|
|
return $locale; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
else { |
81
|
0
|
|
|
|
|
|
next NS; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$args_hr->{'locale_ns_path'} =~ s{/$}{}; |
86
|
0
|
|
|
|
|
|
my $path = "$args_hr->{'locale_ns_path'}/$locale\.pm"; |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
0
|
|
|
|
if( exists $INC{$path} || eval { $args_hr->{'loads'}{$locale}++; require $path } ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$final = $locale; |
90
|
0
|
|
|
|
|
|
$args_hr->{'base_object'}{'locale_cache'}{ $locale } = 1; |
91
|
0
|
|
|
|
|
|
last NS; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
else { |
94
|
0
|
|
|
|
|
|
push @{$args_hr->{'errors'}{$locale}}, $@; |
|
0
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
$args_hr->{'base_object'}{'locale_cache'}{ $locale } = ''; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
return $final; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |