line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Localizer::Resource; |
2
|
5
|
|
|
5
|
|
204922
|
use strict; |
|
5
|
|
|
|
|
39
|
|
|
5
|
|
|
|
|
144
|
|
3
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
5
|
|
|
|
|
27
|
|
|
5
|
|
|
|
|
125
|
|
4
|
5
|
|
|
5
|
|
24
|
use utf8; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
25
|
|
5
|
5
|
|
|
5
|
|
191
|
use 5.010_001; |
|
5
|
|
|
|
|
17
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
1814
|
use Localizer::Style::Gettext; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
156
|
|
8
|
5
|
|
|
5
|
|
1906
|
use Localizer::BuiltinFunctions; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
209
|
|
9
|
5
|
|
|
5
|
|
1896
|
use Localizer::Lexicon; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
382
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $BUILTIN_FUNCTIONS = { |
12
|
|
|
|
|
|
|
numf => \&Localizer::BuiltinFunctions::numf, |
13
|
|
|
|
|
|
|
numerate => \&Localizer::BuiltinFunctions::numerate, |
14
|
|
|
|
|
|
|
quant => \&Localizer::BuiltinFunctions::quant, |
15
|
|
|
|
|
|
|
sprintf => \&Localizer::BuiltinFunctions::sprintf, |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Class::Accessor::Lite 0.05 ( |
19
|
5
|
|
|
|
|
29
|
rw => [qw(dictionary compiled precompile style functions)], |
20
|
5
|
|
|
5
|
|
37
|
); |
|
5
|
|
|
|
|
66
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
6
|
|
|
6
|
1
|
4988
|
my $class = shift; |
24
|
6
|
50
|
|
|
|
59
|
my %args = @_==1 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
25
|
|
|
|
|
|
|
|
26
|
6
|
50
|
|
|
|
22
|
unless (exists $args{dictionary}) { |
27
|
0
|
|
|
|
|
0
|
Carp::confess("Missing mandatory parameter: dictionary"); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$args{dictionary} = Localizer::Lexicon->new($args{dictionary}) |
31
|
6
|
50
|
|
|
|
52
|
if ref($args{dictionary}) eq 'HASH'; |
32
|
|
|
|
|
|
|
|
33
|
6
|
|
66
|
|
|
45
|
$args{style} ||= Localizer::Style::Gettext->new(); |
34
|
|
|
|
|
|
|
|
35
|
6
|
|
|
|
|
14
|
my $functions = do { |
36
|
6
|
100
|
|
|
|
32
|
if (exists $args{functions}) { |
37
|
|
|
|
|
|
|
+{ |
38
|
|
|
|
|
|
|
%$BUILTIN_FUNCTIONS, |
39
|
2
|
|
|
|
|
8
|
%{delete $args{functions}}, |
|
2
|
|
|
|
|
11
|
|
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
} else { |
42
|
4
|
|
|
|
|
10
|
$BUILTIN_FUNCTIONS |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
6
|
|
|
|
|
32
|
my $self = bless { |
47
|
|
|
|
|
|
|
compiled => +{}, |
48
|
|
|
|
|
|
|
precompile => 1, |
49
|
|
|
|
|
|
|
functions => $functions, |
50
|
|
|
|
|
|
|
%args, |
51
|
|
|
|
|
|
|
}, $class; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Compile dictionary data to CodeRef or ScalarRef |
54
|
6
|
100
|
|
|
|
28
|
if ($self->precompile) { |
55
|
3
|
|
|
|
|
32
|
for my $msgid ($self->dictionary->msgids) { |
56
|
5
|
|
|
|
|
30
|
$self->_compile($msgid); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
6
|
|
|
|
|
57
|
return $self; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub maketext { |
64
|
29
|
|
|
29
|
1
|
7574
|
my ($self, $msgid, @args) = @_; |
65
|
|
|
|
|
|
|
|
66
|
29
|
|
|
|
|
68
|
my $compiled = $self->_compile($msgid); |
67
|
27
|
50
|
|
|
|
74
|
return unless defined $compiled; |
68
|
|
|
|
|
|
|
|
69
|
27
|
100
|
|
|
|
91
|
if (ref $compiled eq 'CODE') { |
|
|
50
|
|
|
|
|
|
70
|
18
|
|
|
|
|
45
|
return $compiled->($self, @args); |
71
|
|
|
|
|
|
|
} elsif (ref $compiled eq 'SCALAR') { |
72
|
9
|
|
|
|
|
56
|
return $$compiled; |
73
|
|
|
|
|
|
|
} else { |
74
|
0
|
|
|
|
|
0
|
die "SHOULD NOT REACH HERE"; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _compile { |
79
|
34
|
|
|
34
|
|
57
|
my ($self, $msgid) = @_; |
80
|
|
|
|
|
|
|
|
81
|
34
|
100
|
|
|
|
84
|
if (my $code = $self->compiled->{$msgid}) { |
82
|
5
|
|
|
|
|
30
|
return $code; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
29
|
|
50
|
|
|
173
|
my $fmt = $self->dictionary->msgstr($msgid) || return; |
86
|
29
|
|
|
|
|
358
|
my $code = $self->style->compile($msgid, $fmt, $self->functions); |
87
|
27
|
|
|
|
|
84
|
$self->compiled->{$msgid} = $code; |
88
|
27
|
|
|
|
|
145
|
return $code; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |