lib/Text/PO/Element.pm

filter: Statementstmt 72.4% 200 / 276 Branchbran 54.4% 74 / 136 Conditioncond 32.6% 17 / 52 MC/DCmcdc 20.6% 6 / 29 Subroutinesub 80.0% 44 / 55 Podpod 100% 36 / 36 totaltotal 64.5% 377 / 584 CC 93 SCAR 31.0
CC
93
Cov
63%
dump
62.6
add_reference
56.0
reference
54.3
CRAP 22.2
« lib/Text/PO/MO.pm ↑ Summary lib/Text/PO/Gettext.pm »
1 ##----------------------------------------------------------------------------
2 ## PO Files Manipulation - ~/lib/Text/PO/Element.pm
3 ## Version v0.4.2
4 ## Copyright(c) 2025 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/07/23
7 ## Modified 2025/12/05
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package Text::PO::Element;
14 BEGIN
15 6 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.8
21 0 ▶ '==' => sub { _obj_eq(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 ▶ '!=' => sub { !_obj_eq(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 0 ▶ 'eq' => sub { _obj_eq(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 18 ▶ 'ne' => sub { !_obj_eq(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
25 6 fallback => 1,
26 6 );
27 6 ▶ use Text::Wrap ();
Subroutine BEGIN: called CC=1 SCAR=0.0
28 6 our $VERSION = 'v0.4.2';
29 6 ▶ use open ':std' => ':utf8';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 };
31  
32 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 6 $Text::Wrap::columns = 80;
36  
37 sub init
38 99 ▶{
Subroutine init: called CC=1 SCAR=0.0
Pod documented
39 99 my $self = shift( @_ );
40 99 $self->{msgid} = undef;
41 99 $self->{msgstr} = undef;
42 99 $self->{msgid_plural} = undef;
43 99 $self->{context} = undef;
44 99 $self->{fuzzy} = undef;
45 99 $self->{comment} = [];
46 99 $self->{auto_comment} = [];
47 # e.g.: c-format
48 99 $self->{flags} = [];
49 # Is it plural?
50 99 $self->{plural} = 0;
51 # reference
52 99 $self->{file} = undef;
53 99 $self->{line} = undef;
54 99 $self->{encoding} = undef;
55 # Parent po object
56 99 $self->{po} = undef;
57 # Whether this element is actually just an include directive
58 # If it is, the include file value is stored in the comment
59 99 $self->{is_include} = 0;
60 99 $self->{is_meta} = 0;
61 99 $self->{_po_line} = 0;
62 99 $self->{_init_strict_use_sub} = 1;
63 99 $self->SUPER::init( @_ );
64 99 return( $self );
65 }
66  
67 1 ▶sub add_auto_comment { return( shift->_add( 'auto_comment', @_ ) ); }
Subroutine add_auto_comment: called CC=1 SCAR=0.0
Pod documented
68  
69 5 ▶sub add_comment { return( shift->_add( 'comment', @_ ) ); }
Subroutine add_comment: called CC=1 SCAR=0.0
Pod documented
70  
71 12 ▶sub add_msgid { return( shift->_add( 'msgid', @_ ) ); }
Subroutine add_msgid: called CC=1 SCAR=0.0
Pod documented
72  
73 0 ▶sub add_msgid_plural { return( shift->_add( 'msgid_plural', @_ ) ); }
Subroutine add_msgid_plural: not called CC=1 SCAR=6.9
Pod documented
74  
75 63 ▶sub add_msgstr { return( shift->_add( 'msgstr', @_ ) ); }
Subroutine add_msgstr: called CC=1 SCAR=0.0
Pod documented
76  
77 sub add_reference
78 0 ▶{
Subroutine add_reference: not called CC=7 SCAR=40.3
Pod documented
79 0 my $self = shift( @_ );
80 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
81 {
82 ## If there is any existing value, convert it to array
83 0 ▶ $self->{file} = [$self->{file}] if( length( $self->{file} ) && $self->_is_array( $self->{file} ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"file"} and $self->_is_array($self->{"file"}) 0 0 0
Condition0%0/3
length $self->{"file"} and $self->_is_array($self->{"file"})
!ll&&!rl&&r
000
MC/DC0%0/2
length $self->{"file"} and $self->_is_array($self->{"file"})
length $self->{"file"} $self->_is_array($self->{"file"})
Truth table0%0/3
A and B
A= length $self->{"file"}B= $self->_is_array($self->{"file"})
ABresult
0X0
100
111
84 0 ▶ $self->{line} = [$self->{line}] if( length( $self->{line} ) && $self->_is_array( $self->{line} ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"line"} and $self->_is_array($self->{"line"}) 0 0 0
Condition0%0/3
length $self->{"line"} and $self->_is_array($self->{"line"})
!ll&&!rl&&r
000
MC/DC0%0/2
length $self->{"line"} and $self->_is_array($self->{"line"})
length $self->{"line"} $self->_is_array($self->{"line"})
Truth table0%0/3
A and B
A= length $self->{"line"}B= $self->_is_array($self->{"line"})
ABresult
0X0
100
111
85 0 ▶ if( $self->_is_array( $_[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($_[0])) { } 0 0 0
86 {
87 0 push( @{$self->{file}}, $_[0]->[0] );
88 0 push( @{$self->{line}}, $_[0]->[1] );
89 }
90 else
91 {
92 0 push( @{$self->{file}}, shift( @_ ) );
93 0 push( @{$self->{line}}, shift( @_ ) );
94 }
95 }
96 0 return( $self );
97 }
98  
99 0 ▶sub auto_comment { return( shift->_set_get_array( 'auto_comment', @_ ) ); }
Subroutine auto_comment: not called CC=1 SCAR=6.9
Pod documented
100  
101 8 ▶sub comment { return( shift->_set_get_array( 'comment', @_ ) ); }
Subroutine comment: called CC=1 SCAR=0.0
Pod documented
102  
103 19 ▶sub context { return( shift->_set_get_scalar( 'context', @_ ) ); }
Subroutine context: called CC=1 SCAR=0.0
Pod documented
104  
105 sub delete
106 0 ▶{
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
107 0 my $self = shift( @_ );
108 0 my $po = $self->po;
109 0 ▶ return( $self->error( "No Text::PO object set." ) ) if( !$po );
Branch: 1 branch
BranchTrueFalseTotal
unless $po 0 0 0
110 0 return( $po->remove_element( $self ) );
111 }
112  
113 sub dump
114 8 ▶{
Subroutine dump: called CC=16 SCAR=41.4
Pod documented
115 8 my $self = shift( @_ );
116 8 my @res = ();
117 8 ▶ if( $self->is_include )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_include) { } 0 8 8
118 {
119 0 ▶ push( @res, '# ' . join( "\n# ", @{$self->{comment}} ) ) if( scalar( @{$self->{comment}} ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$self->{"comment"};} 0 0 0
120 0 ▶ push( @res, '#. $include "' . $self->{file} . '"' ) if( length( $self->{file} // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
if length($self->{"file"} // "") 0 0 0
Condition0%0/2
$self->{"file"} // ""
l!l
00
MC/DC0%0/1
$self->{"file"} // ""
$self->{"file"}
Truth table0%0/2
A
A= $self->{"file"}
Aresult
11
00
121 }
122 else
123 {
124 0 ▶ push( @res, '# ' . join( "\n# ", @{$self->{comment}} ) ) if( scalar( @{$self->{comment}} ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$self->{"comment"};} 0 8 8
125 0 ▶ push( @res, '#. ' . join( "\n#. ", @{$self->{auto_comment}} ) ) if( scalar( @{$self->{auto_comment}} ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$self->{"auto_comment"};} 0 8 8
126 8 my $ref = $self->reference;
127 8 ▶ push( @res, "#: $ref" ) if( length( $ref ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $ref 3 5 8
128 8 my $flags = $self->flags;
129 8 ▶ if( scalar( @$flags ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$flags) 0 8 8
130 {
131 0 push( @res, sprintf( '#, %s', join( ", ", @$flags ) ) );
132 }
133 8 ▶ push( @res, sprintf( 'msgctxt "%s"', $self->po->quote( $self->{context} ) ) ) if( length( $self->{context} ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"context"} 0 8 8
134 8 foreach my $k ( qw( msgid msgid_plural ) )
135 {
136 16 ▶ if( $self->can( "${k}_as_string" ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("${k}_as_string")) { } 16 0 16
137 {
138 16 my $sub = "${k}_as_string";
139 16 push( @res, $self->$sub() );
140 }
141 else
142 {
143 0 ▶ if( ref( $self->{ $k } ) && scalar( @{$self->{ $k }} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->{$k} and scalar @{$self->{$k};}) { } 0 0 0
elsif (not ref $self->{$k} and length $self->{$k}) { } 0 0 0
Condition0%0/2
ref $self->{$k} and scalar @{$self->{$k};}
!ll
00
MC/DC0%0/1
ref $self->{$k} and scalar @{$self->{$k};}
ref $self->{$k}
Truth table0%0/2
A
A= ref $self->{$k}
Aresult
00
11
144 {
145 0 push( @res, sprintf( '%s ""', $k ) );
146 0 push( @res, map( sprintf( '"%s"', $self->po->quote( $_ ) ), @{$self->{ $k }} ) );
147 }
148 ▶ elsif( !ref( $self->{ $k } ) && length( $self->{ $k } ) )
Condition0%0/3
not ref $self->{$k} and length $self->{$k}
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $self->{$k} and length $self->{$k}
not ref $self->{$k} length $self->{$k}
Truth table0%0/3
not(A) and B
A= not ref $self->{$k}B= length $self->{$k}
ABresult
0X0
100
111
149 {
150 0 push( @res, sprintf( '%s "%s"', $k, $self->po->quote( $self->{ $k } ) ) );
151 }
152 }
153 }
154 8 push( @res, $self->msgstr_as_string );
155 }
156 8 return( join( "\n", @res ) );
157 }
158  
159 28 ▶sub encoding { return( shift->_set_get_scalar( 'encoding', @_ ) ); }
Subroutine encoding: called CC=1 SCAR=0.0
Pod documented
160  
161 1 ▶sub file { return( shift->_set_get_scalar( 'file', @_ ) ); }
Subroutine file: called CC=1 SCAR=0.0
Pod documented
162  
163 16 ▶sub flags { return( shift->_set_get_array( 'flags', @_ ) ); }
Subroutine flags: called CC=1 SCAR=0.0
Pod documented
164  
165 0 ▶sub fuzzy { return( shift->_set_get_boolean( 'fuzzy', @_ ) ); }
Subroutine fuzzy: not called CC=1 SCAR=6.9
Pod documented
166  
167 sub id
168 107 ▶{
Subroutine id: called CC=2 SCAR=6.9
Pod documented
169 107 my $self = shift( @_ );
170 107 my $msgid = $self->msgid;
171 107 ▶ if( ref( $msgid ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $msgid) { } 6 101 107
172 {
173 6 return( CORE::join( '', @$msgid ) );
174 }
175 else
176 {
177 101 return( $msgid );
178 }
179 }
180  
181 80 ▶sub is_include { return( shift->_set_get_boolean( 'is_include', @_ ) ); }
Subroutine is_include: called CC=1 SCAR=0.0
Pod documented
182  
183 60 ▶sub is_meta { return( shift->_set_get_boolean( 'is_meta', @_ ) ); }
Subroutine is_meta: called CC=1 SCAR=0.0
Pod documented
184  
185 0 ▶sub line { return( shift->_set_get_number( 'line', @_ ) ); }
Subroutine line: not called CC=1 SCAR=6.9
Pod documented
186  
187 sub merge
188 0 ▶{
Subroutine merge: not called CC=6 SCAR=37.4
Pod documented
189 0 my $self = shift( @_ );
190 0 ▶ my $elem = shift( @_ ) || return( $self->error( "No element object was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No element object was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No element object was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
191 0 ▶ return( $self->error( "Object provided ($elem) is not an Text::PO::Element object" ) ) if( !$self->_is_object( $elem ) || !$elem->isa( 'Text::PO::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($elem) and $elem->isa("Text::PO::Element") 0 0 0
Condition0%0/3
$self->_is_object($elem) and $elem->isa("Text::PO::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($elem) and $elem->isa("Text::PO::Element")
$self->_is_object($elem) $elem->isa("Text::PO::Element")
Truth table0%0/3
A and B
A= $self->_is_object($elem)B= $elem->isa("Text::PO::Element")
ABresult
0X0
100
111
192 0 my @k = grep( !/^po$/, keys( %$elem ) );
193 0 foreach( @k )
194 {
195 0 ▶ $self->{ $_ } = $elem->{ $_ } if( !length( $self->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{$_} 0 0 0
196 }
197 0 return( $self );
198 }
199  
200 196 ▶sub msgid { return( shift->_set_get( 'msgid', @_ ) ); }
Subroutine msgid: called CC=1 SCAR=0.0
Pod documented
201  
202 sub msgid_as_string
203 8 ▶{
Subroutine msgid_as_string: called CC=1 SCAR=0.0
Pod documented
204 8 my $self = shift( @_ );
205 8 return( $self->normalise( 'msgid', $self->{msgid} ) );
206 }
207  
208 sub msgid_as_text
209 135 ▶{
Subroutine msgid_as_text: called CC=2 SCAR=6.9
Pod documented
210 135 my $self = shift( @_ );
211 135 ▶ my $msgid = $self->_is_array( $self->{msgid} ) ? join( '', @{$self->{msgid}} ) : $self->{msgid};
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($self->{'msgid'}) ? : 18 117 135
212 135 return( $msgid );
213 }
214  
215 8 ▶sub msgid_plural { return( shift->_set_get( 'msgid_plural', @_ ) ); }
Subroutine msgid_plural: called CC=1 SCAR=0.0
Pod documented
216  
217 sub msgid_plural_as_string
218 16 ▶{
Subroutine msgid_plural_as_string: called CC=2 SCAR=6.9
Pod documented
219 16 my $self = shift( @_ );
220 # Important to return undef and not an empty string if there is no plural msgid
221 # undef will not be added to the list, but empty string would
222 16 ▶ return if( !CORE::length( $self->{msgid_plural} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"msgid_plural"} 14 2 16
223 2 return( $self->normalise( 'msgid_plural', $self->{msgid_plural} ) );
224 }
225  
226 sub msgid_plural_as_text
227 16 ▶{
Subroutine msgid_plural_as_text: called CC=2 SCAR=7.6
Pod documented
228 16 my $self = shift( @_ );
229 # Important to return undef and not an empty string if there is no plural msgid
230 # undef will not be added to the list, but empty string would
231 0 ▶ my $msgid = $self->_is_array( $self->{msgid_plural} ) ? join( '', @{$self->{msgid_plural}} ) : $self->{msgid_plural};
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($self->{'msgid_plural'}) ? : 0 16 16
232 16 return( $msgid );
233 }
234  
235 sub msgstr
236 167 ▶{
Subroutine msgstr: called CC=8 SCAR=20.9
Pod documented
237 167 my $self = shift( @_ );
238 167 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 89 78 167
239 {
240 89 ▶ if( @_ == 2 )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) { } 13 76 89
241 {
242 13 my( $pos, $str ) = @_;
243 13 ▶ return( $self->error( "msgstr plural offset \"$pos\" is not an integer." ) ) if( $pos !~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $pos =~ /^\d+$/ 0 13 13
244 13 $pos = int( $pos );
245 13 ▶ $self->{msgstr} = [] if( ref( $self->{msgstr} ) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"msgstr"} ne "ARRAY" 6 7 13
246 13 ▶ $self->{msgstr}->[ $pos ] = [] if( ref( $self->{msgstr}->[ $pos ] ) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"msgstr"}[$pos] ne "ARRAY" 13 0 13
247 13 push( @{$self->{msgstr}->[ $pos ]}, $str );
248 }
249 else
250 {
251 76 ▶ if( !ref( $_[0] ) && defined( $_[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_[0] and defined $_[0]) 73 3 76
Condition66%2/3
not ref $_[0] and defined $_[0]
!ll&&!rl&&r
3073
MC/DC50%1/2
not ref $_[0] and defined $_[0]
not ref $_[0] defined $_[0]
Truth table66%2/3
not(A) and B
A= not ref $_[0]B= defined $_[0]
ABresult
0X0
100
111
252 {
253 73 chomp( @_ );
254 }
255 76 $self->{msgstr} = shift( @_ );
256 }
257 }
258 167 return( $self->{msgstr} );
259 }
260  
261 sub msgstr_as_string
262 8 ▶{
Subroutine msgstr_as_string: called CC=5 SCAR=16.5
Pod documented
263 8 my $self = shift( @_ );
264 8 my @res = ();
265 8 ▶ if( $self->plural )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->plural) { } 1 7 8
266 {
267 1 ▶ for( my $i = 0; $i < scalar( @{$self->{msgstr}} ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"msgstr"};}) 2 1 3
268 {
269 2 my $ref = $self->{msgstr}->[$i];
270 # Is this a multiline plural localised text?
271 # msgstr[0] ""
272 # "some long line text"
273 # "2nd line of localised text"
274 2 ▶ if( scalar( @$ref ) > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$ref > 1) { } 0 2 2
275 {
276 0 push( @res, sprintf( 'msgstr[%d] ""', $i ) );
277 0 push( @res, map( sprintf( '"%s"', $self->po->quote( $_ ) ), @$ref ) );
278 }
279 # Regular plural localised text msgstr[0] "some text"
280 else
281 {
282 2 ▶ push( @res, sprintf( 'msgstr[%d] "%s"', $i, $self->po->quote( $ref->[0] ) ) ) if( length( $ref->[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $ref->[0] 2 0 2
283 }
284 }
285 1 return( join( "\n", @res ) );
286 }
287 else
288 {
289 7 return( $self->normalise( 'msgstr', $self->{msgstr} ) );
290 }
291 }
292  
293 sub msgstr_as_text
294 17 ▶{
Subroutine msgstr_as_text: called CC=2 SCAR=6.9
Pod documented
295 17 my $self = shift( @_ );
296 17 ▶ my $msgstr = $self->_is_array( $self->{msgstr} ) ? join( '', @{$self->{msgstr}} ) : $self->{msgstr};
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($self->{'msgstr'}) ? : 4 13 17
297 17 return( $msgstr );
298 }
299  
300 sub normalise
301 17 ▶{
Subroutine normalise: called CC=8 SCAR=21.2
Pod documented
302 17 my $self = shift( @_ );
303 17 my $type = shift( @_ );
304 17 my $text = shift( @_ );
305 17 my @res = ();
306 17 my $lines;
307 17 ▶ if( ref( $text ) && scalar( @$text ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $text and scalar @$text) { } 2 15 17
elsif (not ref $text and length $text) { } 15 0 15
Condition100%2/2
ref $text and scalar @$text
!ll
152
MC/DC100%1/1
ref $text and scalar @$text
ref $text
Truth table100%2/2
A
A= ref $text
Aresult
00
11
308 {
309 2 $lines = $self->wrap( join( '', @$text ) );
310 }
311 ▶ elsif( !ref( $text ) && length( $text ) )
Condition33%1/3
not ref $text and length $text
!ll&&!rl&&r
0015
MC/DC0%0/2
not ref $text and length $text
not ref $text length $text
Truth table33%1/3
not(A) and B
A= not ref $textB= length $text
ABresult
0X0
100
111
312 {
313 15 $lines = $self->wrap( $text );
314 }
315
316 17 ▶ if( defined( $lines ) && scalar( @$lines ) > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lines and scalar @$lines > 1) { } 2 15 17
Condition66%2/3
defined $lines and scalar @$lines > 1
!ll&&!rl&&r
0152
MC/DC50%1/2
defined $lines and scalar @$lines > 1
defined $lines scalar @$lines > 1
Truth table66%2/3
A and B
A= defined $linesB= scalar @$lines > 1
ABresult
0X0
100
111
317 {
318 2 push( @res, sprintf( '%s ""', $type ) );
319 2 push( @res, map( sprintf( '"%s"', $_ ), @$lines ) );
320 }
321 else
322 {
323 15 ▶ push( @res, sprintf( '%s "%s"', $type, ( defined( $lines ) ? $lines->[0] : '' ) ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $lines ? : 15 0 15
324 }
325 17 return( join( "\n", @res ) );
326 }
327  
328 50 ▶sub plural { return( shift->_set_get_boolean( 'plural', @_ ) ); }
Subroutine plural: called CC=1 SCAR=0.0
Pod documented
329  
330 140 ▶sub po { return( shift->_set_get_object( 'po', 'Text::PO', @_ ) ); }#
Subroutine po: called CC=1 SCAR=0.0
Pod documented
331  
332 sub reference
333 31 ▶{
Subroutine reference: called CC=13 SCAR=39.9
Pod documented
334 31 my $self = shift( @_ );
335 31 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 15 16 31
336 {
337 15 ▶ if( $self->_is_array( $_[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($_[0])) { } 0 15 15
338 {
339 # Multi references:
340 # colorscheme.cpp:79 skycomponents/equator.cpp:31
341 0 ▶ if( $self->_is_array( $_[0]->[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($_[0][0])) { } 0 0 0
342 {
343 0 $self->{file} = [];
344 0 $self->{line} = [];
345 0 foreach my $a ( @{$_[0]} )
346 {
347 0 push( @{$self->{file}}, $a->[0] );
348 0 push( @{$self->{line}}, $a->[1] );
349 }
350 }
351 else
352 {
353 0 @$self{ qw( file line ) } = @{$_[0]};
354 }
355 }
356 else
357 {
358 15 @$self{ qw( file line ) } = split( /:/, shift( @_ ), 2 );
359 }
360 }
361 31 ▶ return( '' ) if( !length( $self->{file} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"file"} 10 21 31
362 0 ▶ return( '' ) if( $self->_is_array( $self->{file} ) && !scalar( @{$self->{file}} ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_array($self->{"file"}) and not scalar @{$self->{"file"};} 0 21 21
Condition33%1/3
$self->_is_array($self->{"file"}) and not scalar @{$self->{"file"};}
!ll&&!rl&&r
2100
MC/DC0%0/2
$self->_is_array($self->{"file"}) and not scalar @{$self->{"file"};}
$self->_is_array($self->{"file"}) not scalar @{$self->{"file"};}
Truth table33%1/3
A and not(B)
A= $self->_is_array($self->{"file"})B= not scalar @{$self->{"file"};}
ABresult
0X0
100
111
363 21 ▶ if( $self->_is_array( $self->{file} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($self->{'file'})) { } 0 21 21
364 {
365 0 my @temp = ();
366 0 ▶ for( my $i = 0; $i < scalar( @{$self->{file}} ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"file"};}) 0 0 0
367 {
368 0 ▶ push( @temp, join( ':', $self->{file}->[$i], ( $self->_is_array( $self->{line} ) ? ( $self->{line}->[$i] // '' ) : '' ) ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($self->{'line'}) ? : 0 0 0
Condition0%0/2
$self->{"line"}[$i] // ""
l!l
00
MC/DC0%0/1
$self->{"line"}[$i] // ""
$self->{"line"}[$i]
Truth table0%0/2
A
A= $self->{"line"}[$i]
Aresult
11
00
369 }
370 0 return( join( ' ', @temp ) );
371 }
372 else
373 {
374 21 ▶ return( join( ':', $self->{file}, ( $self->{line} // '' ) ) );
Condition100%2/2
$self->{"line"} // ""
l!l
192
MC/DC100%1/1
$self->{"line"} // ""
$self->{"line"}
Truth table100%2/2
A
A= $self->{"line"}
Aresult
11
00
375 }
376 }
377  
378 sub wrap
379 17 ▶{
Subroutine wrap: called CC=4 SCAR=13.9
Pod documented
380 17 my $self = shift( @_ );
381 17 my $text = shift( @_ );
382 17 my $max = 80;
383 17 ▶ if( length( $text ) > $max )
Branch: 1 branch
BranchTrueFalseTotal
if (length $text > $max) { } 2 15 17
384 {
385 2 my $lines = [split( /\n/, $text )];
386 2 ▶ for( my $i = 0; $i < scalar( @$lines ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$lines) 2 2 4
387 {
388 2 ▶ if( length( $lines->[$i] ) > $max )
Branch: 1 branch
BranchTrueFalseTotal
if (length $lines->[$i] > $max) { } 2 0 2
389 {
390 2 my $newLines = $self->wrap_line( $lines->[$i] );
391 2 splice( @$lines, $i, 1, @$newLines );
392 2 $i += scalar( @$newLines ) - 1;
393 }
394 else
395 {
396 0 $lines->[$i] = $self->po->quote( $lines->[$i] . "\n" );
397 }
398 }
399 2 return( $lines );
400 }
401 else
402 {
403 15 return( [ $self->po->quote( $text ) ] );
404 }
405 }
406  
407 sub wrap_line
408 2 ▶{
Subroutine wrap_line: called CC=4 SCAR=13.9
Pod documented
409 2 my $self = shift( @_ );
410 2 my $text = shift( @_ );
411 2 ▶ return( [] ) if( !length( $text ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $text 0 2 2
412 2 my $new = Text::Wrap::wrap( '', '', $text );
413 2 my $newLines = [split( /\n/, $new )];
414 2 ▶ for( my $j = 0; $j < scalar( @$newLines ); $j++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @$newLines) 4 2 6
415 {
416 4 ▶ $newLines->[$j] .= ' ' unless( $j == $#${newLines} );
Branch: 1 branch
BranchTrueFalseTotal
unless $j == $newLines->$#* 2 2 4
417 4 $newLines->[$j] = $self->po->quote( $newLines->[$j] );
418 }
419 #$newLines->[ $#${newLines} ] = $self->po->quote( $newLines->[ $#${newLines} ] );
420 2 return( $newLines );
421 }
422  
423 sub _add
424 81 ▶{
Subroutine _add: called CC=2 SCAR=6.9
425 81 my $self = shift( @_ );
426 81 my $what = shift( @_ );
427 #chomp( @_ );
428 81 ▶ $self->{ $what } = [] if( !ref( $self->{ $what } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{$what} 24 57 81
429 81 push( @{$self->{ $what }}, @_ );
430 81 return( $self );
431 }
432  
433 sub _obj_eq
434 18 ▶{
Subroutine _obj_eq: called CC=16 SCAR=33.8
435 6 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
436 18 my $self = shift( @_ );
437 18 my $other = shift( @_ );
438 18 ▶ my $msgid = $self->_is_array( $self->{msgid} ) ? join( '', @{$self->{msgid}} ) : $self->{msgid};
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($self->{'msgid'}) ? : 2 16 18
439 18 ▶ if( $self->_is_a( $other => 'Text::PO::Element' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($other, 'Text::PO::Element')) { } 18 0 18
elsif (not defined $other) { } 0 0 0
440 {
441 18 ▶ my $msgstr = $self->_is_array( $self->{msgstr} ) ? join( '', @{$self->{msgstr}} ) : $self->{msgstr};
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($self->{'msgstr'}) ? : 4 14 18
442 18 ▶ my $other_msgid = $self->_is_array( $other->{msgid} ) ? join( '', @{$other->{msgid}} ) : $other->{msgid};
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($other->{'msgid'}) ? : 3 15 18
443 18 ▶ my $other_msgstr = $self->_is_array( $other->{msgstr} ) ? join( '', @{$other->{msgstr}} ) : $other->{msgstr};
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($other->{'msgstr'}) ? : 2 16 18
444 18 ▶ return( ( ( $msgid // '' ) eq ( $other_msgid // '' ) && ( $msgstr // '' ) eq ( $other_msgstr // '' ) ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
($msgid // '') eq ($other_msgid // '') && ($msgstr // '') eq ($other_msgstr // '') ? : 0 18 18
Condition45%5/11
($msgid // "") eq ($other_msgid // "") and ($msgstr // "") eq ($other_msgstr // "")
!ll&&!rl&&r
1800
$msgid // ""
l!l
171
$other_msgid // ""
l!l
711
$msgstr // ""
l!l
00
$other_msgstr // ""
l!l
00
MC/DC0%0/2
($msgid // "") eq ($other_msgid // "") and ($msgstr // "") eq ($other_msgstr // "")
$msgid $msgstr
MC/DC100%1/1
$other_msgid // ""
$other_msgid
MC/DC0%0/1
$other_msgstr // ""
$other_msgstr
Truth table33%1/3
A and B
A= $msgidB= $msgstr
ABresult
0X0
100
111
Truth table100%2/2
A
A= $other_msgid
Aresult
11
00
Truth table0%0/2
A
A= $other_msgstr
Aresult
11
00
445 }
446 # Comparing an undefined value would trigger a Perl warning
447 elsif( !defined( $other ) )
448 {
449 0 ▶ return( !defined( $msgid ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
!defined($msgid) ? : 0 0 0
450 }
451 else
452 {
453 0 ▶ return( ( $msgid // '' ) eq $other ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
($msgid // '') eq $other ? : 0 0 0
Condition0%0/2
$msgid // ""
l!l
00
MC/DC0%0/1
$msgid // ""
$msgid
Truth table0%0/2
A
A= $msgid
Aresult
11
00
454 }
455 }
456  
457 sub _set_get
458 204 ▶{
Subroutine _set_get: called CC=5 SCAR=16.1
459 204 my $self = shift( @_ );
460 204 my $name = shift( @_ );
461 204 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 85 119 204
462 {
463 85 ▶ if( !ref( $_[0] ) && length( $_[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_[0] and length $_[0]) 63 22 85
Condition66%2/3
not ref $_[0] and length $_[0]
!ll&&!rl&&r
02263
MC/DC50%1/2
not ref $_[0] and length $_[0]
not ref $_[0] length $_[0]
Truth table66%2/3
not(A) and B
A= not ref $_[0]B= length $_[0]
ABresult
0X0
100
111
464 {
465 63 chomp( @_ );
466 }
467 85 ▶ $self->plural(1) if( $name eq 'msgid_plural' );
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "msgid_plural" 6 79 85
468 85 return( $self->SUPER::_set_get( $name, @_ ) );
469 }
470 119 return( $self->SUPER::_set_get( $name ) );
471 }
472  
473 sub _set_get_msg_property
474 0 ▶{
Subroutine _set_get_msg_property: not called CC=5 SCAR=34.0
475 0 my $self = shift( @_ );
476 0 my $prop = shift( @_ );
477 0 ▶ $self->_set_get( $prop, @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
478 0 ▶ if( ref( $self->{ $prop } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$prop}) { } 0 0 0
479 {
480 0 ▶ return( wantarray() ? ( @{$self->{ $prop }} ) : join( '', @{$self->{ $prop }} ) );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
481 }
482 else
483 {
484 0 ▶ return( wantarray() ? ( $self->{ $prop } ) : $self->{ $prop } );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
485 }
486 }
487  
488 6 1;
489 # NOTE: POD
490 __END__
« lib/Text/PO/MO.pm ↑ Summary lib/Text/PO/Gettext.pm »