blib/lib/Locale/XGettext/TT2.pm

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