Extract/Perl.pm

filter: Statementstmt 91.4% 149 / 163 Branchbran 76.7% 43 / 56 Conditioncond 72.7% 8 / 11 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 94.7% 18 / 19 Podpod 100% 4 / 4 totaltotal 86.8% 225 / 259 CC 34 SCAR 19.3
CC
34
Cov
87%
interpolate_escape_sequence
15.2
stack_item_mapping
10.0
preprocess
8.9
CRAP 6.9
« Extract/TT.pm ↑ Summary Extract/JavaScript.pm »
1 package Locale::TextDomain::OO::Extract::Perl; ## no critic (TidyCode)
2
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use MooX::Types::MooseLike::Base qw(ArrayRef Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9
10 3 our $VERSION = '2.011';
11
12 3 extends qw(
13 Locale::TextDomain::OO::Extract::Base::RegexBasedExtractor
14 );
15 3 with qw(
16 Locale::TextDomain::OO::Extract::Role::File
17 );
18
19 has filter => (
20 is => 'rw',
21 isa => ArrayRef[Str],
22 lazy => 1,
23 0 ▶ default => sub {[ 'all' ]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 3 );
25
26 14 ▶sub _filtered_start_rule {
Subroutine _filtered_start_rule: called CC=2 SCAR=6.9
27 14 my $self = shift;
28
29 14 my %filter_of = map { $_ => 1 } @{ $self->filter };
30 224 ▶ my $list_if = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
31 224 my ( $key, @list ) = @_;
32 my $condition
33 = $filter_of{all} && ! $filter_of{"!$key"}
34 224 ▶ || $filter_of{$key};
Condition100%6/6
$filter_of{'all'} && !$filter_of{"!$key"} || $filter_of{$key}
l!l&&r!l&&!r
8428112
$filter_of{"all"} and not $filter_of{"!$key"}
!ll&&!rl&&r
1122884
MC/DC100%3/3
$filter_of{'all'} && !$filter_of{"!$key"} || $filter_of{$key}
$filter_of{"all"} not $filter_of{"!$key"} $filter_of{$key}
Truth table80%4/5
A and not(B) || C
A= $filter_of{"all"}B= not $filter_of{"!$key"}C= $filter_of{$key}
ABCresult
11X1
0X11
1011
0X00
1000
35 224 ▶ return $condition ? @list : ();
Branch: 1 branch
BranchTrueFalseTotal
$condition ? : 112 112 224
36 14 };
37 14 my $with_bracket = join "\n| ", (
38 $list_if->('Gettext', 'N? __ n? p? x?'),
39 $list_if->('Gettext::DomainAndCategory', 'N? __ d? c? n? p? x?'),
40 $list_if->('Gettext::Loc', 'N? loc_ n? p? x?'),
41 $list_if->('Gettext::Loc::DomainAndCategory', 'N? loc_ d? c? n? p? x?'),
42 $list_if->('BabelFish::Loc', 'N? loc_b p?'),
43 $list_if->('BabelFish::Loc::DomainAndCategory', 'N? loc_b d? c? p?'),
44 $list_if->('Maketext::Loc', 'N? loc (?: _mp? )?'),
45 $list_if->('Maketext::Localise', 'N? localise (?: _mp? )?'),
46 $list_if->('Maketext::Localize', 'N? localize (?: _mp? )?'),
47 $list_if->('Maketext', 'N? maketext (?: _p )?'),
48 $list_if->('Gettext::DomainAndCategory', '__begin_ d? c?'),
49 $list_if->('Gettext::Loc::DomainAndCategory', 'loc_begin_ d? c?'),
50 $list_if->('BabelFish::Loc::DomainAndCategory', 'loc_begin_b d? c?'),
51 );
52 14 ▶ $with_bracket ||= '(?!)';
Condition50%1/2
$with_bracket ||= "(?!)"
l!l
140
MC/DC0%0/1
$with_bracket ||= "(?!)"
$with_bracket
Truth table50%1/2
A
A= $with_bracket
Aresult
11
00
53 14 my $without = join q{}, map { "\n| $_" } (
54 $list_if->('Gettext::DomainAndCategory', '__end_ d? c?'),
55 $list_if->('Gettext::Loc::DomainAndCategory', 'loc_end_ d? c?'),
56 $list_if->('BabelFish::Loc::DomainAndCategory', 'loc_end_b d? c?'),
57 );
58
59 14 return qr{
60 \b
61 (?:
62 (?: $with_bracket ) \s* [(]
63 $without
64 )
65 }xms;
66 }
67
68 3 my $category_rule
69 = my $context_rule
70 = my $domain_rule
71 = my $domain_or_category_rule
72 = my $plural_rule
73 = my $singular_rule
74 = my $text_rule
75 = [
76 [
77 # 'text with 0 .. n escaped chars'
78 qr{
79 \s* ( ['] )
80 (
81 [^\\']* # normal text
82 (?: \\ . [^\\']* )* # maybe followed by escaped char and normal text
83 )
84 [']
85 }xms,
86 ],
87 'or',
88 [
89 # "text with 0 .. n escaped chars"
90 qr{
91 \s* ( ["] )
92 (
93 [^\\"]* # normal text
94 (?: \\ . [^\\"]* )* # maybe followed by escaped char and normal text
95 )
96 ["]
97 }xms,
98 ],
99 'or',
100 [
101 # q{text with 0 .. n {placeholders} and/or 0 .. n escaped chars}
102 ## no critic (EscapedMetacharacters)
103 qr{
104 \s* ( qq? \{ ) # q curly bracket quoted
105 (
106 (?:
107 [^\{\}\\] # normal text
108 | \\ . # escaped char
109 | \{ (?-1) \} # any pairs of curly brackets with the same stuff inside
110 )*
111 )
112 \} # end of quote
113 }xms,
114 ## use critic (EscapedMetacharacters)
115 ],
116 ];
117 3 my $comma_rule = qr{ \s* [,] }xms;
118 3 my $count_rule = qr{ \s* ( [^,)]+ ) }xms;
119 3 my $close_rule = qr{ \s* [,]? \s* ( [^)]* ) [)] }xms;
120
121 3 my $rules = [
122 # loc_, __
123 [
124 'begin',
125 qr{ \b N? (?: loc_ | __ ) ( x? ) \s* [(] }xms,
126 'and',
127 $text_rule,
128 'and',
129 $close_rule,
130 'end',
131 ],
132 'or',
133 [
134 'begin',
135 qr{ \b N? (?: loc_ | __ ) ( n x? ) \s* [(] }xms,
136 'and',
137 $singular_rule,
138 'and',
139 $comma_rule,
140 'and',
141 $plural_rule,
142 'and',
143 $comma_rule,
144 'and',
145 $count_rule,
146 'and',
147 $close_rule,
148 'end',
149 ],
150 'or',
151 [
152 'begin',
153 qr{ \b N? (?: loc_ | __ ) ( p x? ) \s* [(] }xms,
154 'and',
155 $context_rule,
156 'and',
157 $comma_rule,
158 'and',
159 $text_rule,
160 'and',
161 $close_rule,
162 'end',
163 ],
164 'or',
165 [
166 'begin',
167 qr{ \b N? (?: loc_ | __ ) ( np x? ) \s* [(] }xms,
168 'and',
169 $context_rule,
170 'and',
171 $comma_rule,
172 'and',
173 $singular_rule,
174 'and',
175 $comma_rule,
176 'and',
177 $plural_rule,
178 'and',
179 $comma_rule,
180 'and',
181 $count_rule,
182 'and',
183 $close_rule,
184 'end',
185 ],
186
187 # loc_d, __d
188 'or',
189 [
190 'begin',
191 qr{ \b N? (?: loc_ | __ ) ( d x? ) \s* [(] }xms,
192 'and',
193 $domain_rule,
194 'and',
195 $comma_rule,
196 'and',
197 $text_rule,
198 'and',
199 $close_rule,
200 'end',
201 ],
202 'or',
203 [
204 'begin',
205 qr{ \b N? (?: loc_ | __ ) ( dn x? ) \s* [(] }xms,
206 'and',
207 $domain_rule,
208 'and',
209 $comma_rule,
210 'and',
211 $singular_rule,
212 'and',
213 $comma_rule,
214 'and',
215 $plural_rule,
216 'and',
217 $comma_rule,
218 'and',
219 $count_rule,
220 'and',
221 $close_rule,
222 'end',
223 ],
224 'or',
225 [
226 'begin',
227 qr{ \b N? (?: loc_ | __ ) ( dp x? ) \s* [(] }xms,
228 'and',
229 $domain_rule,
230 'and',
231 $comma_rule,
232 'and',
233 $context_rule,
234 'and',
235 $comma_rule,
236 'and',
237 $text_rule,
238 'and',
239 $close_rule,
240 'end',
241 ],
242 'or',
243 [
244 'begin',
245 qr{ \b N? (?: loc_ | __ ) ( dnp x? ) \s* [(] }xms,
246 'and',
247 $domain_rule,
248 'and',
249 $comma_rule,
250 'and',
251 $context_rule,
252 'and',
253 $comma_rule,
254 'and',
255 $singular_rule,
256 'and',
257 $comma_rule,
258 'and',
259 $plural_rule,
260 'and',
261 $comma_rule,
262 'and',
263 $count_rule,
264 'and',
265 $close_rule,
266 'end',
267 ],
268
269 # loc_c, __c
270 'or',
271 [
272 'begin',
273 qr{ \b N? (?: loc_ | __ ) ( c x? ) \s* [(] }xms,
274 'and',
275 $text_rule,
276 'and',
277 $comma_rule,
278 'and',
279 $category_rule,
280 'and',
281 $close_rule,
282 'end',
283 ],
284 'or',
285 [
286 'begin',
287 qr{ \b N? (?: loc_ | __ ) ( cn x? ) \s* [(] }xms,
288 'and',
289 $singular_rule,
290 'and',
291 $comma_rule,
292 'and',
293 $plural_rule,
294 'and',
295 $comma_rule,
296 'and',
297 $count_rule,
298 'and',
299 $comma_rule,
300 'and',
301 $category_rule,
302 'and',
303 $close_rule,
304 'end',
305 ],
306 'or',
307 [
308 'begin',
309 qr{ \b N? (?: loc_ | __ ) ( cp x? ) \s* [(] }xms,
310 'and',
311 $context_rule,
312 'and',
313 $comma_rule,
314 'and',
315 $text_rule,
316 'and',
317 $comma_rule,
318 'and',
319 $category_rule,
320 'and',
321 $close_rule,
322 'end',
323 ],
324 'or',
325 [
326 'begin',
327 qr{ \b N? (?: loc_ | __ ) ( cnp x? ) \s* [(] }xms,
328 'and',
329 $context_rule,
330 'and',
331 $comma_rule,
332 'and',
333 $singular_rule,
334 'and',
335 $comma_rule,
336 'and',
337 $plural_rule,
338 'and',
339 $comma_rule,
340 'and',
341 $count_rule,
342 'and',
343 $comma_rule,
344 'and',
345 $category_rule,
346 'and',
347 $close_rule,
348 'end',
349 ],
350
351 # loc_dc, __dc
352 'or',
353 [
354 'begin',
355 qr{ \b N? (?: loc_ | __ ) ( dc x? ) \s* [(] }xms,
356 'and',
357 $domain_rule,
358 'and',
359 $comma_rule,
360 'and',
361 $text_rule,
362 'and',
363 $comma_rule,
364 'and',
365 $category_rule,
366 'and',
367 $close_rule,
368 'end',
369 ],
370 'or',
371 [
372 'begin',
373 qr{ \b N? (?: loc_ | __ ) ( dcn x? ) \s* [(] }xms,
374 'and',
375 $domain_rule,
376 'and',
377 $comma_rule,
378 'and',
379 $singular_rule,
380 'and',
381 $comma_rule,
382 'and',
383 $plural_rule,
384 'and',
385 $comma_rule,
386 'and',
387 $count_rule,
388 'and',
389 $comma_rule,
390 'and',
391 $category_rule,
392 'and',
393 $close_rule,
394 'end',
395 ],
396 'or',
397 [
398 'begin',
399 qr{ \b N? (?: loc_ | __ ) ( dcp x? ) \s* [(] }xms,
400 'and',
401 $domain_rule,
402 'and',
403 $comma_rule,
404 'and',
405 $context_rule,
406 'and',
407 $comma_rule,
408 'and',
409 $text_rule,
410 'and',
411 $comma_rule,
412 'and',
413 $category_rule,
414 'and',
415 $close_rule,
416 'end',
417 ],
418 'or',
419 [
420 'begin',
421 qr{ \b N? (?: loc_ | __ ) ( dcnp x? ) \s* [(] }xms,
422 'and',
423 $domain_rule,
424 'and',
425 $comma_rule,
426 'and',
427 $context_rule,
428 'and',
429 $comma_rule,
430 'and',
431 $singular_rule,
432 'and',
433 $comma_rule,
434 'and',
435 $plural_rule,
436 'and',
437 $comma_rule,
438 'and',
439 $count_rule,
440 'and',
441 $comma_rule,
442 'and',
443 $category_rule,
444 'and',
445 $close_rule,
446 'end',
447 ],
448
449 # loc_b... (BabelFish)
450 'or',
451 [
452 'begin',
453 qr{ \b N? loc_b () \s* [(] }xms,
454 'and',
455 $text_rule,
456 'and',
457 $close_rule,
458 'end',
459 ],
460 'or',
461 [
462 'begin',
463 qr{ \b N? loc_b ( p ) \s* [(] }xms,
464 'and',
465 $context_rule,
466 'and',
467 $comma_rule,
468 'and',
469 $text_rule,
470 'and',
471 $close_rule,
472 'end',
473 ],
474 'or',
475 [
476 'begin',
477 qr{ \b N? loc_b ( d ) \s* [(] }xms,
478 'and',
479 $domain_rule,
480 'and',
481 $comma_rule,
482 'and',
483 $text_rule,
484 'and',
485 $close_rule,
486 'end',
487 ],
488 'or',
489 [
490 'begin',
491 qr{ \b N? loc_b ( dp ) \s* [(] }xms,
492 'and',
493 $domain_rule,
494 'and',
495 $comma_rule,
496 'and',
497 $context_rule,
498 'and',
499 $comma_rule,
500 'and',
501 $text_rule,
502 'and',
503 $close_rule,
504 'end',
505 ],
506 'or',
507 [
508 'begin',
509 qr{ \b N? loc_b ( c ) \s* [(] }xms,
510 'and',
511 $text_rule,
512 'and',
513 $comma_rule,
514 'and',
515 $category_rule,
516 'and',
517 $close_rule,
518 'end',
519 ],
520 'or',
521 [
522 'begin',
523 qr{ \b N? loc_b ( cp ) \s* [(] }xms,
524 'and',
525 $context_rule,
526 'and',
527 $comma_rule,
528 'and',
529 $text_rule,
530 'and',
531 $comma_rule,
532 'and',
533 $category_rule,
534 'and',
535 $close_rule,
536 'end',
537 ],
538 'or',
539 [
540 'begin',
541 qr{ \b N? loc_b ( dc ) \s* [(] }xms,
542 'and',
543 $domain_rule,
544 'and',
545 $comma_rule,
546 'and',
547 $text_rule,
548 'and',
549 $comma_rule,
550 'and',
551 $category_rule,
552 'and',
553 $close_rule,
554 'end',
555 ],
556 'or',
557 [
558 'begin',
559 qr{ \b N? loc_b ( dcp ) \s* [(] }xms,
560 $domain_rule,
561 'and',
562 $comma_rule,
563 'and',
564 $context_rule,
565 'and',
566 $comma_rule,
567 'and',
568 $text_rule,
569 'and',
570 $comma_rule,
571 'and',
572 $category_rule,
573 'and',
574 $close_rule,
575 'end',
576 ],
577
578 # maketext loc, localise, localize
579 'or',
580 [
581 'begin',
582 qr{ \b N? loc (?: ali[sz]e )? (?: _m )? () \s* [(] }xms,
583 'and',
584 $text_rule,
585 'and',
586 $close_rule,
587 'end',
588 ],
589 'or',
590 [
591 'begin',
592 qr{ \b N? loc (?: ali[sz]e )? _m ( p ) \s* [(] }xms,
593 'and',
594 $context_rule,
595 'and',
596 $comma_rule,
597 'and',
598 $text_rule,
599 'and',
600 $close_rule,
601 'end',
602 ],
603
604 # maketext
605 'or',
606 [
607 'begin',
608 qr{ \b N? maketext () \s* [(] }xms,
609 'and',
610 $text_rule,
611 'and',
612 $close_rule,
613 'end',
614 ],
615 'or',
616 [
617 'begin',
618 qr{ \b N? maketext_ ( p ) \s* [(] }xms,
619 'and',
620 $context_rule,
621 'and',
622 $comma_rule,
623 'and',
624 $text_rule,
625 'and',
626 $close_rule,
627 'end',
628 ],
629
630 # begin
631 'or',
632 [
633 'begin',
634 qr{ \b (?: loc_ | __ ) ( begin ) _ ( [dc] ) \s* [(] }xms,
635 'and',
636 $domain_or_category_rule,
637 'end',
638 ],
639 'or',
640 [
641 'begin',
642 qr{ \b (?: loc_ | __ ) ( begin ) [_] ( dc ) \s* [(] }xms,
643 'and',
644 $domain_rule,
645 'and',
646 $comma_rule,
647 'and',
648 $category_rule,
649 'end',
650 ],
651 'or',
652 [
653 'begin',
654 qr{ \b loc_begin_b ( [dc] ) \s* [(] }xms,
655 'and',
656 $domain_or_category_rule,
657 'end',
658 ],
659 'or',
660 [
661 'begin',
662 qr{ \b loc_begin_b ( dc ) \s* [(] }xms,
663 'and',
664 $domain_rule,
665 'and',
666 $comma_rule,
667 'and',
668 $category_rule,
669 'end',
670 ],
671
672 # end
673 'or',
674 [
675 'begin',
676 qr{ \b (?: loc_ | __ ) ( end ) [_] ( [dc] ) \b }xms,
677 'end',
678 ],
679 'or',
680 [
681 'begin',
682 qr{ \b (?: loc_ | __ ) ( end ) [_] ( dc ) \b }xms,
683 'end',
684 ],
685 'or',
686 [
687 'begin',
688 qr{ \b loc_end_b ( [dc] ) \b }xms,
689 'end',
690 ],
691 'or',
692 [
693 'begin',
694 qr{ \b loc_end_b ( dc ) \b }xms,
695 'end',
696 ],
697 ];
698
699 # remove pod and all lines after __END__, handle different newlines
700 16 ▶sub preprocess {
Subroutine preprocess: called CC=8 SCAR=21.8
Pod documented
701 16 my $self = shift;
702
703 16 my $content_ref = $self->content_ref;
704
705 # remove all lines after __END__
706 # replace pod without killing the line number
707 16 my ($is_pod, $is_end);
708 16 ${$content_ref}
709 = join "\n",
710 map {
711 16 ▶ $_ eq '__END__' ? do { $is_end = 1; q{} }
Branch: 3 branches
BranchTrueFalseTotal
$is_end ? : 200 1208 1408
/ \A [=] ( \w+ ) /msx ? : 4 1204 1208
lc $1 eq 'cut' ? : 2 2 4
712 : $is_end ? ()
713 : m{ \A [=] ( \w+ ) }xms ? (
714 lc $1 eq 'cut'
715 2 ? do { $is_pod = 0; q{} }
716 1424 ▶ : do { $is_pod = 1; q{} }
Branch: 2 branches
BranchTrueFalseTotal
$_ eq '__END__' ? : 16 1408 1424
$is_pod ? : 2 1202 1204
717 )
718 : $is_pod ? q{}
719 : $_;
720 }
721 16 split m{ \r? \n }xms, ${$content_ref};
722
723 # replace heredoc's without killing the line number
724 # <<'...'
725 REPLACE: {
726 16 ▶ ${$content_ref} =~ s{
Branch: 1 branch
BranchTrueFalseTotal
${$content_ref;} =~ s[ << \s* ' ( \w+ ) ' ( [^\n]* ) \n ( .*? ) ^ \1 $ ]["\n'" . do { my $text = $3; $text =~ s/'/\\'/gmsx; $text } . q['] . $2;]egmsx and redo REPLACE 0 16 16
727 << \s* ' ( \w+ ) ' ( [^\n]* ) \n
728 ( .*? )
729 ^ \1 $
730 }
731 {
732 qq{\n'}
733 0 . do { my $text = $3; $text =~ s{'}{\\'}xmsg; $text }
734 . q{'}
735 . $2
736 }xmsge and redo REPLACE;
737 }
738 # <<...
739 # <<"..."
740 REPLACE: {
741 16 ▶ ${$content_ref} =~ s{
Branch: 1 branch
BranchTrueFalseTotal
${$content_ref;} =~ s[ << \s* ( ["]? ) ( \w+ ) \1 ( [^\n]* ) \n ( .*? ) ^ \2 $ ][qq[\n"] . do { my $text = $4; $text =~ s/"/\\"/gmsx; $text } . '"' . $3;]egmsx and redo REPLACE 0 16 16
742 << \s* ( ["]? ) ( \w+ ) \1 ( [^\n]* ) \n
743 ( .*? )
744 ^ \2 $
745 }
746 {
747 qq{\n"}
748 0 . do { my $text = $4; $text =~ s{"}{\\"}xmsg; $text }
749 . q{"}
750 . $3
751 }xmsge and redo REPLACE;
752 }
753
754 16 return $self;
755 }
756
757 281 ▶sub interpolate_escape_sequence {
Subroutine interpolate_escape_sequence: called CC=9 SCAR=27.2
Pod documented
758 281 my ( undef, $string, $quot ) = @_;
759
760 # nothing to interpolate
761 281 ▶ defined $string
Branch: 1 branch
BranchTrueFalseTotal
defined $string or return $string 278 3 281
762 or return $string;
763 278 ▶ defined $quot
Branch: 1 branch
BranchTrueFalseTotal
defined $quot or confess("Quote expected") 278 0 278
764 or confess 'Quote expected';
765
766 278 ▶ my $is_interpolate = $quot eq q{"} || $quot eq 'qq{';
Condition33%1/3
$quot eq '"' || $quot eq 'qq{'
l!l&&r!l&&!r
00278
MC/DC0%0/2
$quot eq '"' || $quot eq 'qq{'
$quot eq '"' $quot eq 'qq{'
Truth table33%1/3
A || B
A= $quot eq '"'B= $quot eq 'qq{'
ABresult
1X1
011
000
767 278 ▶ if ( ! $is_interpolate ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_interpolate) 278 0 278
768 # '...'
769 278 ▶ if ( $quot eq q{'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quot eq "'") 272 6 278
770 272 $string =~ s{ \\ ( ['] ) }{$1}xmsg;
771 272 return $string;
772 }
773 # q{...}
774 6 ▶ if ( $quot eq 'q{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quot eq "q{") 6 0 6
775 6 $string =~ s{ \\ ( [\{\}] ) }{$1}xmsg; ## no critic (EscapedMetacharacters)
776 6 return $string;
777 }
778 0 confess "Unknown quot $quot";
779 }
780
781 # "..."
782 # qq{...}
783 0 my %char_of = (
784 b => "\b",
785 f => "\f",
786 n => "\n",
787 r => "\r",
788 t => "\t",
789 );
790 0 $string =~ s{
791 \\
792 (?:
793 ( [bfnrt] ) # Backspace
794 # Form feed
795 # New line
796 # Carriage return
797 # Horizontal tab
798 | ( [xN] ) # do not handle \x.., \x{...}, \N{...}
799 | (.) # Backslash itself
800 # Single quotation mark
801 # Double quotation mark
802 # anything else that needs no escape
803 )
804 }{
805 0 ▶ $1 ? $char_of{$1}
Branch: 2 branches
BranchTrueFalseTotal
$1 ? : 0 0 0
$2 ? : 0 0 0
806 : $2 ? "\\$2"
807 : $3
808 }xmsge;
809
810 0 return $string;
811 }
812
813 163 ▶sub stack_item_mapping {
Subroutine stack_item_mapping: called CC=10 SCAR=23.0
Pod documented
814 163 my $self = shift;
815
816 163 my $match = $_->{match};
817 # The chars e.g. after loc_ were stored to make a decision now.
818 163 my $extra_parameter = shift @{$match};
819 163 ▶ @{$match}
Branch: 1 branch
BranchTrueFalseTotal
@{$match;} or return 157 6 163
820 or return;
821
822 157 ▶ if ( $extra_parameter eq 'begin' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extra_parameter eq "begin") 6 151 157
823 {
824 2 ▶ d => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
825 2 push @{ $self->domain_stack }, $self->domain;
826 $self->domain(
827 scalar $self->interpolate_escape_sequence(
828 2 reverse splice @{$match}, 0, 2
829 ),
830 );
831 },
832 2 ▶ c => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
833 2 push @{ $self->category_stack }, $self->category;
834 $self->category(
835 scalar $self->interpolate_escape_sequence(
836 2 reverse splice @{$match}, 0, 2
837 ),
838 );
839 },
840 2 ▶ dc => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
841 2 push @{ $self->domain_stack }, $self->domain;
842 $self->domain(
843 scalar $self->interpolate_escape_sequence(
844 2 reverse splice @{$match}, 0, 2
845 ),
846 );
847 2 push @{ $self->category_stack }, $self->category;
848 $self->category(
849 scalar $self->interpolate_escape_sequence(
850 2 reverse splice @{$match}, 0, 2
851 ),
852 );
853 },
854 6 }->{ shift @{$match} }->();
855 6 return;
856 }
857 151 ▶ if ( $extra_parameter eq 'end' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extra_parameter eq "end") 6 145 151
858 {
859 2 ▶ d => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
860 2 ▶ @{ $self->domain_stack }
Branch: 1 branch
BranchTrueFalseTotal
@{$self->domain_stack;} or confess("Domain stack is empty because end_d is called without begin_d or begin_dc before") 2 0 2
861 or confess 'Domain stack is empty because end_d is called without begin_d or begin_dc before';
862 2 $self->domain( pop @{ $self->domain_stack } );
863 },
864 2 ▶ c => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
865 2 ▶ @{ $self->category_stack }
Branch: 1 branch
BranchTrueFalseTotal
@{$self->category_stack;} or confess("Category stack is empty because end_c is called without begin_c or begin_dc before") 2 0 2
866 or confess 'Category stack is empty because end_c is called without begin_c or begin_dc before';
867 2 $self->category( pop @{ $self->category_stack } );
868 },
869 2 ▶ dc => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
870 2 ▶ @{ $self->domain_stack }
Branch: 1 branch
BranchTrueFalseTotal
@{$self->domain_stack;} or confess("Domain stack is empty because end_dc is called without begin_d or begin_dc before") 2 0 2
871 or confess 'Domain stack is empty because end_dc is called without begin_d or begin_dc before';
872 2 ▶ @{ $self->category_stack }
Branch: 1 branch
BranchTrueFalseTotal
@{$self->category_stack;} or confess("Category stack is empty because end_dc is called without begin_c or begin_dc before") 2 0 2
873 or confess 'Category stack is empty because end_dc is called without begin_c or begin_dc before';
874 2 $self->domain( pop @{ $self->domain_stack } );
875 2 $self->category( pop @{ $self->category_stack } );
876 },
877 6 }->{ shift @{$match} }->();
878 6 return;
879 }
880
881 145 my $count;
882 $self->add_message({
883 reference => ( sprintf '%s:%s', $self->filename, $_->{line_number} ),
884 domain => $extra_parameter =~ m{ d }xms
885 ? scalar $self->interpolate_escape_sequence(
886 26 ▶ reverse splice @{$match}, 0, 2
Branch: 1 branch
BranchTrueFalseTotal
$extra_parameter =~ / p /msx ? : 48 97 145
887 )
888 : $self->domain,
889 msgctxt => $extra_parameter =~ m{ p }xms
890 ? scalar $self->interpolate_escape_sequence(
891 48 reverse splice @{$match}, 0, 2
892 )
893 : undef,
894 msgid => scalar $self->interpolate_escape_sequence(
895 145 ▶ reverse splice @{$match}, 0, 2
Branch: 1 branch
BranchTrueFalseTotal
$extra_parameter =~ / n /msx ? : 28 117 145
896 ),
897 msgid_plural => $extra_parameter =~ m{ n }xms
898 ? do {
899 my $plural = $self->interpolate_escape_sequence(
900 28 reverse splice @{$match}, 0, 2
901 );
902 28 $count = shift @{$match};
903 28 ▶ $plural;
Branch: 1 branch
BranchTrueFalseTotal
$extra_parameter =~ / c /msx ? : 26 119 145
904 }
905 : undef,
906 category => $extra_parameter =~ m{ c }xms
907 ? scalar $self->interpolate_escape_sequence(
908 26 reverse splice @{$match}, 0, 2
909 )
910 : $self->category,
911 145 ▶ automatic => do {
Branch: 1 branch
BranchTrueFalseTotal
$extra_parameter =~ / d /msx ? : 26 119 145
912 145 my $placeholders = shift @{$match};
913 my $string = join ', ', map { ## no critic (MutatingListFunctions)
914 145 defined $_
915 290 ▶ ? do {
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 170 120 290
916 170 s{ \s+ }{ }xmsg;
917 170 s{ \s+ \z }{}xms;
918 170 ▶ length $_ ? $_ : ();
Branch: 1 branch
BranchTrueFalseTotal
length $_ ? : 88 82 170
919 }
920 : ();
921 } ( $count, $placeholders );
922 145 $string =~ s{ \A ( .{70} ) .+ \z }{$1 ...}xms;
923 145 $string;
924 },
925 });
926
927 145 return;
928 }
929
930 14 ▶sub extract {
Subroutine extract: called CC=2 SCAR=6.9
Pod documented
931 14 my $self = shift;
932
933 14 $self->start_rule( $self->_filtered_start_rule );
934 14 $self->rules($rules);
935 14 $self->preprocess;
936 14 $self->SUPER::extract;
937 14 for ( @{ $self->stack } ) {
938 163 $self->stack_item_mapping;
939 }
940
941 14 return $self;
942 }
943
944 3 __PACKAGE__->meta->make_immutable;
945
946 3 1;
947
948 __END__
« Extract/TT.pm ↑ Summary Extract/JavaScript.pm »