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
|
|
14
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
102
|
|
6
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1792
|
|
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 $ns = ref($args_hr->{'get_locale_from'}); |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
0
|
|
|
|
if (exists $args_hr->{'get_locale_from'}{'locale'}) { |
|
|
0
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
$ns = exists $args_hr->{'get_locale_from'}{'locale'}{'id'} ? $args_hr->{'get_locale_from'}{'locale'}{'id'} : ref($args_hr->{'get_locale_from'}{'locale'}); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif ($ns =~ m{^DateTime::Locale::} && exists $args_hr->{'get_locale_from'}{'id'}) { |
55
|
0
|
|
|
|
|
|
$ns = $args_hr->{'get_locale_from'}{'id'}; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
($args_hr->{'get_locale_from'}) = reverse split /::/, $ns; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my ($short) = split(/[-_]+/,$args_hr->{'get_locale_from'}); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $final = ''; |
63
|
0
|
0
|
|
|
|
|
my @try = $args_hr->{'get_locale_from'} eq $short ? ($args_hr->{'get_locale_from'}) : ($args_hr->{'get_locale_from'}, $short); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
NS: |
66
|
0
|
|
|
|
|
|
for my $locale ( @try ) { |
67
|
0
|
0
|
|
|
|
|
if ( exists $args_hr->{'base_object'}{'locale_cache'}{ $locale } ) { |
68
|
0
|
0
|
|
|
|
|
if ( $args_hr->{'base_object'}{'locale_cache'}{ $locale } ) { |
69
|
0
|
|
|
|
|
|
return $locale; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
0
|
|
|
|
|
|
next NS; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$args_hr->{'locale_ns_path'} =~ s{/$}{}; |
77
|
0
|
|
|
|
|
|
my $path = "$args_hr->{'locale_ns_path'}/$locale\.pm"; |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
0
|
|
|
|
if( exists $INC{$path} || eval { $args_hr->{'loads'}{$locale}++; require $path } ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$final = $locale; |
81
|
0
|
|
|
|
|
|
$args_hr->{'base_object'}{'locale_cache'}{ $locale } = 1; |
82
|
0
|
|
|
|
|
|
last NS; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else { |
85
|
0
|
|
|
|
|
|
push @{$args_hr->{'errors'}{$locale}}, $@; |
|
0
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$args_hr->{'base_object'}{'locale_cache'}{ $locale } = ''; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return $final; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |