line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::I18N::Lexicon::Maketext; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
24420
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
112
|
|
4
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
91
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
12
|
use Carp qw(croak); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
166
|
|
7
|
3
|
|
|
3
|
|
19
|
use List::Util qw(first); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
228
|
|
8
|
3
|
|
|
3
|
|
489
|
use Locale::Maketext; |
|
3
|
|
|
|
|
8855
|
|
|
3
|
|
|
|
|
79
|
|
9
|
3
|
|
|
3
|
|
1382
|
use Plack::I18N::Util qw(try_load_class); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
200
|
|
10
|
3
|
|
|
3
|
|
336
|
use Plack::I18N::Handle; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1254
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
24
|
|
|
24
|
1
|
3061
|
my $class = shift; |
14
|
24
|
|
|
|
|
46
|
my (%params) = @_; |
15
|
|
|
|
|
|
|
|
16
|
24
|
|
|
|
|
26
|
my $self = {}; |
17
|
24
|
|
|
|
|
40
|
bless $self, $class; |
18
|
|
|
|
|
|
|
|
19
|
24
|
|
66
|
|
|
254
|
$self->{i18n_class} = $params{i18n_class} || croak 'i18n_class required'; |
20
|
23
|
|
|
|
|
30
|
$self->{locale_dir} = $params{locale_dir}; |
21
|
23
|
|
100
|
|
|
52
|
$self->{default_language} = $params{default_language} || 'en'; |
22
|
|
|
|
|
|
|
|
23
|
23
|
|
|
|
|
42
|
$self->_init_lexicon; |
24
|
|
|
|
|
|
|
|
25
|
23
|
|
|
|
|
678
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _init_lexicon { |
29
|
23
|
|
|
23
|
|
16
|
my $self = shift; |
30
|
|
|
|
|
|
|
|
31
|
23
|
|
|
|
|
24
|
my $i18n_class = $self->{i18n_class}; |
32
|
|
|
|
|
|
|
|
33
|
23
|
100
|
|
|
|
46
|
if (!try_load_class($i18n_class)) { |
34
|
3
|
50
|
|
3
|
|
14
|
eval <<"EOC" or croak $@; |
|
3
|
|
|
0
|
|
3
|
|
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
232
|
|
|
0
|
|
|
|
|
0
|
|
35
|
|
|
|
|
|
|
package $i18n_class; |
36
|
|
|
|
|
|
|
use parent 'Locale::Maketext'; |
37
|
|
|
|
|
|
|
sub _loaded {1} |
38
|
|
|
|
|
|
|
1; |
39
|
|
|
|
|
|
|
EOC |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
23
|
|
|
|
|
51
|
my $default_i18n_class = "$i18n_class\::$self->{default_language}"; |
43
|
23
|
100
|
|
|
|
42
|
if (!try_load_class($default_i18n_class)) { |
44
|
3
|
50
|
|
3
|
|
12
|
eval <<"EOC" or croak $@; |
|
3
|
|
|
0
|
|
5
|
|
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
276
|
|
|
0
|
|
|
|
|
0
|
|
45
|
|
|
|
|
|
|
package $default_i18n_class; |
46
|
|
|
|
|
|
|
use parent -norequire, '$i18n_class'; |
47
|
|
|
|
|
|
|
our %Lexicon = (_AUTO => 1); |
48
|
|
|
|
|
|
|
sub _loaded {1} |
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
EOC |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub detect_languages { |
55
|
21
|
|
|
21
|
1
|
26
|
my $self = shift; |
56
|
|
|
|
|
|
|
|
57
|
21
|
|
33
|
|
|
44
|
my $path = $self->{locale_dir} || $INC{$self->{i18n_class}} || join '/', |
58
|
|
|
|
|
|
|
'lib', split /::/, $self->{i18n_class}; |
59
|
|
|
|
|
|
|
|
60
|
21
|
50
|
|
|
|
549
|
opendir(my $dh, $path) or croak "Can't opendir $path: $!"; |
61
|
21
|
100
|
|
|
|
149
|
my @files = grep { /\.p[om]$/ && -e "$path/$_" } readdir($dh); |
|
63
|
|
|
|
|
406
|
|
62
|
21
|
|
|
|
|
146
|
closedir $dh; |
63
|
|
|
|
|
|
|
|
64
|
21
|
|
|
|
|
35
|
my @languages = @files; |
65
|
21
|
|
|
|
|
93
|
s{\.pm$}{} for @languages; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
unshift @languages, $self->{default_language} |
68
|
21
|
100
|
|
21
|
|
146
|
unless first { $_ eq $self->{default_language} } @languages; |
|
21
|
|
|
|
|
81
|
|
69
|
|
|
|
|
|
|
|
70
|
21
|
|
|
|
|
190
|
return @languages; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
__END__ |