line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DateTime::Language; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1944
|
use Class::Factory::Util; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Params::Validate qw( validate SCALAR ); |
7
|
|
|
|
|
|
|
use vars qw ( %ISOMap ); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# my %ISOMap; |
10
|
|
|
|
|
|
|
foreach my $set ( [ 'aa', 'aar' => 'Afar' ], |
11
|
|
|
|
|
|
|
[ 'am', 'amh' => 'Amharic' ], |
12
|
|
|
|
|
|
|
[ 'cz', 'ces', 'cze' => 'Czech' ], |
13
|
|
|
|
|
|
|
[ 'de', 'deu', 'ger' => 'German' ], |
14
|
|
|
|
|
|
|
[ 'de-at', 'deu-at', 'ger-at' => 'Austrian' ], |
15
|
|
|
|
|
|
|
[ 'dk', 'dan' => 'Danish' ], |
16
|
|
|
|
|
|
|
[ 'en', 'eng' => 'English' ], |
17
|
|
|
|
|
|
|
[ 'es', 'esl', 'spa' => 'Spanish' ], |
18
|
|
|
|
|
|
|
[ 'fr', 'fra', 'fre' => 'French' ], |
19
|
|
|
|
|
|
|
[ 'x-drs', 'sil-drs' => 'Gedeo' ], |
20
|
|
|
|
|
|
|
[ 'it', 'ita' => 'Italian' ], |
21
|
|
|
|
|
|
|
[ 'nl', 'dut', 'nla' => 'Dutch' ], |
22
|
|
|
|
|
|
|
[ 'no', 'nor' => 'Norwegian' ], |
23
|
|
|
|
|
|
|
[ 'om', 'orm' => 'Oromo' ], |
24
|
|
|
|
|
|
|
# not quite right, but better than failing |
25
|
|
|
|
|
|
|
[ 'pt', 'por' => 'Brazilian' ], |
26
|
|
|
|
|
|
|
[ 'pt-br', 'por-br' => 'Brazilian' ], |
27
|
|
|
|
|
|
|
[ 'sid' => 'Sidama' ], |
28
|
|
|
|
|
|
|
[ 'so', 'som' => 'Somali' ], |
29
|
|
|
|
|
|
|
[ 'sv', 'sve', 'swe' => 'Swedish' ], |
30
|
|
|
|
|
|
|
[ 'ti-et', 'tig-et' => 'TigrinyaEthiopian' ], |
31
|
|
|
|
|
|
|
[ 'ti-er', 'tig-er' => 'TigrinyaEritrean' ], |
32
|
|
|
|
|
|
|
) |
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
my $module = pop @$set; |
35
|
|
|
|
|
|
|
@ISOMap{ @$set } = ($module) x @$set; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# print "ISOMap: $ISOMap{sid}\n"; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub new |
41
|
|
|
|
|
|
|
{ |
42
|
|
|
|
|
|
|
my $class = shift; |
43
|
|
|
|
|
|
|
my %p = validate( @_, |
44
|
|
|
|
|
|
|
{ language => { type => SCALAR } }, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $real_class = $class->load( $p{language} ); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $obj = bless {}, $real_class; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$obj->_init; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return $obj; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub languages { $_[0]->subclasses } |
57
|
|
|
|
|
|
|
sub iso_codes { keys %ISOMap } |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub class_base |
60
|
|
|
|
|
|
|
{ |
61
|
|
|
|
|
|
|
"DateTime::Language"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub load |
66
|
|
|
|
|
|
|
{ |
67
|
|
|
|
|
|
|
my $class = shift; |
68
|
|
|
|
|
|
|
my $lang = shift; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $real_lang; |
71
|
|
|
|
|
|
|
if ( $lang =~ /^((?:x-)?\w\w\w?)(?:-\w\w\w?)?$/ ) |
72
|
|
|
|
|
|
|
{ |
73
|
|
|
|
|
|
|
$real_lang = |
74
|
|
|
|
|
|
|
( exists $ISOMap{$lang} ? |
75
|
|
|
|
|
|
|
$ISOMap{$lang} : |
76
|
|
|
|
|
|
|
$1 ? |
77
|
|
|
|
|
|
|
$ISOMap{$1} : |
78
|
|
|
|
|
|
|
undef |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
die "Unsupported or invalid ISO language code, $lang" |
82
|
|
|
|
|
|
|
unless defined $real_lang; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else |
85
|
|
|
|
|
|
|
{ |
86
|
|
|
|
|
|
|
$real_lang = $lang; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $real_class = $class->class_base."::$real_lang"; |
90
|
|
|
|
|
|
|
eval "use $real_class"; |
91
|
|
|
|
|
|
|
die $@ if $@; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# print "XLoading $real_class\n"; |
94
|
|
|
|
|
|
|
return $real_class; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _init |
98
|
|
|
|
|
|
|
{ |
99
|
|
|
|
|
|
|
my $self = shift; |
100
|
|
|
|
|
|
|
my $class = ref $self; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
foreach my $key ( qw( day_names day_abbreviations month_names |
103
|
|
|
|
|
|
|
month_abbreviations am_pm ordinal_suffixes |
104
|
|
|
|
|
|
|
month_numbers day_numbers |
105
|
|
|
|
|
|
|
) |
106
|
|
|
|
|
|
|
) |
107
|
|
|
|
|
|
|
{ |
108
|
|
|
|
|
|
|
my $var_name = join '', map { ucfirst } split /_/, $key; |
109
|
|
|
|
|
|
|
$var_name = 'AMPM' if $var_name eq 'AmPm'; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
no strict 'refs'; |
112
|
|
|
|
|
|
|
if ( $key =~ /numbers$/ ) |
113
|
|
|
|
|
|
|
{ |
114
|
|
|
|
|
|
|
$self->{$key} = \%{"$class\::$var_name"}; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
else |
117
|
|
|
|
|
|
|
{ |
118
|
|
|
|
|
|
|
$self->{$key} = \@{"$class\::$var_name"}; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub month_names { $_[0]->{month_names} } |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub month_name { $_[0]->{month_names}[ $_[1]->month_0 ] } |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub day_names { $_[0]->{day_names} } |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub day_name { $_[0]->{day_names}[ $_[1]->day_of_week_0 ] } |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub month_abbreviations { $_[0]->{month_abbreviations} } |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub month_abbreviation { $_[0]->{month_abbreviations}[ $_[1]->month_0 ] } |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub day_abbreviations { $_[0]->{day_abbreviations} } |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub day_abbreviation { $_[0]->{day_abbreviations}[ $_[1]->day_of_week_0 ] } |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub am_pm_list { $_[0]->{am_pm} } |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub am_pm { $_[0]->{am_pm}[ $_[1]->hour < 12 ? 0 : 1 ] } |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#sub preferred_datetime_format { '%m/%d/%y %H:%M:%S' } |
144
|
|
|
|
|
|
|
#sub preferred_date_format { '%m/%d/%y' } |
145
|
|
|
|
|
|
|
#sub preferred_time_format { '%H:%M:%S' } |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
__END__ |