blib/lib/Test/Locale/PO.pm

filter: Statementstmt 87.2% 41 / 47 Branchbran 75.0% 12 / 16 Conditioncond 66.6% 10 / 15 MC/DCmcdc 55.5% 5 / 9 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 79.5% 74 / 93 CC 17 SCAR 28.5
CC
17
Cov
81%
po_file_ok
21.1
BEGIN
1.0
BEGIN
1.0
CRAP 17.3
↑ Summary
1 package Test::Locale::PO;
2 # ABSTRACT: check PO files for empty/fuzzy translations
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 our $VERSION = '1.02'; # VERSION
7  
8 2 ▶use base 'Test::Builder::Module';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our @EXPORT = qw( po_file_ok );
11  
12 2 ▶use Locale::PO;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 my $CLASS = __PACKAGE__;
15  
16 5 ▶sub po_file_ok {
Subroutine po_file_ok: called CC=17 SCAR=30.5
Pod documented
17 5 my $file = shift;
18 5 my $opts = { empty => 1, fuzzy => 1, @_ };
19 5 my $tb = $CLASS->builder;
20  
21 5 ▶ if( ! -f $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $file) 0 5 5
22 0 $tb->ok(0, $file.' does not exist!');
23 0 return;
24 }
25
26 5 my $content;
27 5 eval {
28 5 $content = Locale::PO->load_file_asarray( $file );
29 };
30 5 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 5 5
31 0 $tb->ok(0, 'could not load PO file!');
32 0 return;
33 }
34 5 ▶ if( scalar(@$content) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$content == 0) 0 5 5
35 0 $tb->ok(0, 'PO file has no entries!');
36 0 return;
37 }
38  
39 5 my @no_msgstr;
40 my @fuzzy;
41 5 foreach my $po ( @$content ) {
42 20 ▶ if( $opts->{'empty'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"empty"}) 16 4 20
43 # check for a simple translation
44 16 ▶ if ( defined $po->msgstr && $po->msgstr !~ m/^["\- ]*$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $po->msgstr and not $po->msgstr =~ /^["\- ]*$/) { } 15 1 16
elsif (defined $po->msgid_plural and defined $po->msgstr_n->{'0'} and not $po->msgstr_n->{'0'} =~ /^["\- ]*$/) { } 0 1 1
Condition66%2/3
defined $po->msgstr and not $po->msgstr =~ /^["\- ]*$/
!ll&&!rl&&r
0115
MC/DC50%1/2
defined $po->msgstr and not $po->msgstr =~ /^["\- ]*$/
defined $po->msgstr not $po->msgstr =~ /^["\- ]*$/
Truth table66%2/3
A and not(B)
A= defined $po->msgstrB= not $po->msgstr =~ /^["\- ]*$/
ABresult
0X0
100
111
45 }
46 # check if plurals are involved
47 ▶ elsif( defined $po->msgid_plural
Condition33%2/6
defined $po->msgid_plural and defined $po->msgstr_n->{0} and not $po->msgstr_n->{0} =~ /^["\- ]*$/
!ll&&!rl&&r
100
defined $po->msgid_plural and defined $po->msgstr_n->{0}
!ll&&!rl&&r
100
MC/DC0%0/3
defined $po->msgid_plural and defined $po->msgstr_n->{0} and not $po->msgstr_n->{0} =~ /^["\- ]*$/
defined $po->msgid_plural defined $po->msgstr_n->{0} not $po->msgstr_n->{0} =~ /^["\- ]*$/
Truth table25%1/4
A and B and not(C)
A= defined $po->msgid_pluralB= defined $po->msgstr_n->{0}C= not $po->msgstr_n->{0} =~ /^["\- ]*$/
ABCresult
0XX0
10X0
1100
1111
48 && defined $po->msgstr_n->{"0"}
49 && $po->msgstr_n->{"0"} !~ m/^["\- ]*$/ ) {
50 } else {
51 1 push( @no_msgstr, $po );
52 }
53 }
54 20 ▶ if( $opts->{'fuzzy'} && $po->has_flag('fuzzy') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"fuzzy"} and $po->has_flag("fuzzy")) 1 19 20
Condition100%3/3
$opts->{"fuzzy"} and $po->has_flag("fuzzy")
!ll&&!rl&&r
4151
MC/DC100%2/2
$opts->{"fuzzy"} and $po->has_flag("fuzzy")
$opts->{"fuzzy"} $po->has_flag("fuzzy")
Truth table100%3/3
A and B
A= $opts->{"fuzzy"}B= $po->has_flag("fuzzy")
ABresult
0X0
100
111
55 1 push( @fuzzy, $po );
56 }
57 }
58  
59 5 ▶ if( scalar(@no_msgstr) != 0 || scalar(@fuzzy) != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @no_msgstr != 0 or scalar @fuzzy != 0) 2 3 5
Condition100%3/3
scalar @no_msgstr != 0 or scalar @fuzzy != 0
l!l&&r!l&&!r
113
MC/DC100%2/2
scalar @no_msgstr != 0 or scalar @fuzzy != 0
scalar @no_msgstr != 0 scalar @fuzzy != 0
Truth table100%3/3
A or B
A= scalar @no_msgstr != 0B= scalar @fuzzy != 0
ABresult
1X1
011
000
60 2 $tb->ok(0, 'check PO file '.$file.' for errors');
61 2 foreach my $po ( @no_msgstr ) {
62 1 $tb->diag('no translation for '.$po->msgid.' on line '.$po->loaded_line_number);
63 }
64 2 foreach my $po ( @fuzzy ) {
65 1 $tb->diag('fuzzy translation for '.$po->msgid.' on line '.$po->loaded_line_number);
66 }
67 2 return;
68 }
69  
70 3 $tb->ok(1, 'PO file '.$file.' is okay');
71 3 return;
72 }
73  
74 2 1;
75  
76 __END__
↑ Summary