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

filter: Statementstmt 89.3% 67 / 75 Branchbran 57.4% 31 / 54 Conditioncond 41.1% 14 / 34 MC/DCmcdc 5.0% 1 / 20 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 5 totaltotal 60.9% 120 / 197 CC 42 SCAR 28.7
CC
42
Cov
69%
parse
28.5
parse_metadata
16.9
__ANON__
14.3
CRAP 17.7
↑ Summary
1 package Locale::Maketext::Lexicon::Getcontext;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use Locale::Maketext::Lexicon::Gettext;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = "0.05";
8 3 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 3 *parse_mo = \&Locale::Maketext::Lexicon::Gettext::parse_mo;
15 3 *_unescape = \&Locale::Maketext::Lexicon::Gettext::_unescape;
16 3 *_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 8 ▶sub parse {
Subroutine parse: called CC=17 SCAR=33.5
Pod undocumented
27 8 my $self = shift;
28 8 my ( %var, $key, @ret );
29 8 my @metadata;
30 8 my @comments;
31 8 my @fuzzy;
32  
33 8 $InputEncoding = $OutputEncoding = $DoEncoding = undef;
34  
35 3 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 8 ▶ Carp::cluck "Undefined source called\n" unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 8 8
37  
38 # Check for magic string of MO files
39 8 ▶ return parse_mo( join( '', @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /^\x95\x04\x12\xde/ or $_[0] =~ /^\xde\x12\x04\x95/ 0 8 8
Condition33%1/3
$_[0] =~ /^\x95\x04\x12\xde/ or $_[0] =~ /^\xde\x12\x04\x95/
l!l&&r!l&&!r
008
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 8 local $^W; # no 'uninitialized' warnings, please.
43  
44 8 require Locale::Maketext::Lexicon;
45 8 my $KeepFuzzy = Locale::Maketext::Lexicon::option('keep_fuzzy');
46 8 ▶ my $UseFuzzy = $KeepFuzzy
Condition33%1/3
$KeepFuzzy || Locale::Maketext::Lexicon::option('use_fuzzy')
l!l&&r!l&&!r
008
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 8 my $AllowEmpty = Locale::Maketext::Lexicon::option('allow_empty');
49 3470 ▶ my $process = sub {
Subroutine __ANON__: called CC=8 SCAR=26.6
50 3470 ▶ if ( length( $var{msgstr} ) and ( $UseFuzzy or !$var{fuzzy} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $var{'msgstr'} and $UseFuzzy || !$var{'fuzzy'}) { } 3470 0 3470
elsif ($AllowEmpty) { } 0 0 0
Condition33%2/6
length $var{"msgstr"} and $UseFuzzy || !$var{"fuzzy"}
!ll&&!rl&&r
003470
$UseFuzzy or not $var{"fuzzy"}
l!l&&r!l&&!r
034700
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 3470 push @ret, ( map transform($_), @var{ 'msgctxt', 'msgstr' } );
52 }
53 elsif ($AllowEmpty) {
54 0 push @ret, ( transform( $var{msgctxt} ), '' );
55 }
56 3470 ▶ if ( $var{msgctxt} eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var{'msgctxt'} eq '') { } 8 3462 3470
57 8 push @metadata, parse_metadata( $var{msgstr} );
58 }
59 else {
60 3462 push @comments, $var{msgctxt}, $var{msgcomment};
61 }
62 3470 ▶ if ( $KeepFuzzy && $var{fuzzy} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($KeepFuzzy and $var{"fuzzy"}) 0 3470 3470
Condition33%1/3
$KeepFuzzy and $var{"fuzzy"}
!ll&&!rl&&r
347000
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 3470 %var = ();
66 8 };
67  
68 # Parse PO files
69 8 foreach (@_) {
70 15406 s/[\015\012]*\z//; # fix CRLF issues
71  
72 /^(msgctxt|msgid|msgstr) +"(.*)" *$/
73 ? do { # leading strings
74 10402 $var{$1} = $2;
75 10402 ▶ $key = $1;
Branch: 1 branch
BranchTrueFalseTotal
/^"(.*)" *$/ ? : 1534 3470 5004
76 }
77 :
78  
79 /^"(.*)" *$/
80 ? do { # continued strings
81 1534 ▶ $var{$key} .= $1;
Branch: 1 branch
BranchTrueFalseTotal
/^# (.*)$/ ? : 0 3470 3470
82 }
83 :
84  
85 /^# (.*)$/
86 ? do { # user comments
87 0 ▶ $var{msgcomment} .= $1 . "\n";
Branch: 1 branch
BranchTrueFalseTotal
/^#, +(.*) *$/ ? : 0 3470 3470
88 }
89 :
90  
91 /^#, +(.*) *$/
92 ? do { # control variables
93 0 ▶ $var{$_} = 1 for split( /,\s+/, $1 );
Branch: 1 branch
BranchTrueFalseTotal
/^ *$/ && %var ? : 3470 0 3470
Condition33%1/3
/^ *$/ and %var
!ll&&!rl&&r
003470
MC/DC0%0/2
/^ *$/ and %var
/^ *$/ %var
Truth table33%1/3
A and B
A= /^ *$/B= %var
ABresult
0X0
100
111
94 }
95 :
96  
97 /^ *$/ && %var
98 15406 ▶ ? do { # interpolate string escapes
Branch: 1 branch
BranchTrueFalseTotal
/^(msgctxt|msgid|msgstr) +"(.*)" *$/ ? : 10402 5004 15406
99 3470 $process->($_);
100 }
101 : ();
102  
103 }
104  
105 # do not silently skip last entry
106 8 ▶ $process->() if keys %var != 0;
Branch: 1 branch
BranchTrueFalseTotal
if keys %var != 0 0 8 8
107  
108 0 push @ret, map { transform($_) } @var{ 'msgctxt', 'msgstr' }
109 8 ▶ if length $var{msgstr};
Branch: 1 branch
BranchTrueFalseTotal
if length $var{"msgstr"} 0 8 8
110 push @metadata, parse_metadata( $var{msgstr} )
111 8 ▶ if $var{msgctxt} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $var{"msgctxt"} eq "" 8 0 8
112  
113 return wantarray
114 8 ▶ ? ( { @metadata, @ret }, {@comments}, {@fuzzy} )
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 8 8
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 16 ▶sub parse_metadata {
Subroutine parse_metadata: called CC=12 SCAR=28.3
Pod undocumented
127 return map {
128 16 (/^([^\x00-\x1f\x80-\xff :=]+):\s*(.*)$/)
129 ? ( $1 eq 'Content-Type' )
130 64 ▶ ? do {
Branch: 2 branches
BranchTrueFalseTotal
/^([^\x00-\x1f\x80-\xff :=]+):\s*(.*)$/ ? : 64 0 64
$1 eq 'Content-Type' ? : 8 56 64
131 8 my $enc = $2;
132 8 ▶ if ( $enc =~ /\bcharset=\s*([-\w]+)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc =~ /\bcharset=\s*([-\w]+)/i) 8 0 8
133 8 ▶ $InputEncoding = $1 || '';
Condition50%1/2
$1 || ''
l!l
80
MC/DC0%0/1
$1 || ''
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
134 8 ▶ $OutputEncoding
Condition50%1/2
Locale::Maketext::Lexicon::encoding() || ''
l!l
08
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 8 ▶ $InputEncoding = 'utf8'
Branch: 1 branch
BranchTrueFalseTotal
if $InputEncoding =~ /^utf-?8$/i 8 0 8
138 if $InputEncoding =~ /^utf-?8$/i;
139 8 ▶ $OutputEncoding = 'utf8'
Branch: 1 branch
BranchTrueFalseTotal
if $OutputEncoding =~ /^utf-?8$/i 0 8 8
140 if $OutputEncoding =~ /^utf-?8$/i;
141 8 ▶ if (Locale::Maketext::Lexicon::option('decode')
Branch: 1 branch
BranchTrueFalseTotal
if (Locale::Maketext::Lexicon::option("decode") and !$OutputEncoding || $InputEncoding ne $OutputEncoding) 8 0 8
Condition33%2/6
Locale::Maketext::Lexicon::option("decode") and !$OutputEncoding || $InputEncoding ne $OutputEncoding
!ll&&!rl&&r
008
not $OutputEncoding or $InputEncoding ne $OutputEncoding
l!l&&r!l&&!r
800
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 table25%1/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 8 ▶ require Encode::compat if $] < 5.007001;
Branch: 1 branch
BranchTrueFalseTotal
if $] < "5.007001" 0 8 8
147 8 require Encode;
148 8 $DoEncoding = 1;
149 }
150 }
151 8 ( "__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 6956 ▶sub transform {
Subroutine transform: called CC=8 SCAR=22.6
Pod undocumented
166 6956 my $str = shift;
167  
168 6956 ▶ if ( $DoEncoding and $InputEncoding ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DoEncoding and $InputEncoding) 6932 24 6956
Condition66%2/3
$DoEncoding and $InputEncoding
!ll&&!rl&&r
2406932
MC/DC50%1/2
$DoEncoding and $InputEncoding
$DoEncoding $InputEncoding
Truth table66%2/3
A and B
A= $DoEncodingB= $InputEncoding
ABresult
0X0
100
111
169 6932 ▶ $str
Branch: 1 branch
BranchTrueFalseTotal
$InputEncoding eq 'utf8' ? : 6932 0 6932
170 = ( $InputEncoding eq 'utf8' )
171 ? Encode::decode_utf8($str)
172 : Encode::decode( $InputEncoding, $str );
173 }
174  
175 6956 $str =~ s/\\([0x]..|c?.)/qq{"\\$1"}/eeg;
176  
177 6956 ▶ if ( $DoEncoding and $OutputEncoding ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DoEncoding and $OutputEncoding) 0 6956 6956
Condition66%2/3
$DoEncoding and $OutputEncoding
!ll&&!rl&&r
2469320
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 6956 ▶ return Locale::Maketext::Lexicon::option('disable_maketext_conversion')
Branch: 1 branch
BranchTrueFalseTotal
Locale::Maketext::Lexicon::option('disable_maketext_conversion') ? : 3478 3478 6956
185 ? $str : _gettext_to_maketext($str);
186 }
187  
188  
189 3 __PACKAGE__
190  
191 __END__
↑ Summary