Localize/Gettext/Parser.pm

filter: Statementstmt 100% 44 / 44 Branchbran 88.4% 23 / 26 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 96.4% 81 / 84 CC 18 SCAR 23.3
CC
18
Cov
96%
_process_block
13.0
parse_file
6.0
BEGIN
1.0
CRAP 10.3
« Localize/Storage/BerkeleyDB.pm ↑ Summary Localize/MultiLevel.pm »
1 package Data::Localize::Gettext::Parser;
2 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 has encoding => (
5 is => 'ro',
6 required => 1,
7 );
8  
9 2 has use_fuzzy => (
10 is => 'ro',
11 required => 1,
12 );
13  
14 2 has keep_empty => (
15 is => 'ro',
16 required => 1,
17 );
18  
19 11 ▶sub parse_file {
Subroutine parse_file: called CC=6 SCAR=18.0
Pod documented
20 11 my ($self, $file) = @_;
21  
22 11 my $enc = ':encoding(' . $self->encoding . ')';
23 11 ▶ open(my $fh, "<$enc", $file) or die "Could not open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<$enc", $file or die "Could not open ${file}: $!" 11 0 11
24  
25 11 my @block = ();
26 11 my %lexicons;
27 11 ▶ while ( defined( my $line = <$fh> ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 74 11 85
28 74 $line =~ s/[\015\012]*\z//; # fix CRLF issues
29  
30 74 ▶ if ( $line =~ /^\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*$/) 18 56 74
31 18 ▶ $self->_process_block(\@block, \%lexicons) if @block;
Branch: 1 branch
BranchTrueFalseTotal
if @block 18 0 18
32 18 @block = ();
33 18 next;
34 }
35  
36 56 push @block, $line;
37 }
38  
39 11 ▶ $self->_process_block(\@block, \%lexicons) if @block;
Branch: 1 branch
BranchTrueFalseTotal
if @block 7 4 11
40  
41 11 return \%lexicons;
42 }
43  
44 25 ▶sub _process_block {
Subroutine _process_block: called CC=13 SCAR=25.7
45 25 my ($self, $block, $lexicons) = @_;
46  
47 25 my $msgid = q{};
48 25 my $msgstr = q{};
49 25 my $value;
50 25 my $is_fuzzy = 0;
51  
52 # Note that we are ignoring the various types of comments allowed in a .po
53 # file - see
54 # http://www.gnu.org/software/gettext/manual/gettext.html#PO-Files for
55 # more details.
56 #
57 # We do not handle the msgstr[0]/msgstr[1] type of string.
58 #
59 # Finally, we don't handle msgctxt at all.
60 25 for my $line (@{$block} ) {
61 56 ▶ if ( $line =~ /^msgid\s+"(.*)"\s*$/ ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($line =~ /^msgid\s+"(.*)"\s*$/) { } 25 31 56
elsif ($line =~ /^msgstr\s+"(.*)"\s*$/) { } 25 6 31
elsif ($line =~ /^"(.*)"\s*$/) { } 4 2 6
elsif ($line =~ /#,\s+.*fuzzy.*$/) { } 2 0 2
62 25 $value = \$msgid;
63  
64 25 ${$value} .= $1;
65 }
66 elsif ( $line =~ /^msgstr\s+"(.*)"\s*$/ ) {
67 25 $value = \$msgstr;
68  
69 25 ${$value} .= $1;
70 }
71 elsif ( $line =~ /^"(.*)"\s*$/ ) {
72 4 ${$value} .= $1;
73 }
74 elsif ( $line =~ /#,\s+.*fuzzy.*$/ ) {
75 2 $is_fuzzy = 1;
76 }
77 }
78  
79 25 ▶ return unless length $msgstr || $self->keep_empty();
Branch: 1 branch
BranchTrueFalseTotal
unless length $msgstr or $self->keep_empty 1 24 25
Condition100%3/3
length $msgstr or $self->keep_empty
l!l&&r!l&&!r
2311
MC/DC100%2/2
length $msgstr or $self->keep_empty
length $msgstr $self->keep_empty
Truth table100%3/3
A or B
A= length $msgstrB= $self->keep_empty
ABresult
1X1
011
000
80  
81 24 ▶ return if $is_fuzzy && ! $self->use_fuzzy();
Branch: 1 branch
BranchTrueFalseTotal
if $is_fuzzy and not $self->use_fuzzy 1 23 24
Condition100%3/3
$is_fuzzy and not $self->use_fuzzy
!ll&&!rl&&r
2211
MC/DC100%2/2
$is_fuzzy and not $self->use_fuzzy
$is_fuzzy not $self->use_fuzzy
Truth table100%3/3
A and not(B)
A= $is_fuzzyB= not $self->use_fuzzy
ABresult
0X0
100
111
82  
83 23 ▶ s/\\(n|\\|\")/ $1 eq 'n' ? "\n" : $1 eq '\\' ? "\\" : '"' /ge for $msgid, $msgstr;
Branch: 2 branches
BranchTrueFalseTotal
$1 eq 'n' ? : 4 6 10
$1 eq '\\' ? : 2 4 6
84  
85 23 $lexicons->{$msgid} = $msgstr;
86  
87 23 return;
88 }
89  
90 2 1;
91  
92 __END__
« Localize/Storage/BerkeleyDB.pm ↑ Summary Localize/MultiLevel.pm »