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