blib/lib/Locale/XGettext/TT2.pm

filter: Statementstmt 83.5% 142 / 170 Branchbran 66.6% 68 / 102 Conditioncond 64.9% 37 / 57 MC/DCmcdc 42.8% 12 / 28 Subroutinesub 73.6% 14 / 19 Podpod 100% 8 / 8 totaltotal 73.1% 281 / 384 CC 73 SCAR 37.0
CC
73
Cov
75%
__ANON__
59.1
split_text
54.4
__extractEntry
18.3
CRAP 40.5
↑ Summary blib/lib/Template/Plugin/Gettext.pm »
1 #! /bin/false
2  
3 # Copyright (C) 2016-2018 Guido Flohr <guido.flohr@cantanea.com>,
4 # all rights reserved.
5  
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU Library General Public License as published
8 # by the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
10  
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Library General Public License for more details.
15  
16 # You should have received a copy of the GNU Library General Public
17 # License along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 # USA.
20  
21 package Locale::XGettext::TT2;
22 7 $Locale::XGettext::TT2::VERSION = '0.8';
23 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 7 ▶use Locale::TextDomain qw(Template-Plugin-Gettext);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 7 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 7 ▶use Locale::XGettext 0.7;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 7 ▶use base qw(Locale::XGettext);
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 sub versionInformation {
32 0 ▶ return __x('{program} (Template-Plugin-Gettext) {version}
Subroutine versionInformation: not called CC=1 SCAR=6.9
Pod documented
33 Copyright (C) {years} Cantanea EOOD (http://www.cantanea.com/).
34 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
35 This is free software: you are free to change and redistribute it.
36 There is NO WARRANTY, to the extent permitted by law.
37 Written by Guido Flohr (http://www.guido-flohr.net/).
38 ',
39 program => $0, years => '2016-2018',
40 version => $Locale::XGettext::TT2::VERSION);
41 }
42  
43 sub fileInformation {
44 0 ▶ return __(<<EOF);
Subroutine fileInformation: not called CC=1 SCAR=6.9
Pod documented
45 The input files should be templates for the Template::Toolkit
46 (http://www.template-toolkit.org/). The strings are usually marked and
47 made translatable with the help of "Template::Plugin::Gettext". Try the
48 command "perldoc Template::Plugin::Gettext" for more information.
49 EOF
50 }
51  
52 sub canExtractAll {
53 0 ▶ shift;
Subroutine canExtractAll: not called CC=1 SCAR=6.9
Pod documented
54 }
55  
56 sub canKeywords {
57 0 ▶ shift;
Subroutine canKeywords: not called CC=1 SCAR=6.9
Pod documented
58 }
59  
60 sub languageSpecificOptions {
61 return [
62 [
63 0 ▶ 'plugin|plug-in:s',
Subroutine languageSpecificOptions: not called CC=1 SCAR=6.9
Pod documented
64 'plug_in',
65 ' --plug-in=PLUG-IN, --plugin=PLUG-IN',
66 __"the plug-in name (defaults to 'Gettext'), can be an empty string",
67 ]
68 ];
69 }
70  
71 sub defaultKeywords {
72 return [
73 10 ▶ 'gettext:1',
Subroutine defaultKeywords: called CC=1 SCAR=0.0
Pod documented
74 'ngettext:1,2',
75 'pgettext:1c,2',
76 'gettextp:1,2c',
77 'npgettext:1c,2,3',
78 'ngettextp:1,2,3c',
79 'xgettext:1',
80 'nxgettext:1,2',
81 'pxgettext:1c,2',
82 'xgettextp:1,2c',
83 'npxgettext:1c,2,3',
84 'nxgettextp:1,2,3c',
85 ];
86 }
87  
88 sub defaultFlags {
89 return [
90 10 ▶ "xgettext:1:perl-brace-format",
Subroutine defaultFlags: called CC=1 SCAR=0.0
Pod documented
91 "nxgettext:1:perl-brace-format",
92 "nxgettext:2:perl-brace-format",
93 "pxgettext:2:perl-brace-format",
94 "xgettextp:1:perl-brace-format",
95 "npxgettext:2:perl-brace-format",
96 "npxgettext:3:perl-brace-format",
97 "nxgettextp:1:perl-brace-format",
98 "nxgettextp:2:perl-brace-format",
99 ];
100 }
101  
102 sub readFile {
103 10 ▶ my ($self, $filename) = @_;
Subroutine readFile: called CC=2 SCAR=6.9
Pod documented
104  
105 10 my %options = (
106 ABSOLUTE => 1,
107 # Needed for reading from POTFILES
108 RELATIVE => 1
109 );
110  
111 10 my $parser = Locale::XGettext::TT2::Parser->new(\%options);
112  
113 10 my $tt = Template->new({
114 %options,
115 PARSER => $parser,
116 });
117  
118 10 my $sink;
119 10 $parser->{__xgettext} = $self;
120 10 $parser->{__xgettext_filename} = $filename;
121  
122 10 ▶ $tt->process($filename, {}, \$sink) or die $tt->error;
Branch: 1 branch
BranchTrueFalseTotal
$tt->process($filename, {}, \$sink) or die $tt->error 1 9 10
123  
124 9 return $self;
125 }
126  
127 package Locale::XGettext::TT2::Parser;
128 7 $Locale::XGettext::TT2::Parser::VERSION = '0.8';
129 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
130  
131 7 ▶use Locale::TextDomain qw(Template-Plugin-Gettext);
Subroutine BEGIN: called CC=1 SCAR=0.0
132  
133 7 ▶use base qw(Template::Parser);
Subroutine BEGIN: called CC=1 SCAR=0.0
134  
135 sub split_text {
136 10 ▶ my ($self, $text) = @_;
Subroutine split_text: called CC=38 SCAR=40.0
137  
138 10 ▶ my $chunks = $self->SUPER::split_text($text) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $chunks = $self->SUPER::split_text($text) or return 0 10 10
139  
140 10 my $keywords = $self->{__xgettext}->keywords;
141 10 my $plug_in = $self->{__xgettext}->option('plug_in');
142 10 ▶ $plug_in = 'Gettext' if !defined $plug_in;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plug_in 9 1 10
143  
144 10 my $ident;
145 10 my $lplug_in = length $plug_in;
146 10 ▶ while (my $chunk = shift @$chunks) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $chunk = shift @$chunks) 75 9 84
147 75 ▶ if (!ref $chunk) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $chunk) 37 38 75
148 37 shift @$chunks;
149 37 next;
150 }
151  
152 38 my ($text, $lineno, $tokens) = @$chunk;
153  
154 38 ▶ next if !ref $tokens;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tokens 0 38 38
155  
156 38 ▶ if ($lplug_in) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lplug_in) { } 37 1 38
157 37 ▶ if ('USE' eq $tokens->[0] && 'IDENT' eq $tokens->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ("USE" eq $tokens->[0] and "IDENT" eq $tokens->[2]) 9 28 37
Condition66%2/3
"USE" eq $tokens->[0] and "IDENT" eq $tokens->[2]
!ll&&!rl&&r
2809
MC/DC50%1/2
"USE" eq $tokens->[0] and "IDENT" eq $tokens->[2]
"USE" eq $tokens->[0] "IDENT" eq $tokens->[2]
Truth table66%2/3
A and B
A= "USE" eq $tokens->[0]B= "IDENT" eq $tokens->[2]
ABresult
0X0
100
111
158 9 ▶ if ($plug_in eq $tokens->[3]
Branch: 2 branches
BranchTrueFalseTotal
if ($plug_in eq $tokens->[3] and 4 == @$tokens || '(' eq $tokens->[4]) { } 0 9 9
elsif ('ASSIGN' eq $tokens->[4] and 'IDENT' eq $tokens->[6] and $plug_in eq $tokens->[7]) { } 9 0 9
Condition16%1/6
$plug_in eq $tokens->[3] and 4 == @$tokens || "(" eq $tokens->[4]
!ll&&!rl&&r
900
4 == @$tokens or "(" eq $tokens->[4]
l!l&&r!l&&!r
000
MC/DC0%0/3
$plug_in eq $tokens->[3] and 4 == @$tokens || "(" eq $tokens->[4]
$plug_in eq $tokens->[3] 4 == @$tokens "(" eq $tokens->[4]
Truth table25%1/4
A and B or C
A= $plug_in eq $tokens->[3]B= 4 == @$tokensC= "(" eq $tokens->[4]
ABCresult
0XX0
1000
11X1
1011
159 && (4 == @$tokens
160 || '(' eq $tokens->[4])) {
161 0 $ident = $plug_in;
162 ▶ } elsif ('ASSIGN' eq $tokens->[4] && 'IDENT' eq $tokens->[6]
Condition33%2/6
"ASSIGN" eq $tokens->[4] and "IDENT" eq $tokens->[6] and $plug_in eq $tokens->[7]
!ll&&!rl&&r
009
"ASSIGN" eq $tokens->[4] and "IDENT" eq $tokens->[6]
!ll&&!rl&&r
009
MC/DC0%0/3
"ASSIGN" eq $tokens->[4] and "IDENT" eq $tokens->[6] and $plug_in eq $tokens->[7]
"ASSIGN" eq $tokens->[4] "IDENT" eq $tokens->[6] $plug_in eq $tokens->[7]
Truth table25%1/4
A and B and C
A= "ASSIGN" eq $tokens->[4]B= "IDENT" eq $tokens->[6]C= $plug_in eq $tokens->[7]
ABCresult
0XX0
10X0
1100
1111
163 && $plug_in eq $tokens->[7]) {
164 9 $ident = $tokens->[3];
165 }
166 9 next;
167 }
168  
169 28 ▶ next if !defined $ident;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ident 0 28 28
170 } else {
171 1 $ident = '';
172 }
173  
174 29 ▶ for (my $i = 0; $i < @$tokens; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$tokens) 232 28 260
175 # FIXME! It would be better to copy $tokens into an array
176 # @tokens because we modify the array reference $tokens.
177 # That implies that we iterate over tokens that do ot exist
178 # and that is an unnecessary risk.
179 232 ▶ if ($lplug_in
Branch: 3 branches
BranchTrueFalseTotal
if ($lplug_in and 'IDENT' eq $tokens->[$i] and $ident eq $$tokens[$i + 1] and 'DOT' eq $$tokens[$i + 2] and 'IDENT' eq $$tokens[$i + 4] and exists $$keywords{$$tokens[$i + 5]}) { } 13 219 232
elsif ('FILTER' eq $tokens->[$i] and 'IDENT' eq $$tokens[$i + 2] and exists $$keywords{$$tokens[$i + 3]}) { } 12 207 219
elsif (not $lplug_in and 'IDENT' eq $tokens->[$i] and exists $$keywords{$$tokens[$i + 1]}) { } 1 412 413
Condition80%12/15
$lplug_in and "IDENT" eq $tokens->[$i] and $ident eq $$tokens[$i + 1] and "DOT" eq $$tokens[$i + 2] and "IDENT" eq $$tokens[$i + 4] and exists $$keywords{$$tokens[$i + 5]}
!ll&&!rl&&r
219013
$lplug_in and "IDENT" eq $tokens->[$i] and $ident eq $$tokens[$i + 1] and "DOT" eq $$tokens[$i + 2] and "IDENT" eq $$tokens[$i + 4]
!ll&&!rl&&r
219013
$lplug_in and "IDENT" eq $tokens->[$i] and $ident eq $$tokens[$i + 1] and "DOT" eq $$tokens[$i + 2]
!ll&&!rl&&r
219013
$lplug_in and "IDENT" eq $tokens->[$i] and $ident eq $$tokens[$i + 1]
!ll&&!rl&&r
1794013
$lplug_in and "IDENT" eq $tokens->[$i]
!ll&&!rl&&r
417553
MC/DC50%3/6
$lplug_in and "IDENT" eq $tokens->[$i] and $ident eq $$tokens[$i + 1] and "DOT" eq $$tokens[$i + 2] and "IDENT" eq $$tokens[$i + 4] and exists $$keywords{$$tokens[$i + 5]}
$lplug_in "IDENT" eq $tokens->[$i] $ident eq $$tokens[$i + 1] "DOT" eq $$tokens[$i + 2] "IDENT" eq $$tokens[$i + 4] exists $$keywords{$$tokens[$i + 5]}
Truth table57%4/7
A and B and C and D and E and F
A= $lplug_inB= "IDENT" eq $tokens->[$i]C= $ident eq $$tokens[$i + 1]D= "DOT" eq $$tokens[$i + 2]E= "IDENT" eq $$tokens[$i + 4]F= exists $$keywords{$$tokens[$i + 5]}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
180 && 'IDENT' eq $tokens->[$i] && $ident eq $tokens->[$i + 1]
181 && 'DOT' eq $tokens->[$i + 2] && 'IDENT' eq $tokens->[$i + 4]
182 && exists $keywords->{$tokens->[$i + 5]}) {
183 13 my $keyword = $keywords->{$tokens->[$i + 5]};
184 13 $self->__extractEntry($text, $lineno, $keyword,
185 @$tokens[$i + 6 .. $#$tokens]);
186 ▶ } elsif ('FILTER' eq $tokens->[$i]
Condition83%5/6
"FILTER" eq $tokens->[$i] and "IDENT" eq $$tokens[$i + 2] and exists $$keywords{$$tokens[$i + 3]}
!ll&&!rl&&r
205212
"FILTER" eq $tokens->[$i] and "IDENT" eq $$tokens[$i + 2]
!ll&&!rl&&r
205014
MC/DC66%2/3
"FILTER" eq $tokens->[$i] and "IDENT" eq $$tokens[$i + 2] and exists $$keywords{$$tokens[$i + 3]}
"FILTER" eq $tokens->[$i] "IDENT" eq $$tokens[$i + 2] exists $$keywords{$$tokens[$i + 3]}
Truth table75%3/4
A and B and C
A= "FILTER" eq $tokens->[$i]B= "IDENT" eq $$tokens[$i + 2]C= exists $$keywords{$$tokens[$i + 3]}
ABCresult
0XX0
10X0
1100
1111
187 && 'IDENT' eq $tokens->[$i + 2]
188 && exists $keywords->{$tokens->[$i + 3]}) {
189 12 my $keyword = $keywords->{$tokens->[$i + 3]};
190 # Inject the block contents as the first argument.
191 12 ▶ if ($i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i) { } 9 3 12
192 9 my $first_arg;
193 9 ▶ if ($tokens->[$i - 2] eq 'LITERAL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[$i - 2] eq 'LITERAL') { } 9 0 9
194 9 $first_arg = $tokens->[$i - 1];
195 } else {
196 0 next;
197 }
198 # May have been called without parentheses, see
199 # https://github.com/gflohr/Template-Plugin-Gettext/issues/4
200 9 ▶ if (!defined $tokens->[4 + $i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $$tokens[4 + $i]) { } 2 7 9
elsif ('FILTER' eq $$tokens[4 + $i] or 'DOT' eq $$tokens[4 + $i]) { } 4 3 7
201 2 $tokens->[4 + $i] = $tokens->[5 + $i] = '(';
202 2 $tokens->[6 + $i] = $tokens->[7 + $i] = ')';
203 2 splice @$tokens, 6 + $i, 0, LITERAL => $first_arg;
204 # Or without parentheses and another filter is immediately
205 # following or the value gets dereferenced with a dot.
206 # The latter is kind of nonsense but we support it
207 # elsewhere as well and it is hard to catch.
208 ▶ } elsif ('FILTER' eq $tokens->[4 + $i]
Condition100%3/3
"FILTER" eq $$tokens[4 + $i] or "DOT" eq $$tokens[4 + $i]
l!l&&r!l&&!r
223
MC/DC100%2/2
"FILTER" eq $$tokens[4 + $i] or "DOT" eq $$tokens[4 + $i]
"FILTER" eq $$tokens[4 + $i] "DOT" eq $$tokens[4 + $i]
Truth table100%3/3
A or B
A= "FILTER" eq $$tokens[4 + $i]B= "DOT" eq $$tokens[4 + $i]
ABresult
1X1
011
000
209 || 'DOT' eq $tokens->[4 + $i]) {
210 4 splice @$tokens, 4 + $i, 0,
211 '(', '(', LITERAL => $first_arg, ')', ')';
212 } else {
213 3 splice @$tokens, 6 + $i, 0,
214 LITERAL => $first_arg, COMMA => ',';
215 }
216 } else {
217 3 ▶ next if !@$chunks;
Branch: 1 branch
BranchTrueFalseTotal
unless @$chunks 0 3 3
218 3 my $first_arg;
219 3 ▶ if (ref $chunks->[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $chunks->[0]) { } 0 3 3
elsif ('TEXT' eq $chunks->[0]) { } 3 0 3
220 0 ▶ next if $chunks->[0]->[2] ne 'ITEXT';
Branch: 1 branch
BranchTrueFalseTotal
if $chunks->[0][2] ne "ITEXT" 0 0 0
221 0 $first_arg = $chunks->[0]->[0];
222 } elsif ('TEXT' eq $chunks->[0]) {
223 3 $first_arg = $chunks->[1];
224 } else {
225 0 next;
226 }
227 3 splice @$tokens, 6, 0,
228 'LITERAL', $first_arg, 'COMMA', ',';
229 }
230 12 $self->__extractEntry($text, $lineno, $keyword,
231 @$tokens[$i + 4 .. $#$tokens]);
232 ▶ } elsif (!$lplug_in && 'IDENT' eq $tokens->[$i]
Condition83%5/6
not $lplug_in and "IDENT" eq $tokens->[$i] and exists $$keywords{$$tokens[$i + 1]}
!ll&&!rl&&r
20601
not $lplug_in and "IDENT" eq $tokens->[$i]
!ll&&!rl&&r
20331
MC/DC66%2/3
not $lplug_in and "IDENT" eq $tokens->[$i] and exists $$keywords{$$tokens[$i + 1]}
not $lplug_in "IDENT" eq $tokens->[$i] exists $$keywords{$$tokens[$i + 1]}
Truth table75%3/4
not(A) and B and C
A= not $lplug_inB= "IDENT" eq $tokens->[$i]C= exists $$keywords{$$tokens[$i + 1]}
ABCresult
0XX0
10X0
1100
1111
233 && exists $keywords->{$tokens->[$i + 1]}) {
234 1 my $keyword = $keywords->{$tokens->[$i + 1]};
235 1 $self->__extractEntry($text, $lineno, $keyword,
236 @$tokens[$i + 2 .. $#$tokens]);
237 }
238 }
239 }
240  
241 # Stop processing here, so that for example includes are ignored.
242 9 return [];
243 }
244  
245 sub __extractEntry {
246 26 ▶ my ($self, $text, $lineno, $keyword, @tokens) = @_;
Subroutine __extractEntry: called CC=13 SCAR=29.1
247  
248 my $args = sub {
249 26 ▶ my (@tokens) = @_;
Subroutine __ANON__: called CC=23 SCAR=40.8
250  
251 26 ▶ return if '(' ne $tokens[0];
Branch: 1 branch
BranchTrueFalseTotal
if "(" ne $tokens[0] 0 26 26
252  
253 26 splice @tokens, 0, 2;
254  
255 26 my @values;
256 26 ▶ while (@tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens) 53 0 53
257 53 ▶ if ('LITERAL' eq $tokens[0]) {
Branch: 5 branches
BranchTrueFalseTotal
if ('LITERAL' eq $tokens[0]) { } 36 17 53
elsif ('"' eq $tokens[0]) { } 8 9 17
elsif ('NUMBER' eq $tokens[0]) { } 0 9 9
elsif ('IDENT' eq $tokens[0]) { } 9 0 9
elsif ('(' eq $tokens[0]) { } 0 0 0
258 36 my $string = substr $tokens[1], 1, -1;
259 36 $string =~ s/\\([\\'])/$1/gs;
260 36 push @values, $string;
261 36 splice @tokens, 0, 2;
262 } elsif ('"' eq $tokens[0]) {
263 8 ▶ if ('TEXT' eq $tokens[2]
Branch: 1 branch
BranchTrueFalseTotal
if ('TEXT' eq $tokens[2] and '"' eq $tokens[4] and 'COMMA' eq $tokens[6] || ')' eq $tokens[6]) { } 7 1 8
Condition55%5/9
"TEXT" eq $tokens[2] and "\"" eq $tokens[4] and "COMMA" eq $tokens[6] || ")" eq $tokens[6]
!ll&&!rl&&r
107
"TEXT" eq $tokens[2] and "\"" eq $tokens[4]
!ll&&!rl&&r
017
"COMMA" eq $tokens[6] or ")" eq $tokens[6]
l!l&&r!l&&!r
070
MC/DC25%1/4
"TEXT" eq $tokens[2] and "\"" eq $tokens[4] and "COMMA" eq $tokens[6] || ")" eq $tokens[6]
"TEXT" eq $tokens[2] "\"" eq $tokens[4] "COMMA" eq $tokens[6] ")" eq $tokens[6]
Truth table40%2/5
A and B and C or D
A= "TEXT" eq $tokens[2]B= "\"" eq $tokens[4]C= "COMMA" eq $tokens[6]D= ")" eq $tokens[6]
ABCDresult
0XXX0
10XX0
11000
111X1
11011
264 && '"' eq $tokens[4]
265 && ('COMMA' eq $tokens[6]
266 || ')' eq $tokens[6])) {
267 7 push @values, $tokens[3];
268 7 splice @tokens, 6;
269 } else {
270 # String containing interpolated variables.
271 1 my $msg = __"Illegal variable interpolation at \"\$\"!";
272 1 push @values, \$msg;
273 1 ▶ while (@tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens) 10 0 10
274 10 ▶ last if 'COMMA' eq $tokens[0];
Branch: 1 branch
BranchTrueFalseTotal
if "COMMA" eq $tokens[0] 0 10 10
275 10 ▶ last if ')' eq $tokens[0];
Branch: 1 branch
BranchTrueFalseTotal
if ")" eq $tokens[0] 1 9 10
276 9 shift @tokens;
277 }
278 }
279 } elsif ('NUMBER' eq $tokens[0]) {
280 0 push @values, $tokens[1];
281 0 splice @tokens, 0, 2;
282 } elsif ('IDENT' eq $tokens[0]) {
283 # We store undef as the value because we cannot use it
284 # anyway.
285 9 push @values, undef;
286 9 splice @tokens, 0, 2;
287 } elsif ('(' eq $tokens[0]) {
288 0 splice @tokens, 0, 2;
289 0 my $nested = 1;
290 0 ▶ while (@tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens) 0 0 0
291 0 ▶ if ('(' eq $tokens[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if ('(' eq $tokens[0]) { } 0 0 0
elsif (')' eq $tokens[0]) { } 0 0 0
292 0 ++$nested;
293 0 splice @tokens, 0, 2;
294 } elsif (')' eq $tokens[0]) {
295 0 --$nested;
296 0 splice @tokens, 0, 2;
297 0 ▶ if (!$nested) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nested) 0 0 0
298 0 push @values, undef;
299 0 last;
300 }
301 } else {
302 0 splice @tokens, 0, 2;
303 }
304 }
305 } else {
306 0 return @values;
307 }
308  
309 53 ▶ return @values if !@tokens;
Branch: 1 branch
BranchTrueFalseTotal
unless @tokens 0 53 53
310  
311 53 my $next = shift @tokens;
312 53 ▶ if ('COMMA' eq $next) {
Branch: 2 branches
BranchTrueFalseTotal
if ('COMMA' eq $next) { } 18 35 53
elsif ('ASSIGN' eq $next and '=>' eq $tokens[0]) { } 9 52 61
313 18 shift @tokens;
314 18 next;
315 ▶ } elsif ('ASSIGN' eq $next && '=>' eq $tokens[0]) {
Condition66%2/3
"ASSIGN" eq $next and "=>" eq $tokens[0]
!ll&&!rl&&r
2609
MC/DC50%1/2
"ASSIGN" eq $next and "=>" eq $tokens[0]
"ASSIGN" eq $next "=>" eq $tokens[0]
Truth table66%2/3
A and B
A= "ASSIGN" eq $nextB= "=>" eq $tokens[0]
ABresult
0X0
100
111
316 9 shift @tokens;
317 9 next;
318 }
319  
320 26 return @values;
321 }
322  
323 0 return @values;
324 26 };
325  
326 26 my $min_args = $keyword->singular;
327 26 my %forms = (msgid => $keyword->singular);
328 26 ▶ if ($keyword->plural) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keyword->plural) 0 26 26
329 0 ▶ $min_args = $keyword->plural if $keyword->plural > $min_args;
Branch: 1 branch
BranchTrueFalseTotal
if $keyword->plural > $min_args 0 0 0
330 0 $forms{msgid_plural} = $keyword->plural;
331 }
332  
333 26 ▶ if ($keyword->context) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keyword->context) 9 17 26
334 9 ▶ $min_args = $keyword->context if $keyword->context > $min_args;
Branch: 1 branch
BranchTrueFalseTotal
if $keyword->context > $min_args 6 3 9
335 9 $forms{msgctxt} = $keyword->context;
336 }
337  
338 26 my @args = $args->(@tokens);
339  
340 # Do we have enough arguments?
341 26 ▶ return if $min_args > @args;
Branch: 1 branch
BranchTrueFalseTotal
if $min_args > @args 0 26 26
342  
343 my $entry = {
344 keyword => $keyword->{function}
345 26 };
346 26 foreach my $prop (keys %forms) {
347 35 my $argno = $forms{$prop} - 1;
348  
349 # We are only interested in literal values. Whatever is
350 # undefined is not parsable or not valid.
351 35 ▶ return if !defined $args[$argno];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args[$argno] 0 35 35
352 35 ▶ if (ref $args[$argno]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[$argno]) 1 34 35
353 1 my $filename = $self->{__xgettext_filename};
354 1 ▶ die "$filename:$lineno: ${$args[$argno]}\n" if ref $args[$argno];
Branch: 1 branch
BranchTrueFalseTotal
if ref $args[$argno] 1 0 1
355 }
356 34 $entry->{$prop} = $args[$argno];
357 }
358  
359 25 my $reference = $self->{__xgettext_filename} . ':' . $lineno;
360 25 $reference =~ s/-[1-9][0-9]*$//;
361 25 $entry->{reference} = $reference;
362  
363 25 ▶ if ($text =~ /^#/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /^#/) 3 22 25
364 3 my $comment = '';
365 3 my @lines = split /\n/, $text;
366 3 foreach my $line (@lines) {
367 6 ▶ last if $line !~ s/^[ \t\r\f\013]*#[ \t\r\f\013]?//;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ s/^[ \t\r\f\013]*#[ \t\r\f\013]?// 3 3 6
368  
369 3 $comment .= $line . "\n";
370 }
371 3 $entry->{automatic} = $comment;
372 }
373  
374 25 $self->{__xgettext}->addEntry($entry);
375  
376 25 return $self;
377 }
378  
379 7 1;
↑ Summary blib/lib/Template/Plugin/Gettext.pm »