line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Locale::Utils::PlaceholderMaketext; ## no critic (TidyCode)
|
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
195646
|
use strict;
|
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
194
|
|
4
|
6
|
|
|
6
|
|
44
|
use warnings;
|
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
217
|
|
5
|
6
|
|
|
6
|
|
39
|
use Carp qw(confess);
|
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
333
|
|
6
|
6
|
|
|
6
|
|
47
|
use Scalar::Util qw(looks_like_number);
|
|
6
|
|
|
|
|
25
|
|
|
6
|
|
|
|
|
424
|
|
7
|
6
|
|
|
6
|
|
3302
|
use Moo;
|
|
6
|
|
|
|
|
82986
|
|
|
6
|
|
|
|
|
41
|
|
8
|
6
|
|
|
6
|
|
11353
|
use MooX::StrictConstructor;
|
|
6
|
|
|
|
|
67960
|
|
|
6
|
|
|
|
|
29
|
|
9
|
6
|
|
|
6
|
|
132086
|
use MooX::Types::MooseLike::Base qw(Bool Str CodeRef);
|
|
6
|
|
|
|
|
31309
|
|
|
6
|
|
|
|
|
447
|
|
10
|
6
|
|
|
6
|
|
2847
|
use namespace::autoclean;
|
|
6
|
|
|
|
|
67826
|
|
|
6
|
|
|
|
|
29
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '1.005';
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has is_strict => (
|
15
|
|
|
|
|
|
|
is => 'rw',
|
16
|
|
|
|
|
|
|
isa => Bool,
|
17
|
|
|
|
|
|
|
);
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has is_escape_percent_sign => (
|
20
|
|
|
|
|
|
|
is => 'rw',
|
21
|
|
|
|
|
|
|
isa => Bool,
|
22
|
|
|
|
|
|
|
);
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has space => (
|
25
|
|
|
|
|
|
|
is => 'rw',
|
26
|
|
|
|
|
|
|
isa => Str,
|
27
|
|
|
|
|
|
|
default => sub { q{ } },
|
28
|
|
|
|
|
|
|
);
|
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
2
|
1
|
58
|
sub reset_space { return shift->space( q{ } ) }
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has formatter_code => (
|
33
|
|
|
|
|
|
|
is => 'rw',
|
34
|
|
|
|
|
|
|
isa => CodeRef,
|
35
|
|
|
|
|
|
|
clearer => 'clear_formatter_code',
|
36
|
|
|
|
|
|
|
);
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub maketext_to_gettext {
|
39
|
11
|
|
|
11
|
1
|
6901
|
my ($self, $string) = @_;
|
40
|
|
|
|
|
|
|
|
41
|
11
|
100
|
|
|
|
41
|
defined $string
|
42
|
|
|
|
|
|
|
or return $string;
|
43
|
10
|
|
|
|
|
251
|
my $is_escape_percent_sign = $self->is_escape_percent_sign;
|
44
|
|
|
|
|
|
|
## no critic (ComplexRegexes)
|
45
|
10
|
|
|
|
|
109
|
$string =~ s{
|
46
|
|
|
|
|
|
|
[~] ( [~\[\]] ) # $1 - unescape
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
( [%] ) # $2 - escape
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
\[
|
51
|
|
|
|
|
|
|
(?:
|
52
|
|
|
|
|
|
|
( [[:alpha:]*\#] [[:alpha:]_]* ) # $3 - function name
|
53
|
|
|
|
|
|
|
[,]
|
54
|
|
|
|
|
|
|
[_] ( [1-9] \d* ) # $4 - variable
|
55
|
|
|
|
|
|
|
( [^\]]* ) # $5 - arguments
|
56
|
|
|
|
|
|
|
| # or
|
57
|
|
|
|
|
|
|
[_] ( [1-9] \d* ) # $6 - variable
|
58
|
|
|
|
|
|
|
)
|
59
|
|
|
|
|
|
|
\]
|
60
|
|
|
|
|
|
|
}
|
61
|
|
|
|
|
|
|
{
|
62
|
29
|
100
|
|
|
|
197
|
$1
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
63
|
|
|
|
|
|
|
? $1
|
64
|
|
|
|
|
|
|
: $2
|
65
|
|
|
|
|
|
|
? $is_escape_percent_sign ? "%$2" : $2
|
66
|
|
|
|
|
|
|
: $6
|
67
|
|
|
|
|
|
|
? "%$6"
|
68
|
|
|
|
|
|
|
: "%$3(%$4$5)"
|
69
|
|
|
|
|
|
|
}xmsge;
|
70
|
|
|
|
|
|
|
## use critic (ComplexRegexes)
|
71
|
|
|
|
|
|
|
|
72
|
10
|
|
|
|
|
47
|
return $string;
|
73
|
|
|
|
|
|
|
}
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub gettext_to_maketext {
|
76
|
19
|
|
|
19
|
1
|
13919
|
my (undef, $string) = @_;
|
77
|
|
|
|
|
|
|
|
78
|
19
|
100
|
|
|
|
70
|
defined $string
|
79
|
|
|
|
|
|
|
or return $string;
|
80
|
|
|
|
|
|
|
## no critic (ComplexRegexes)
|
81
|
18
|
|
|
|
|
114
|
$string =~ s{
|
82
|
|
|
|
|
|
|
[%] ( [%] ) # $1 - unescape
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
( [~\[\]] ) # $2 - escape
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
[%]
|
87
|
|
|
|
|
|
|
(?:
|
88
|
|
|
|
|
|
|
( [[:alpha:]*\#] [[:alpha:]_]* ) # $3 - function name
|
89
|
|
|
|
|
|
|
[(]
|
90
|
|
|
|
|
|
|
[%] ( [1-9] \d* ) # $4 - variable
|
91
|
|
|
|
|
|
|
( [^)]* ) # $5 - arguments
|
92
|
|
|
|
|
|
|
[)]
|
93
|
|
|
|
|
|
|
| # or
|
94
|
|
|
|
|
|
|
( [1-9] \d* ) # $6 - variable
|
95
|
|
|
|
|
|
|
)
|
96
|
|
|
|
|
|
|
}
|
97
|
|
|
|
|
|
|
{
|
98
|
52
|
100
|
|
|
|
339
|
$1
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
99
|
|
|
|
|
|
|
? $1
|
100
|
|
|
|
|
|
|
: $2
|
101
|
|
|
|
|
|
|
? "~$2"
|
102
|
|
|
|
|
|
|
: $6
|
103
|
|
|
|
|
|
|
? "[_$6]"
|
104
|
|
|
|
|
|
|
: "[$3,_$4$5]"
|
105
|
|
|
|
|
|
|
}xmsge;
|
106
|
|
|
|
|
|
|
## use critic (ComplexRegexes)
|
107
|
|
|
|
|
|
|
|
108
|
18
|
|
|
|
|
67
|
return $string;
|
109
|
|
|
|
|
|
|
}
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Expand the placeholders
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _replace { ## no critic (ManyArgs)
|
114
|
184
|
|
|
184
|
|
1016
|
my ($self, $arg_ref, $text, $index_quant, $singular, $plural, $zero, $index_string) = @_;
|
115
|
|
|
|
|
|
|
|
116
|
184
|
100
|
|
|
|
660
|
if (defined $index_quant) { # quant
|
117
|
74
|
|
|
|
|
222
|
my $number = $arg_ref->[$index_quant - 1];
|
118
|
74
|
100
|
|
|
|
326
|
if ( ! looks_like_number($number) ) {
|
119
|
28
|
100
|
|
|
|
606
|
$number = $self->is_strict ? return $text : 0;
|
120
|
|
|
|
|
|
|
}
|
121
|
58
|
100
|
|
|
|
1263
|
my $formatted
|
122
|
|
|
|
|
|
|
= $self->formatter_code
|
123
|
|
|
|
|
|
|
? $self->formatter_code->($number, 'numeric', 'quant')
|
124
|
|
|
|
|
|
|
: $number;
|
125
|
58
|
|
|
|
|
1743
|
my $space = $self->space;
|
126
|
|
|
|
|
|
|
return
|
127
|
58
|
50
|
100
|
|
|
1002
|
+( defined $zero && $number == 0 )
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
128
|
|
|
|
|
|
|
? $zero
|
129
|
|
|
|
|
|
|
: $number == 1
|
130
|
|
|
|
|
|
|
? (
|
131
|
|
|
|
|
|
|
defined $singular
|
132
|
|
|
|
|
|
|
? "$formatted$space$singular"
|
133
|
|
|
|
|
|
|
: return $text
|
134
|
|
|
|
|
|
|
)
|
135
|
|
|
|
|
|
|
: (
|
136
|
|
|
|
|
|
|
defined $plural
|
137
|
|
|
|
|
|
|
? "$formatted$space$plural"
|
138
|
|
|
|
|
|
|
: defined $singular
|
139
|
|
|
|
|
|
|
? "$formatted$space$singular"
|
140
|
|
|
|
|
|
|
: return $text
|
141
|
|
|
|
|
|
|
);
|
142
|
|
|
|
|
|
|
}
|
143
|
|
|
|
|
|
|
# replace only
|
144
|
110
|
|
|
|
|
347
|
my $string = $arg_ref->[$index_string - 1];
|
145
|
110
|
100
|
|
|
|
1399
|
defined $string
|
|
|
100
|
|
|
|
|
|
146
|
|
|
|
|
|
|
or return $self->is_strict ? $text : q{};
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
return
|
149
|
56
|
100
|
|
|
|
1371
|
$self->formatter_code
|
|
|
100
|
|
|
|
|
|
150
|
|
|
|
|
|
|
? $self->formatter_code->(
|
151
|
|
|
|
|
|
|
$string,
|
152
|
|
|
|
|
|
|
looks_like_number($string) ? 'numeric' : 'string',
|
153
|
|
|
|
|
|
|
)
|
154
|
|
|
|
|
|
|
: $string;
|
155
|
|
|
|
|
|
|
}
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub expand_maketext {
|
158
|
30
|
|
|
30
|
1
|
27286
|
my ($self, $text, @args) = @_;
|
159
|
|
|
|
|
|
|
|
160
|
30
|
100
|
|
|
|
139
|
defined $text
|
161
|
|
|
|
|
|
|
or return $text;
|
162
|
29
|
100
|
66
|
|
|
186
|
my $arg_ref = ( @args == 1 && ref $args[0] eq 'ARRAY' )
|
163
|
|
|
|
|
|
|
? $args[0]
|
164
|
|
|
|
|
|
|
: [ @args ];
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
## no critic (ComplexRegexes)
|
167
|
29
|
|
|
|
|
280
|
$text =~ s{
|
168
|
|
|
|
|
|
|
[~] ( [~\[\]] ) # $1: escaped
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
( # $2: text
|
171
|
|
|
|
|
|
|
\[ (?:
|
172
|
|
|
|
|
|
|
(?: quant | [*] )
|
173
|
|
|
|
|
|
|
[,] [_] ( \d+ ) # $3: n
|
174
|
|
|
|
|
|
|
[,] ( [^,\]]* ) # $4: singular
|
175
|
|
|
|
|
|
|
(?: [,] ( [^,\]]* ) )? # $5: plural
|
176
|
|
|
|
|
|
|
(?: [,] ( [^,\]]* ) )? # $6: zero
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
[_] ( \d+ ) # $7: n
|
179
|
|
|
|
|
|
|
) \]
|
180
|
|
|
|
|
|
|
)
|
181
|
|
|
|
|
|
|
}
|
182
|
|
|
|
|
|
|
{
|
183
|
101
|
100
|
|
|
|
1451
|
$1
|
184
|
|
|
|
|
|
|
? $1
|
185
|
|
|
|
|
|
|
: $self->_replace($arg_ref, $2, $3, $4, $5, $6, $7)
|
186
|
|
|
|
|
|
|
}xmsge;
|
187
|
|
|
|
|
|
|
## use critic (ComplexRegexes)
|
188
|
|
|
|
|
|
|
|
189
|
29
|
|
|
|
|
557
|
return $text;
|
190
|
|
|
|
|
|
|
}
|
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub expand_gettext {
|
193
|
29
|
|
|
29
|
1
|
17154
|
my ($self, $text, @args) = @_;
|
194
|
|
|
|
|
|
|
|
195
|
29
|
100
|
|
|
|
93
|
defined $text
|
196
|
|
|
|
|
|
|
or return $text;
|
197
|
28
|
100
|
66
|
|
|
132
|
my $arg_ref = ( @args == 1 && ref $args[0] eq 'ARRAY' )
|
198
|
|
|
|
|
|
|
? $args[0]
|
199
|
|
|
|
|
|
|
: [ @args ];
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
## no critic (ComplexRegexes)
|
202
|
28
|
|
|
|
|
183
|
$text =~ s{
|
203
|
|
|
|
|
|
|
[%] ( % ) # $1: escaped
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
( # $2: text
|
206
|
|
|
|
|
|
|
[%] (?: quant | [*] )
|
207
|
|
|
|
|
|
|
[(]
|
208
|
|
|
|
|
|
|
[%] ( \d+ ) # $3: n
|
209
|
|
|
|
|
|
|
[,] ( [^,)]* ) # $4: singular
|
210
|
|
|
|
|
|
|
(?: [,] ( [^,)]* ) )? # $5: plural
|
211
|
|
|
|
|
|
|
(?: [,] ( [^,)]* ) )? # $6: zero
|
212
|
|
|
|
|
|
|
[)]
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
[%] ( \d+ ) # $7: n
|
215
|
|
|
|
|
|
|
)
|
216
|
|
|
|
|
|
|
}
|
217
|
|
|
|
|
|
|
{
|
218
|
92
|
50
|
|
|
|
799
|
$1
|
219
|
|
|
|
|
|
|
? $1
|
220
|
|
|
|
|
|
|
: $self->_replace($arg_ref, $2, $3, $4, $5, $6, $7)
|
221
|
|
|
|
|
|
|
}xmsge;
|
222
|
|
|
|
|
|
|
## use critic (ComplexRegexes)
|
223
|
|
|
|
|
|
|
|
224
|
28
|
|
|
|
|
338
|
return $text;
|
225
|
|
|
|
|
|
|
}
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable;
|
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
1;
|
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
__END__
|