Gettext/Storage/PO.pm

filter: Statementstmt 94.8% 274 / 289 Branchbran 85.9% 67 / 78 Conditioncond 67.4% 29 / 43 MC/DCmcdc 33.3% 8 / 24 Subroutinesub 97.0% 33 / 34 Podpod 100% 4 / 4 totaltotal 87.9% 415 / 472 CC 68 SCAR 16.4
CC
68
Cov
90%
__ANON__
11.4
__ANON__
9.2
__ANON__
8.0
CRAP 5.1
« Gettext/Storage.pm ↑ Summary Gettext/Schema.pm »
1 package File::Gettext::Storage::PO;
2  
3 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Date::Format ( );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Encode qw( decode encode );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::DataClass::Constants qw( NUL SPC );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::DataClass::Functions qw( extension_map );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use File::Gettext::Constants qw( CONTEXT_SEP );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 extension_map '+File::Gettext::Storage::PO' => '.po';
13  
14 2 extends q(File::DataClass::Storage);
15  
16 2 has '+extn' => default => '.po';
17  
18 # Private functions
19 205 ▶my $_comment_field = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
20 return { '#' => q(translator_comment),
21 '# ' => q(translator_comment),
22 '#.' => q(extracted_comment),
23 '#:' => q(reference),
24 '#,' => q(flags),
25 205 '#|' => q(previous), }->{ $_[ 0 ] };
26 2 };
27  
28 362 ▶my $_comment_prefix = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
29 return { 'translator_comment' => '# ',
30 'extracted_comment' => '#.',
31 'reference' => '#:',
32 'flags' => '#,',
33 362 'previous' => '#|', }->{ $_[ 0 ] };
34 2 };
35  
36 2 ▶my $_decode_hash; $_decode_hash = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
37 77 my ($charset, $in) = @_; my $out = {};
38  
39 77 for my $k (grep { defined } keys %{ $in }) {
40 398 ▶ my $values = $in->{ $k }; defined $values or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $values or next 398 0 398
41  
42 398 ▶ if (ref $values eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $values eq 'HASH') { } 7 391 398
elsif (ref $values eq 'ARRAY') { } 98 293 391
43 7 $out->{ $k } = $_decode_hash->( $charset, $values );
44 }
45 elsif (ref $values eq 'ARRAY') {
46 98 $out->{ $k } = [ map { decode( $charset, $_ ) } @{ $values } ];
47 }
48 293 else { $out->{ $k } = decode( $charset, $values ) }
49 }
50  
51 77 return $out;
52 2 };
53  
54 7 ▶my $_header_inflate = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
55 7 ▶ my $data = shift; my $header = (delete $data->{ NUL() }) || { msgstr => [] };
Condition50%1/2
delete $data->{''} || {'msgstr', []}
l!l
70
MC/DC0%0/1
delete $data->{''} || {'msgstr', []}
delete $data->{''}
Truth table50%1/2
A
A= delete $data->{''}
Aresult
11
00
56  
57 7 my $null_entry = $header->{msgstr}->[ 0 ]; $header->{msgstr} = {};
58  
59 7 ▶ $null_entry or return $header;
Branch: 1 branch
BranchTrueFalseTotal
$null_entry or return $header 2 5 7
60  
61 2 for my $line (split m{ [\n] }msx, $null_entry) {
62 20 my ($k, $v) = split m{ [:] }msx, $line, 2;
63  
64 20 $k =~ s{ [-] }{_}gmsx; $v =~ s{ \A \s+ }{}msx;
65 20 $header->{msgstr}->{ lc $k } = $v;
66 }
67  
68 2 return $header;
69 2 };
70  
71 361 ▶my $_original_order = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
72 361 my ($hash, $lhs, $rhs) = @_;
73  
74 # New elements will be added at the end
75 361 ▶ exists $hash->{ $lhs }->{_order} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $hash->{$lhs}{"_order"} or return 1 359 2 361
76 359 ▶ exists $hash->{ $rhs }->{_order} or return -1;
Branch: 1 branch
BranchTrueFalseTotal
exists $hash->{$rhs}{"_order"} or return -1 358 1 359
77 358 return $hash->{ $lhs }->{_order} <=> $hash->{ $rhs }->{_order};
78 2 };
79  
80 378 ▶my $_quote = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
81 378 my $text = shift;
82  
83 378 $text =~ s{ \A [\"] }{\\\"}msx; $text =~ s{ ([^\\])[\"] }{$1\\\"}gmsx;
84  
85 378 return '"'.$text.'\n"';
86 2 };
87  
88 205 ▶my $_store_comment = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
89 205 my ($rec, $line, $attr) = @_;
90  
91 205 ▶ my $value = length $line > 1 ? substr $line, 2 : NUL;
Branch: 1 branch
BranchTrueFalseTotal
length $line > 1 ? : 191 14 205
92  
93 205 ▶ if ($attr eq q(flags)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr eq 'flags') { } 35 170 205
94 35 push @{ $rec->{ $attr } }, map { s{ \s+ }{}msx; $_ }
95 split m{ [,] }msx, $value;
96 }
97 170 ▶ else { $rec->{ $attr } .= $rec->{ $attr } ? "\n${value}" : $value }
Branch: 1 branch
BranchTrueFalseTotal
$rec->{$attr} ? : 118 52 170
98  
99 205 return;
100 2 };
101  
102 6 ▶my $_time2str = sub {
Subroutine __ANON__: called CC=3 SCAR=11.4
103 6 my ($format, $time) = @_;
104  
105 6 ▶ defined $format or $format = '%Y-%m-%d %H:%M:%S';
Branch: 1 branch
BranchTrueFalseTotal
defined $format or $format = "%Y-%m-%d %H:%M:%S" 6 0 6
106 6 ▶ defined $time or $time = time;
Branch: 1 branch
BranchTrueFalseTotal
defined $time or $time = time 0 6 6
107  
108 6 return Date::Format::Generic->time2str( $format, $time );
109 2 };
110  
111 276 ▶my $_unquote = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
112 276 my $text = shift;
113  
114 276 $text =~ s{ [\\][n] \z }{\n}msx; $text =~ s{ [\\][\"] }{\"}gmsx;
115  
116 276 return $text;
117 2 };
118  
119 122 ▶my $_append_msgtext = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
120 122 my ($rec, $key, $last, $text) = @_;
121  
122 122 ▶ if (ref $rec->{ $key } ne 'ARRAY') { $rec->{ $key } .= $_unquote->( $text ) }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rec->{$key} ne 'ARRAY') { } 45 77 122
123 77 ▶ else { $rec->{ $key }->[ $last || 0 ] .= $_unquote->( $text ) }
Condition50%1/2
$last || 0
l!l
077
MC/DC0%0/1
$last || 0
$last
Truth table50%1/2
A
A= $last
Aresult
11
00
124  
125 122 return;
126 2 };
127  
128 154 ▶my $_store_msgtext = sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
129 154 my ($rec, $line, $last_ref) = @_; my $key;
130  
131 154 ▶ if ($line =~ m{ \A msgctxt \s+ [\"] (.*) [\"] \z }msx) {
Branch: 5 branches
BranchTrueFalseTotal
if ($line =~ / \A msgctxt \s+ [\"] (.*) [\"] \z /msx) { } 8 146 154
elsif ($line =~ / \A msgid \s+ [\"] (.*) [\"] \z /msx) { } 70 76 146
elsif ($line =~ / \A msgid_plural \s+ [\"] (.*) [\"] \z /msx) { } 3 73 76
elsif ($line =~ / \A msgstr \s+ [\"] (.*) [\"] \z /msx) { } 67 6 73
elsif ($line =~ / \A msgstr\[\s*(\d+)\s*\] \s+ [\"](.*)[\"] \z /msx) { } 6 0 6
132 8 $key = q(msgctxt); $rec->{ $key } = $_unquote->( $1 );
133 }
134 elsif ($line =~ m{ \A msgid \s+ [\"] (.*) [\"] \z }msx) {
135 70 $key = q(msgid); $rec->{ $key } = $_unquote->( $1 );
136 }
137 elsif ($line =~ m{ \A msgid_plural \s+ [\"] (.*) [\"] \z }msx) {
138 3 $key = q(msgid_plural); $rec->{ $key } = $_unquote->( $1 );
139 }
140 elsif ($line =~ m{ \A msgstr \s+ [\"] (.*) [\"] \z }msx) {
141 67 ▶ $key = q(msgstr); $rec->{ $key } ||= [];
Condition50%1/2
$rec->{$key} ||= []
l!l
067
MC/DC0%0/1
$rec->{$key} ||= []
$rec->{$key}
Truth table50%1/2
A
A= $rec->{$key}
Aresult
11
00
142 67 $rec->{ $key }->[ ${ $last_ref } = 0 ] .= $_unquote->( $1 );
143 }
144 elsif ($line =~ m{ \A msgstr\[\s*(\d+)\s*\] \s+ [\"](.*)[\"] \z }msx) {
145 6 ▶ $key = q(msgstr); $rec->{ $key } ||= [];
Condition100%2/2
$rec->{$key} ||= []
l!l
33
MC/DC100%1/1
$rec->{$key} ||= []
$rec->{$key}
Truth table100%2/2
A
A= $rec->{$key}
Aresult
11
00
146 6 $rec->{ $key }->[ ${ $last_ref } = $1 ] .= $_unquote->( $2 );
147 }
148  
149 154 return $key;
150 2 };
151  
152 # Private common methods
153 15 ▶my $_get_charset = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
154 15 my ($self, $po_header) = @_; my $charset = $self->schema->charset;
155  
156 15 ▶ my $msgstr = $po_header->{msgstr} || {};
Condition100%2/2
$po_header->{'msgstr'} || {}
l!l
123
MC/DC100%1/1
$po_header->{'msgstr'} || {}
$po_header->{'msgstr'}
Truth table100%2/2
A
A= $po_header->{'msgstr'}
Aresult
11
00
157 15 ▶ my $content_type = $msgstr->{content_type} || NUL;
Condition100%2/2
$msgstr->{'content_type'} || ''
l!l
411
MC/DC100%1/1
$msgstr->{'content_type'} || ''
$msgstr->{'content_type'}
Truth table100%2/2
A
A= $msgstr->{'content_type'}
Aresult
11
00
158  
159 15 ▶ $content_type =~ s{ .* = }{}msx and $charset = $content_type;
Branch: 1 branch
BranchTrueFalseTotal
$content_type =~ s/ .* = //msx and $charset = $content_type 4 11 15
160  
161 15 return $charset;
162 2 };
163  
164 # Private read methods
165 7 ▶my $_inflate_and_decode = sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
166 7 my ($self, $data) = @_;
167  
168 7 my $po_header = $_header_inflate->( $data );
169 7 my $charset = $self->$_get_charset( $po_header );
170 7 my $tmp = $data; $data = {};
171  
172 # Decode all keys and values using the charset from the header
173 7 ▶ for my $k (grep { $_ and defined $tmp->{ $_ } } keys %{ $tmp }) {
Condition33%1/3
$_ && defined $tmp->{$_}
!ll&&!rl&&r
0063
MC/DC0%0/2
$_ && defined $tmp->{$_}
$_ defined $tmp->{$_}
Truth table33%1/3
A && B
A= $_B= defined $tmp->{$_}
ABresult
0X0
100
111
174 63 my $rec = $tmp->{ $k }; my $id = decode( $charset, $k );
175  
176 63 $data->{ $id } = $_decode_hash->( $charset, $rec );
177 }
178  
179 7 return { po => $data, po_header => $_decode_hash->( $charset, $po_header ) };
180 2 };
181  
182 71 ▶my $_store_record = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
183 71 ▶ my ($self, $data, $rec, $order_ref) = @_; exists $rec->{msgid} or return;
Branch: 1 branch
BranchTrueFalseTotal
exists $rec->{"msgid"} or return 70 1 71
184  
185 70 ▶ my @ctxt = split m{ [\.] }msx, ($rec->{msgctxt} || NUL), 2;
Condition100%2/2
$rec->{'msgctxt'} || ''
l!l
862
MC/DC100%1/1
$rec->{'msgctxt'} || ''
$rec->{'msgctxt'}
Truth table100%2/2
A
A= $rec->{'msgctxt'}
Aresult
11
00
186  
187 70 ▶ $ctxt[ 0 ] = $ctxt[ 0 ] ? $ctxt[ 0 ].SPC : 'messages ';
Branch: 1 branch
BranchTrueFalseTotal
$ctxt[0] ? : 8 62 70
188 70 ▶ $ctxt[ 1 ] = $ctxt[ 1 ] ? SPC.$ctxt[ 1 ] : NUL;
Branch: 1 branch
BranchTrueFalseTotal
$ctxt[1] ? : 4 66 70
189 70 $rec->{labels} = $ctxt[ 0 ].$rec->{msgid}.$ctxt[ 1 ];
190 70 $rec->{_order} = ${ $order_ref }++;
191 70 $data->{ $self->make_key( $rec ) } = $rec;
192 70 return;
193 2 };
194  
195 7 ▶my $_read_filter = sub {
Subroutine __ANON__: called CC=9 SCAR=22.1
196 7 ▶ my ($self, $buf) = @_; $buf ||= [];
Condition50%1/2
$buf ||= []
l!l
70
MC/DC0%0/1
$buf ||= []
$buf
Truth table50%1/2
A
A= $buf
Aresult
11
00
197  
198 7 my ($data, $order, $rec, $key, $last) = ({}, 0, {});
199  
200 7 for my $line (grep { defined } @{ $buf }) {
201 # Lines beginning with a hash are comments
202 545 ▶ if ('#' eq substr $line, 0, 1) {
Branch: 4 branches
BranchTrueFalseTotal
if ('#' eq substr($line, 0, 1)) { } 205 340 545
elsif ('msg' eq substr($line, 0, 3)) { } 154 186 340
elsif ($line =~ / \A \s* [\"] (.+) [\"] \z /msx and defined $key) { } 122 64 186
elsif ($line =~ / \A \s* \z /msx) { } 64 0 64
203 205 my $field = $_comment_field->( substr $line, 0, 2 );
204  
205 205 ▶ $field and $_store_comment->( $rec, $line, $field );
Branch: 1 branch
BranchTrueFalseTotal
$field and &$_store_comment($rec, $line, $field) 205 0 205
206 }
207 # Field names all begin with the prefix msg
208 elsif ('msg' eq substr $line, 0, 3) {
209 154 $key = $_store_msgtext->( $rec, $line, \$last );
210 }
211 # Match any continuation lines
212 ▶ elsif ($line =~ m{ \A \s* [\"] (.+) [\"] \z }msx and defined $key) {
Condition66%2/3
$line =~ / \A \s* [\"] (.+) [\"] \z /msx and defined $key
!ll&&!rl&&r
640122
MC/DC50%1/2
$line =~ / \A \s* [\"] (.+) [\"] \z /msx and defined $key
$line =~ / \A \s* [\"] (.+) [\"] \z /msx defined $key
Truth table66%2/3
A and B
A= $line =~ / \A \s* [\"] (.+) [\"] \z /msxB= defined $key
ABresult
0X0
100
111
213 122 $_append_msgtext->( $rec, $key, $last, $1 );
214 }
215 # A blank line ends the record
216 elsif ($line =~ m{ \A \s* \z }msx) {
217 64 $self->$_store_record( $data, $rec, \$order );
218 64 $key = undef; $last = undef; $rec = {};
219 }
220 }
221  
222 7 $self->$_store_record( $data, $rec, \$order ); # If the last line isn't blank
223  
224 7 return $self->$_inflate_and_decode( $data );
225 2 };
226  
227 # Private write methods
228 3 ▶my $_default_po_header = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
229 3 my $self = shift;
230 3 my $charset = $self->schema->charset;
231 3 my $defaults = $self->schema->default_po_header;
232 3 my $appname = $defaults->{appname };
233 3 my $company = $defaults->{company };
234 3 my $email = $defaults->{email };
235 3 my $lang = $defaults->{lang };
236 3 my $team = $defaults->{team };
237 3 my $translator = $defaults->{translator};
238 3 my $rev_date = $_time2str->( '%Y-%m-%d %H:%M%z' );
239 3 my $year = $_time2str->( '%Y' );
240  
241 return {
242 3 'translator_comment' => join "\n", ( '@(#)$Id'.'$',
243 'GNU Gettext Portable Object.',
244 "Copyright (C) ${year} ${company}.",
245 "${translator} ${email}, ${year}.",
246 '', ),
247 flags => [ 'fuzzy', ],
248 msgstr => {
249 'project_id_version' => "${appname} ${File::Gettext::VERSION}",
250 'po_revision_date' => $rev_date,
251 'last_translator' => "${translator} ${email}",
252 'language_team' => "${team} ${email}",
253 'language' => $lang,
254 'mime_version' => '1.0',
255 'content_type' => 'text/plain; charset='.$charset,
256 'content_transfer_encoding' => '8bit',
257 'plural_forms' => 'nplurals=2; plural=(n != 1);', }, };
258 2 };
259  
260 170 ▶my $_get_comment_lines = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
261 170 my ($self, $attr_name, $values, $prefix) = @_; my $lines = [];
262  
263 170 ▶ $attr_name eq 'flags' and return [ $prefix.SPC.(join ', ', @{ $values }) ];
Branch: 1 branch
BranchTrueFalseTotal
$attr_name eq "flags" and return [$prefix . ' ' . join(", ", @{$values;})] 70 100 170
264  
265 100 ▶ $values =~ m{ [\n] \z }msx and $values .= SPC;
Branch: 1 branch
BranchTrueFalseTotal
$values =~ / [\n] \z /msx and $values .= ' ' 2 98 100
266  
267 100 for my $line (map { $prefix.$_ } split m{ [\n] }msx, $values) {
268 304 $line =~ s{ \# \s+ \z }{\#}msx; push @{ $lines }, $line;
269 }
270  
271 100 return $lines;
272 2 };
273  
274 138 ▶my $_get_po_header_key = sub {
Subroutine __ANON__: called CC=2 SCAR=9.9
275 138 my ($self, $k) = @_; my $key_table = $self->schema->header_key_table;
276  
277 138 ▶ defined $key_table->{ $k } and return $key_table->{ $k };
Branch: 1 branch
BranchTrueFalseTotal
defined $key_table->{$k} and return $key_table->{$k} 138 0 138
278  
279 0 my $po_key = join q(-), map { ucfirst $_ } split m{ [_] }msx, $k;
280  
281 0 return [ 1 + keys %{ $key_table }, $po_key ];
282 2 };
283  
284 192 ▶my $_split_on_nl = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
285 192 my ($self, $attr_name, $value) = @_;
286  
287 192 ▶ $value ||= NUL; my $last_char = substr $value, -1; chomp $value;
Condition100%2/2
$value ||= ""
l!l
17814
MC/DC100%1/1
$value ||= ""
$value
Truth table100%2/2
A
A= $value
Aresult
11
00
288  
289 192 my @lines = split m{ [\n] }msx, $value; my $lines = [];
290  
291 192 ▶ if (@lines < 2) { push @{ $lines }, "${attr_name} ".$_quote->( $value ) }
Branch: 1 branch
BranchTrueFalseTotal
if (@lines < 2) { } 152 40 192
292 else {
293 40 push @{ $lines }, $attr_name.' ""';
294 40 push @{ $lines }, map { $_quote->( $_ ) } @lines;
295 }
296  
297 192 ▶ $last_char ne "\n" and $lines->[ -1 ] =~ s{ [\\][n][\"] \z }{\"}msx;
Branch: 1 branch
BranchTrueFalseTotal
$last_char ne "\n" and $lines->[-1] =~ s/ [\\][n][\"] \z /"/msx 62 130 192
298 192 return $lines;
299 2 };
300  
301 0 ▶my $_array_split_on_nl = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
302 0 my ($self, $attr, $values) = @_; my $index = 0; my $lines = [];
303  
304 0 for my $value (@{ $values }) {
305 0 push @{ $lines }, @{ $self->$_split_on_nl( "${attr}[${index}]", $value )};
306 0 $index++;
307 }
308  
309 0 return $lines;
310 2 };
311  
312 8 ▶my $_header_deflate = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
313 8 ▶ my ($self, $po_header) = @_; my $msgstr_ref = $po_header->{msgstr} || {};
Condition100%2/2
$po_header->{'msgstr'} || {}
l!l
53
MC/DC100%1/1
$po_header->{'msgstr'} || {}
$po_header->{'msgstr'}
Truth table100%2/2
A
A= $po_header->{'msgstr'}
Aresult
11
00
314  
315 8 ▶ my $header = { %{ $po_header || {} } }; my $msgstr;
Condition50%1/2
$po_header || {}
l!l
80
MC/DC0%0/1
$po_header || {}
$po_header
Truth table50%1/2
A
A= $po_header
Aresult
11
00
316  
317 8 for my $k (sort { $self->$_get_po_header_key( $a )->[ 0 ]
318 <=> $self->$_get_po_header_key( $b )->[ 0 ] }
319 8 keys %{ $msgstr_ref }) {
320 22 $msgstr .= $self->$_get_po_header_key( $k )->[ 1 ];
321  
322 # if ($k eq q(po_revision_date)) {
323 # $msgstr .= ': '.$_time2str->( "%Y-%m-%d %H:%M%z" )."\n";
324 # }
325 # else { $msgstr .= ': '.($msgstr_ref->{ $k } || NUL)."\n" }
326 22 ▶ $msgstr .= ': '.($msgstr_ref->{ $k } || NUL)."\n";
Condition50%1/2
$msgstr_ref->{$k} || ''
l!l
220
MC/DC0%0/1
$msgstr_ref->{$k} || ''
$msgstr_ref->{$k}
Truth table50%1/2
A
A= $msgstr_ref->{$k}
Aresult
11
00
327 }
328  
329 8 $header->{_order} = 0;
330 8 $header->{msgid } = NUL;
331 8 $header->{msgstr} = [ $msgstr ];
332 8 return $header;
333 2 };
334  
335 362 ▶my $_get_lines = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
336 362 my ($self, $attr_name, $values) = @_; my ($cpref, $lines);
337  
338 362 ▶ if ($cpref = $_comment_prefix->( $attr_name )) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cpref = &$_comment_prefix($attr_name)) { } 170 192 362
elsif (ref $values eq 'ARRAY') { } 94 98 192
339 170 $lines = $self->$_get_comment_lines( $attr_name, $values, $cpref );
340 }
341 elsif (ref $values eq 'ARRAY') {
342 94 ▶ if (@{ $values } > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$values;} > 1) { } 0 94 94
343 0 $lines = $self->$_array_split_on_nl( $attr_name, $values );
344 }
345 94 else { $lines = $self->$_split_on_nl( $attr_name, $values->[ 0 ] ) }
346 }
347 98 else { $lines = $self->$_split_on_nl( $attr_name, $values ) }
348  
349 362 return $lines;
350 2 };
351  
352 8 ▶my $_write_filter = sub {
Subroutine __ANON__: called CC=11 SCAR=24.3
353 8 ▶ my ($self, $data) = @_; my $buf ||= [];
Condition50%1/2
my $buf ||= []
l!l
08
MC/DC0%0/1
my $buf ||= []
my $buf
Truth table50%1/2
A
A= my $buf
Aresult
11
00
354  
355 8 ▶ my $po = $data->{po } || {};
Condition100%2/2
$data->{'po'} || {}
l!l
62
MC/DC100%1/1
$data->{'po'} || {}
$data->{'po'}
Truth table100%2/2
A
A= $data->{'po'}
Aresult
11
00
356 8 ▶ my $po_header = $data->{po_header} || $self->$_default_po_header;
Condition66%2/3
$data->{'po_header'} || $self->$_default_po_header
l!l&&r!l&&!r
530
MC/DC0%0/2
$data->{'po_header'} || $self->$_default_po_header
$data->{'po_header'} $self->$_default_po_header
Truth table66%2/3
A || B
A= $data->{'po_header'}B= $self->$_default_po_header
ABresult
1X1
011
000
357 8 my $charset = $self->$_get_charset( $po_header );
358 8 my $attrs = $self->schema->source->attributes;
359  
360 8 $po->{ NUL() } = $self->$_header_deflate( $po_header );
361  
362 8 for my $key (sort { $_original_order->( $po, $a, $b ) } keys %{ $po }) {
363 94 my $rec = $po->{ $key };
364  
365 $rec->{name} and not $rec->{msgid}
366 94 ▶ and $rec->{msgid} = delete $rec->{name};
Branch: 1 branch
BranchTrueFalseTotal
$rec->{"name"} and not $rec->{"msgid"} and $rec->{"msgid"} = delete $rec->{"name"} 0 94 94
Condition33%1/3
$rec->{"name"} and not $rec->{"msgid"}
!ll&&!rl&&r
9400
MC/DC0%0/2
$rec->{"name"} and not $rec->{"msgid"}
$rec->{"name"} not $rec->{"msgid"}
Truth table33%1/3
A and not(B)
A= $rec->{"name"}B= not $rec->{"msgid"}
ABresult
0X0
100
111
367  
368 94 for my $attr_name (grep { exists $rec->{ $_ } } @{ $attrs }) {
369 365 ▶ my $values = $rec->{ $attr_name }; defined $values or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $values or next 362 3 365
370  
371 362 ▶ ref $values eq 'ARRAY' and @{ $values } < 1 and next;
Branch: 1 branch
BranchTrueFalseTotal
ref $values eq "ARRAY" and @{$values;} < 1 and next 0 362 362
Condition66%2/3
ref $values eq "ARRAY" and @{$values;} < 1
!ll&&!rl&&r
1981640
MC/DC0%0/2
ref $values eq "ARRAY" and @{$values;} < 1
ref $values eq "ARRAY" @{$values;} < 1
Truth table66%2/3
A and B
A= ref $values eq "ARRAY"B= @{$values;} < 1
ABresult
0X0
100
111
372 362 push @{ $buf }, map { encode( $charset, $_ ) }
373 362 @{ $self->$_get_lines( $attr_name, $values ) };
374 }
375  
376 94 push @{ $buf }, NUL;
377 }
378  
379 8 pop @{ $buf };
380 8 return $buf;
381 2 };
382  
383 # Public methods
384 7 ▶sub read_from_file {
Subroutine read_from_file: called CC=1 SCAR=0.0
Pod documented
385 7 my ($self, $rdr) = @_;
386  
387 7 return $self->$_read_filter( [ $rdr->chomp->getlines ] );
388 };
389  
390 8 ▶sub write_to_file {
Subroutine write_to_file: called CC=1 SCAR=0.0
Pod documented
391 8 my ($self, $wtr, $data) = @_;
392  
393 8 $wtr->println( @{ $self->$_write_filter( $data ) } );
394 8 return $data;
395 }
396  
397 3 ▶sub decompose_key {
Subroutine decompose_key: called CC=2 SCAR=7.0
Pod documented
398 3 my ($self, $key) = @_; my $sep = CONTEXT_SEP;
399  
400 3 ▶ 0 >= index $key, $sep and return (NUL, $key);
Branch: 1 branch
BranchTrueFalseTotal
0 >= index($key, $sep) and return "", $key 0 3 3
401  
402 3 return split m{ $sep }msx, $key, 2;
403 }
404  
405 76 ▶sub make_key {
Subroutine make_key: called CC=2 SCAR=6.9
Pod documented
406 76 my ($self, $rec) = @_;
407  
408 return (exists $rec->{msgctxt}
409 76 ▶ ? $rec->{msgctxt}.CONTEXT_SEP : NUL).$rec->{msgid};
Branch: 1 branch
BranchTrueFalseTotal
exists $rec->{'msgctxt'} ? : 14 62 76
410 }
411  
412 2 1;
413  
414 __END__
« Gettext/Storage.pm ↑ Summary Gettext/Schema.pm »