line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Author: Slaven Rezic |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright (C) 2009,2010 Slaven Rezic. All rights reserved. |
7
|
|
|
|
|
|
|
# This package is free software; you can redistribute it and/or |
8
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Mail: slaven@rezic.de |
11
|
|
|
|
|
|
|
# WWW: http://www.rezic.de/eserte/ |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package Acme::Study::OS::DateLocales; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
25675
|
use 5.008; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
31
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
41
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
5
|
use base qw(Exporter); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
160
|
|
22
|
|
|
|
|
|
|
our @EXPORT = qw(weekday_and_month_names_dump); |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
2966
|
use Data::Dumper qw(Dumper); |
|
1
|
|
|
|
|
11079
|
|
|
1
|
|
|
|
|
100
|
|
25
|
1
|
|
|
1
|
|
1027
|
use File::Spec::Functions qw(file_name_is_absolute); |
|
1
|
|
|
|
|
1049
|
|
|
1
|
|
|
|
|
101
|
|
26
|
1
|
|
|
1
|
|
1177
|
use POSIX qw(strftime); |
|
1
|
|
|
|
|
8353
|
|
|
1
|
|
|
|
|
8
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub all_locales { |
29
|
0
|
|
|
0
|
0
|
|
my @res; |
30
|
0
|
0
|
|
|
|
|
if (_is_in_path("locale")) { |
31
|
0
|
0
|
|
|
|
|
open my $fh, "-|", "locale", "-a" |
32
|
|
|
|
|
|
|
or die $!; |
33
|
0
|
|
|
|
|
|
while(<$fh>) { |
34
|
0
|
|
|
|
|
|
chomp; |
35
|
0
|
|
|
|
|
|
push @res, $_; |
36
|
0
|
0
|
|
|
|
|
last if @res > 300; # Sanity check: limit to at most 300 locales. FreeBSD 7.x has 163. |
37
|
|
|
|
|
|
|
} |
38
|
0
|
0
|
|
|
|
|
close $fh |
39
|
|
|
|
|
|
|
or die $!; |
40
|
|
|
|
|
|
|
} |
41
|
0
|
|
|
|
|
|
@res; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub weekday_and_month_names { |
45
|
0
|
|
|
0
|
0
|
|
my @res; |
46
|
0
|
|
|
|
|
|
my @locales = all_locales(); |
47
|
0
|
0
|
|
|
|
|
if (!@locales) { |
48
|
0
|
|
|
|
|
|
push @locales, ""; # means: use default locale |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my %register; |
52
|
|
|
|
|
|
|
my $fingerprint_data = sub { |
53
|
0
|
|
|
0
|
|
|
my($ref) = @_; |
54
|
0
|
|
|
|
|
|
local $Data::Dumper::Indent = 0; |
55
|
0
|
|
|
|
|
|
local $Data::Dumper::Useqq = 0; |
56
|
0
|
|
|
|
|
|
local $Data::Dumper::Sortkeys = 1; |
57
|
0
|
|
|
|
|
|
Dumper($ref); |
58
|
0
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
my $register_and_use_data = sub { |
60
|
0
|
|
|
0
|
|
|
my($ref, $name) = @_; |
61
|
0
|
|
|
|
|
|
my $fingerprint = $fingerprint_data->($ref); |
62
|
0
|
0
|
|
|
|
|
if (exists $register{$fingerprint}) { |
63
|
0
|
|
|
|
|
|
+{ '==' => $register{$fingerprint} }; |
64
|
|
|
|
|
|
|
} else { |
65
|
0
|
|
|
|
|
|
$register{$fingerprint} = $name; |
66
|
0
|
|
|
|
|
|
$ref; |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
}; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
for my $locale (@locales) { |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $locname; |
73
|
0
|
0
|
|
|
|
|
if ($locale eq '') { |
74
|
0
|
|
|
|
|
|
$locname = ''; |
75
|
|
|
|
|
|
|
} else { |
76
|
0
|
|
|
|
|
|
$locname = $locale; |
77
|
0
|
|
|
|
|
|
POSIX::setlocale(&POSIX::LC_ALL, $locale); |
78
|
0
|
|
|
|
|
|
POSIX::setlocale(&POSIX::LC_TIME, $locale); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my %locale_res; |
82
|
|
|
|
|
|
|
{ |
83
|
0
|
|
|
|
|
|
my @l = (0,0,0,1,undef,2000-1900); |
|
0
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
for my $mon (1..12) { |
85
|
0
|
|
|
|
|
|
$l[4] = $mon-1; |
86
|
0
|
|
|
|
|
|
push @{$locale_res{'%B'}}, strftime("%B", @l); |
|
0
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
push @{$locale_res{'%b'}}, strftime("%b", @l); |
|
0
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
push @{$locale_res{'%OB'}}, strftime("%OB", @l); |
|
0
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
{ |
93
|
0
|
|
|
|
|
|
my @l = (0,0,0,1,1,1,undef); |
|
0
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
foreach my $wkday (0..6) { |
95
|
0
|
|
|
|
|
|
$l[6] = $wkday; |
96
|
0
|
|
|
|
|
|
push @{$locale_res{'%A'}}, strftime("%A", @l); |
|
0
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
push @{$locale_res{'%a'}}, strftime("%a", @l); |
|
0
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Order of the register_and_use_data calls is crucial here: |
102
|
|
|
|
|
|
|
# first do it for the whole dataset, and then for every |
103
|
|
|
|
|
|
|
# embedded array. |
104
|
0
|
|
|
|
|
|
my $locale_res = $register_and_use_data->(\%locale_res, $locname); |
105
|
0
|
0
|
|
|
|
|
unless ($locale_res->{'=='}) { |
106
|
0
|
|
|
|
|
|
for my $key (keys %$locale_res) { |
107
|
0
|
|
|
|
|
|
$locale_res->{$key} = $register_and_use_data->($locale_res->{$key}, $key); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
push @res, { |
112
|
|
|
|
|
|
|
# 'n' (name) has a leading space, to have it first |
113
|
|
|
|
|
|
|
# in the Sortkeys-sorted dump |
114
|
|
|
|
|
|
|
" n" => $locname, |
115
|
|
|
|
|
|
|
"d" => $locale_res, |
116
|
|
|
|
|
|
|
}; |
117
|
|
|
|
|
|
|
} |
118
|
0
|
|
|
|
|
|
@res; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub weekday_and_month_names_dump { |
122
|
0
|
|
|
0
|
0
|
|
my @res = weekday_and_month_names(); |
123
|
0
|
|
|
|
|
|
join "\n", map { |
124
|
0
|
|
|
|
|
|
Data::Dumper->new([$_],['r'])->Useqq(1)->Indent(0)->Sortkeys(1)->Dump |
125
|
|
|
|
|
|
|
} @res; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# REPO BEGIN |
129
|
|
|
|
|
|
|
sub _is_in_path { |
130
|
0
|
|
|
0
|
|
|
my($prog) = @_; |
131
|
0
|
0
|
|
|
|
|
if (file_name_is_absolute($prog)) { |
132
|
0
|
0
|
|
|
|
|
if ($^O eq 'MSWin32') { |
133
|
0
|
0
|
0
|
|
|
|
return $prog if (-f $prog && -x $prog); |
134
|
0
|
0
|
0
|
|
|
|
return "$prog.bat" if (-f "$prog.bat" && -x "$prog.bat"); |
135
|
0
|
0
|
0
|
|
|
|
return "$prog.com" if (-f "$prog.com" && -x "$prog.com"); |
136
|
0
|
0
|
0
|
|
|
|
return "$prog.exe" if (-f "$prog.exe" && -x "$prog.exe"); |
137
|
0
|
0
|
0
|
|
|
|
return "$prog.cmd" if (-f "$prog.cmd" && -x "$prog.cmd"); |
138
|
|
|
|
|
|
|
} else { |
139
|
0
|
0
|
0
|
|
|
|
return $prog if -f $prog and -x $prog; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} |
142
|
0
|
|
|
|
|
|
require Config; |
143
|
0
|
|
|
|
|
|
%Config::Config = %Config::Config if 0; # cease -w |
144
|
0
|
|
0
|
|
|
|
my $sep = $Config::Config{'path_sep'} || ':'; |
145
|
0
|
|
|
|
|
|
foreach (split(/$sep/o, $ENV{PATH})) { |
146
|
0
|
0
|
|
|
|
|
if ($^O eq 'MSWin32') { |
147
|
|
|
|
|
|
|
# maybe use $ENV{PATHEXT} like maybe_command in ExtUtils/MM_Win32.pm? |
148
|
0
|
0
|
0
|
|
|
|
return "$_\\$prog" if (-f "$_\\$prog" && -x "$_\\$prog"); |
149
|
0
|
0
|
0
|
|
|
|
return "$_\\$prog.bat" if (-f "$_\\$prog.bat" && -x "$_\\$prog.bat"); |
150
|
0
|
0
|
0
|
|
|
|
return "$_\\$prog.com" if (-f "$_\\$prog.com" && -x "$_\\$prog.com"); |
151
|
0
|
0
|
0
|
|
|
|
return "$_\\$prog.exe" if (-f "$_\\$prog.exe" && -x "$_\\$prog.exe"); |
152
|
0
|
0
|
0
|
|
|
|
return "$_\\$prog.cmd" if (-f "$_\\$prog.cmd" && -x "$_\\$prog.cmd"); |
153
|
|
|
|
|
|
|
} else { |
154
|
0
|
0
|
0
|
|
|
|
return "$_/$prog" if (-x "$_/$prog" && !-d "$_/$prog"); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
0
|
|
|
|
|
|
undef; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
# REPO END |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
1; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
__END__ |