blib/lib/Locale/Maketext/Lexicon/Getcontext.pm

filter: Statementstmt 89.3% 67 / 75 Branchbran 57.6% 30 / 52 Conditioncond 44.1% 15 / 34 MC/DCmcdc 10.0% 2 / 20 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 5 totaltotal 62.0% 121 / 195 SCAR 44.8
CC
41
Cov
70%
parse
26.3
parse_metadata
16.9
__ANON__
14.3
CRAP 88.4
↑ Summary
1 package Locale::Maketext::Lexicon::Getcontext;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Locale::Maketext::Lexicon::Gettext;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = "0.03";
8 2 my ( $InputEncoding, $OutputEncoding, $DoEncoding );
9  
10 0 ▶sub input_encoding {$InputEncoding}
Subroutine input_encoding: not called CC=1 SCAR=6.9
Pod undocumented
11 0 ▶sub output_encoding {$OutputEncoding}
Subroutine output_encoding: not called CC=1 SCAR=6.9
Pod undocumented
12  
13 # functions
14 2 *parse_mo = \&Locale::Maketext::Lexicon::Gettext::parse_mo;
15 2 *_unescape = \&Locale::Maketext::Lexicon::Gettext::_unescape;
16 2 *_gettext_to_maketext
17 = \&Locale::Maketext::Lexicon::Gettext::_gettext_to_maketext;
18  
19  
20  
21 #
22 # parse()
23 # -----
24 # copy-pasted from Locale::Maketext::Lexicon::Gettext, with s/msgid/msgctxt/g
25 #
26 sub parse {
27 4 ▶ my $self = shift;
Subroutine parse: called CC=17 SCAR=32.7
Pod undocumented
28 4 my ( %var, $key, @ret );
29 4 my @metadata;
30 4 my @comments;
31 4 my @fuzzy;
32  
33 4 $InputEncoding = $OutputEncoding = $DoEncoding = undef;
34  
35 2 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 4 ▶ Carp::cluck "Undefined source called\n" unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 4 4
37  
38 # Check for magic string of MO files
39 4 ▶ return parse_mo( join( '', @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /^\x95\x04\x12\xde/ or $_[0] =~ /^\xde\x12\x04\x95/ 0 4 4
Condition33%1/3
$_[0] =~ /^\x95\x04\x12\xde/ or $_[0] =~ /^\xde\x12\x04\x95/
l!l&&r!l&&!r
004
MC/DC0%0/2
$_[0] =~ /^\x95\x04\x12\xde/ or $_[0] =~ /^\xde\x12\x04\x95/
$_[0] =~ /^\x95\x04\x12\xde/ $_[0] =~ /^\xde\x12\x04\x95/
Truth table33%1/3
A or B
A= $_[0] =~ /^\x95\x04\x12\xde/B= $_[0] =~ /^\xde\x12\x04\x95/
ABresult
1X1
011
000
40 if ( $_[0] =~ /^\x95\x04\x12\xde/ or $_[0] =~ /^\xde\x12\x04\x95/ );
41  
42 4 local $^W; # no 'uninitialized' warnings, please.
43  
44 4 require Locale::Maketext::Lexicon;
45 4 my $KeepFuzzy = Locale::Maketext::Lexicon::option('keep_fuzzy');
46 4 ▶ my $UseFuzzy = $KeepFuzzy
Condition33%1/3
$KeepFuzzy || Locale::Maketext::Lexicon::option('use_fuzzy')
l!l&&r!l&&!r
004
MC/DC0%0/2
$KeepFuzzy || Locale::Maketext::Lexicon::option('use_fuzzy')
$KeepFuzzy Locale::Maketext::Lexicon::option('use_fuzzy')
Truth table33%1/3
A || B
A= $KeepFuzzyB= Locale::Maketext::Lexicon::option('use_fuzzy')
ABresult
1X1
011
000
47 || Locale::Maketext::Lexicon::option('use_fuzzy');
48 4 my $AllowEmpty = Locale::Maketext::Lexicon::option('allow_empty');
49 my $process = sub {
50 1734 ▶ if ( length( $var{msgstr} ) and ( $UseFuzzy or !$var{fuzzy} ) ) {
Subroutine __ANON__: called CC=8 SCAR=26.6
Branch: 2 branches
BranchTrueFalseTotal
if (length $var{'msgstr'} and $UseFuzzy || !$var{'fuzzy'}) { } 1734 0 1734
elsif ($AllowEmpty) { } 0 0 0
Condition33%2/6
length $var{"msgstr"} and $UseFuzzy || !$var{"fuzzy"}
!ll&&!rl&&r
001734
$UseFuzzy or not $var{"fuzzy"}
l!l&&r!l&&!r
017340
MC/DC0%0/3
length $var{"msgstr"} and $UseFuzzy || !$var{"fuzzy"}
length $var{"msgstr"} $UseFuzzy not $var{"fuzzy"}
Truth table25%1/4
A and B or not(C)
A= length $var{"msgstr"}B= $UseFuzzyC= not $var{"fuzzy"}
ABCresult
0XX0
1000
11X1
1011
51 1734 push @ret, ( map transform($_), @var{ 'msgctxt', 'msgstr' } );
52 }
53 elsif ($AllowEmpty) {
54 0 push @ret, ( transform( $var{msgctxt} ), '' );
55 }
56 1734 ▶ if ( $var{msgctxt} eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var{'msgctxt'} eq '') { } 4 1730 1734
57 4 push @metadata, parse_metadata( $var{msgstr} );
58 }
59 else {
60 1730 push @comments, $var{msgctxt}, $var{msgcomment};
61 }
62 1734 ▶ if ( $KeepFuzzy && $var{fuzzy} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($KeepFuzzy and $var{"fuzzy"}) 0 1734 1734
Condition33%1/3
$KeepFuzzy and $var{"fuzzy"}
!ll&&!rl&&r
173400
MC/DC0%0/2
$KeepFuzzy and $var{"fuzzy"}
$KeepFuzzy $var{"fuzzy"}
Truth table33%1/3
A and B
A= $KeepFuzzyB= $var{"fuzzy"}
ABresult
0X0
100
111
63 0 push @fuzzy, $var{msgctxt}, 1;
64 }
65 1734 %var = ();
66 4 };
67  
68 # Parse PO files
69 4 foreach (@_) {
70 7697 s/[\015\012]*\z//; # fix CRLF issues
71  
72 /^(msgctxt|msgstr) +"(.*)" *$/
73 ? do { # leading strings
74 3464 $var{$1} = $2;
75 3464 ▶ $key = $1;
Branch: 1 branch
BranchTrueFalseTotal
/^"(.*)" *$/ ? : 765 3468 4233
76 }
77 :
78  
79 /^"(.*)" *$/
80 ? do { # continued strings
81 765 ▶ $var{$key} .= $1;
Branch: 1 branch
BranchTrueFalseTotal
/^# (.*)$/ ? : 0 3468 3468
82 }
83 :
84  
85 /^# (.*)$/
86 ? do { # user comments
87 0 ▶ $var{msgcomment} .= $1 . "\n";
Branch: 1 branch
BranchTrueFalseTotal
/^#, +(.*) *$/ ? : 0 3468 3468
88 }
89 :
90  
91 /^#, +(.*) *$/
92 ? do { # control variables
93 0 ▶ $var{$_} = 1 for split( /,\s+/, $1 );
Branch: 1 branch
BranchTrueFalseTotal
/^ *$/ && %var ? : 1734 1734 3468
Condition66%2/3
/^ *$/ and %var
!ll&&!rl&&r
173401734
MC/DC50%1/2
/^ *$/ and %var
/^ *$/ %var
Truth table66%2/3
A and B
A= /^ *$/B= %var
ABresult
0X0
100
111
94 }
95 :
96  
97 /^ *$/ && %var
98 7697 ▶ ? do { # interpolate string escapes
Branch: 1 branch
BranchTrueFalseTotal
/^(msgctxt|msgstr) +"(.*)" *$/ ? : 3464 4233 7697
99 1734 $process->($_);
100 }
101 : ();
102  
103 }
104  
105 # do not silently skip last entry
106 4 ▶ $process->() if keys %var != 0;
Branch: 1 branch
BranchTrueFalseTotal
if keys %var != 0 0 4 4
107  
108 0 push @ret, map { transform($_) } @var{ 'msgctxt', 'msgstr' }
109 4 ▶ if length $var{msgstr};
Branch: 1 branch
BranchTrueFalseTotal
if length $var{"msgstr"} 0 4 4
110 push @metadata, parse_metadata( $var{msgstr} )
111 4 ▶ if $var{msgctxt} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $var{"msgctxt"} eq "" 4 0 4
112  
113 return wantarray
114 4 ▶ ? ( { @metadata, @ret }, {@comments}, {@fuzzy} )
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 4 4
115 : ( { @metadata, @ret } );
116  
117 }
118  
119  
120 #
121 # parse_metadata()
122 # --------------
123 # copy-pasted from Locale::Maketext::Lexicon::Gettext, with no change,
124 # because it accesses the $InputEncoding and $OutputEncoding vars
125 #
126 sub parse_metadata {
127 return map {
128 8 ▶ (/^([^\x00-\x1f\x80-\xff :=]+):\s*(.*)$/)
Subroutine parse_metadata: called CC=12 SCAR=28.3
Pod undocumented
129 ? ( $1 eq 'Content-Type' )
130 32 ▶ ? do {
Branch: 2 branches
BranchTrueFalseTotal
/^([^\x00-\x1f\x80-\xff :=]+):\s*(.*)$/ ? : 32 0 32
$1 eq 'Content-Type' ? : 4 28 32
131 4 my $enc = $2;
132 4 ▶ if ( $enc =~ /\bcharset=\s*([-\w]+)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc =~ /\bcharset=\s*([-\w]+)/i) 4 0 4
133 4 ▶ $InputEncoding = $1 || '';
Condition50%1/2
$1 || ''
l!l
40
MC/DC0%0/1
$1 || ''
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
134 4 ▶ $OutputEncoding
Condition50%1/2
Locale::Maketext::Lexicon::encoding() || ''
l!l
04
MC/DC0%0/1
Locale::Maketext::Lexicon::encoding() || ''
Locale::Maketext::Lexicon::encoding()
Truth table50%1/2
A
A= Locale::Maketext::Lexicon::encoding()
Aresult
11
00
135 = Locale::Maketext::Lexicon::encoding()
136 || '';
137 4 ▶ $InputEncoding = 'utf8'
Branch: 1 branch
BranchTrueFalseTotal
if $InputEncoding =~ /^utf-?8$/i 4 0 4
138 if $InputEncoding =~ /^utf-?8$/i;
139 4 ▶ $OutputEncoding = 'utf8'
Branch: 1 branch
BranchTrueFalseTotal
if $OutputEncoding =~ /^utf-?8$/i 0 4 4
140 if $OutputEncoding =~ /^utf-?8$/i;
141 4 ▶ if (Locale::Maketext::Lexicon::option('decode')
Branch: 1 branch
BranchTrueFalseTotal
if (Locale::Maketext::Lexicon::option("decode") and !$OutputEncoding || $InputEncoding ne $OutputEncoding) 4 0 4
Condition33%2/6
Locale::Maketext::Lexicon::option("decode") and !$OutputEncoding || $InputEncoding ne $OutputEncoding
!ll&&!rl&&r
040
not $OutputEncoding or $InputEncoding ne $OutputEncoding
l!l&&r!l&&!r
400
MC/DC0%0/3
Locale::Maketext::Lexicon::option("decode") and !$OutputEncoding || $InputEncoding ne $OutputEncoding
Locale::Maketext::Lexicon::option("decode") not $OutputEncoding $InputEncoding ne $OutputEncoding
Truth table0%0/4
A and not(B) or C
A= Locale::Maketext::Lexicon::option("decode")B= not $OutputEncodingC= $InputEncoding ne $OutputEncoding
ABCresult
0XX0
1000
11X1
1011
142 and ( !$OutputEncoding
143 or $InputEncoding ne $OutputEncoding )
144 )
145 {
146 4 ▶ require Encode::compat if $] < 5.007001;
Branch: 1 branch
BranchTrueFalseTotal
if $] < "5.007001" 0 4 4
147 4 require Encode;
148 4 $DoEncoding = 1;
149 }
150 }
151 4 ( "__Content-Type", $enc );
152 }
153 : ( "__$1", $2 )
154 : ();
155 } split( /\r*\n+\r*/, transform(pop) );
156 }
157  
158  
159 #
160 # transform()
161 # ---------
162 # copy-pasted from Locale::Maketext::Lexicon::Gettext, with no change,
163 # because it accesses the $InputEncoding and $OutputEncoding vars
164 #
165 sub transform {
166 3476 ▶ my $str = shift;
Subroutine transform: called CC=7 SCAR=21.5
Pod undocumented
167  
168 3476 ▶ if ( $DoEncoding and $InputEncoding ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DoEncoding and $InputEncoding) 3464 12 3476
Condition66%2/3
$DoEncoding and $InputEncoding
!ll&&!rl&&r
1203464
MC/DC50%1/2
$DoEncoding and $InputEncoding
$DoEncoding $InputEncoding
Truth table66%2/3
A and B
A= $DoEncodingB= $InputEncoding
ABresult
0X0
100
111
169 3464 ▶ $str
Branch: 1 branch
BranchTrueFalseTotal
$InputEncoding eq 'utf8' ? : 3464 0 3464
170 = ( $InputEncoding eq 'utf8' )
171 ? Encode::decode_utf8($str)
172 : Encode::decode( $InputEncoding, $str );
173 }
174  
175 3476 $str =~ s/\\([0x]..|c?.)/qq{"\\$1"}/eeg;
176  
177 3476 ▶ if ( $DoEncoding and $OutputEncoding ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DoEncoding and $OutputEncoding) 0 3476 3476
Condition66%2/3
$DoEncoding and $OutputEncoding
!ll&&!rl&&r
1234640
MC/DC0%0/2
$DoEncoding and $OutputEncoding
$DoEncoding $OutputEncoding
Truth table66%2/3
A and B
A= $DoEncodingB= $OutputEncoding
ABresult
0X0
100
111
178 0 ▶ $str
Branch: 1 branch
BranchTrueFalseTotal
$OutputEncoding eq 'utf8' ? : 0 0 0
179 = ( $OutputEncoding eq 'utf8' )
180 ? Encode::encode_utf8($str)
181 : Encode::encode( $OutputEncoding, $str );
182 }
183  
184 3476 return _gettext_to_maketext($str);
185 }
186  
187  
188 2 __PACKAGE__
189  
190 __END__
↑ Summary