blib/lib/File/OM.pm

filter: Statementstmt 92.5% 524 / 566 Branchbran 66.3% 240 / 362 Conditioncond 65.5% 99 / 151 MC/DCmcdc 42.5% 37 / 87 Subroutinesub 94.1% 64 / 68 Podpod 0.0% 0 / 6 totaltotal 77.7% 964 / 1240 CC 246 SCAR 25.8
CC
246
Cov
80%
anvl_rec
132.0
elem
20.6
elem
19.3
CRAP 13.2
« blib/lib/File/ANVL.pm ↑ Summary blib/lib/File/ERC.pm »
1 # xxx need 'raw' format, like plain but no wrap for resolve mode
2 # xxx or need 'granvl' format, like anvl but no wrap for resolve mode?
3 # xxx need 'null' format, to do ...?
4  
5 package File::OM;
6  
7 61 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 61 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 61 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 61 our $VERSION;
12 61 $VERSION = sprintf "%d.%02d", q$Name: Release-1-05 $ =~ /Release-(\d+)-(\d+)/;
13  
14 61 require Exporter;
15 61 our @ISA = qw(Exporter);
16  
17 61 our @EXPORT = qw();
18  
19 61 our @EXPORT_OK = qw();
20  
21 61 our %EXPORT_TAGS = (all => [ @EXPORT_OK ]);
22  
23 61 ▶use Text::Wrap; # which recommends localizing next two settings
Subroutine BEGIN: called CC=1 SCAR=0.0
24 # local $Text::Wrap::columns = $self->{wrap};
25 # local $Text::Wrap::huge = 'overflow';
26  
27 61 our %outputformats = (
28 anvl => 'ANVL',
29 csv => 'CSV',
30 json => 'JSON',
31 plain => 'Plain',
32 psv => 'PSV',
33 turtle => 'Turtle',
34 xml => 'XML',
35 );
36  
37 1 ▶sub listformats {
Subroutine listformats: called CC=1 SCAR=0.0
Pod undocumented
38 1 return map $outputformats{$_}, sort keys %outputformats;
39 }
40  
41 81 ▶sub om_opt_defaults { return {
Subroutine om_opt_defaults: called CC=1 SCAR=0.0
Pod undocumented
42  
43 81 anvl_mode => # which flavor, eg, ANVL, ANVLR, ANVLS
44 'ANVL', # vanilla (unused for now)
45 elemsref => [], # one array to store record elements
46 indent_start => '', # overall starting indent
47 indent_step => # how much to increment/decrement indent
48 ' ', # for XML, JSON
49 outhandle => '', # return string by default
50 turtle_indent => # turtle has one indent width
51 ' ',
52 turtle_predns => # turtle predicate namespaces
53 'http://purl.org/kernel/elements/1.1/',
54 turtle_nosubject => # a default subject
55 'default', # XXX not a URI -- what should this be?
56 turtle_subjelpat => # pattern for matching a subject element
57 '',
58 turtle_stream_prefix => # symbol we use for turtle
59 'erc',
60 xml_stream_name => # for XML output, stream tag
61 'recs',
62 xml_record_name => # for XML output, record tag
63 'rec',
64 wrap => 72, # at which column to wrap elements (0=nowrap)
65 wrap_indent => '', # current indent for wrap, but "\t" for ANVL
66 # xxx is this even used?
67 verbose => 0, # more output (default less)
68  
69 # The following keys are maintained internally.
70 #
71 elemnum => 0, # current element number
72 indent => '', # current ident
73 recnum => 0, # current record number
74 record_is_open => 0, # whether a record is open
75 stream_is_open => 0, # whether a stream is open
76 };
77 }
78  
79 81 ▶sub new {
Subroutine new: called CC=7 SCAR=19.5
Pod undocumented
80 81 ▶ my $class = shift || ''; # XXX undefined depending on how called
Condition50%1/2
shift() || ''
l!l
810
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
81 81 my $self = om_opt_defaults();
82 81 ▶ my $format = lc (shift || '');
Condition100%2/2
shift() || ''
l!l
774
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
83 81 ▶ if ($format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format) { } 77 4 81
84 77 $format = $outputformats{$format}; # canonical name
85 77 ▶ $format or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$format or return undef 76 1 77
86 76 $class = "File::OM::$format";
87 }
88 else { # if no format given, expect
89 4 ▶ $class =~ /^File::OM::\S/ # to be called from subclass
Branch: 1 branch
BranchTrueFalseTotal
$class =~ /^File::OM::\S/ or return undef 4 0 4
90 or return undef;
91 }
92 80 bless $self, $class;
93  
94 80 my $options = shift;
95 80 my ($key, $value);
96 80 ▶ $self->{$key} = $value
Branch: 1 branch
BranchTrueFalseTotal
() = each %$options and do { $self->{$key} = $value } 169 80 249
97 while ($key, $value) = each %$options;
98  
99 80 return $self;
100 }
101  
102 # xxxx should refactor subclass methodes to more generic SUPER methods
103 # there's lots of repeated code
104  
105 85 ▶sub DESTROY {
Subroutine DESTROY: called CC=5 SCAR=16.1
106 85 my $self = shift;
107 85 my ($s, $z) = ('', ''); # built string and catchup string
108 $self->{stream_is_open} and # wrap up any loose ends
109 85 ▶ $z = $self->cstream(); # which calls crec()
Branch: 1 branch
BranchTrueFalseTotal
$self->{"stream_is_open"} and $z = $self->cstream 24 61 85
110 85 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 57 28 85
111 $self->{outhandle} and
112 85 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 28 28
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
2857
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
113 or
114 return $s;
115 }
116  
117 17 ▶sub elems {
Subroutine elems: called CC=3 SCAR=11.0
Pod undocumented
118 # XXX why do 4 bytes (instead of 2) show up in wget??
119 # # %-encode any chars that need it
120 # my $except_re = qr/([\001-\037\177-\377])/; XXX needed any more?
121 # $s =~ s/$except_re/ "%" . join("", unpack("H2", $1)) /ge;
122  
123 17 my $self = shift;
124 17 my $sequence = '';
125 17 my ($name, $value);
126 17 while (1) {
127 44 ($name, $value) = (shift, shift); # next arg pair
128 44 ▶ last unless $name or $value; # done if null
Branch: 1 branch
BranchTrueFalseTotal
unless $name or $value 17 27 44
Condition66%2/3
$name or $value
l!l&&r!l&&!r
27017
MC/DC50%1/2
$name or $value
$name $value
Truth table66%2/3
A or B
A= $nameB= $value
ABresult
1X1
011
000
129 27 $sequence .= $self->elem($name, $value);
130 }
131 17 return $sequence;
132 }
133  
134 # Shared routine to construct a header ordering based on the record
135 # in the given element array. Used by CSV and PSV formats.
136 #
137 1 ▶sub rec2hdr { my( $r_elems ) = (shift);
Subroutine rec2hdr: called CC=4 SCAR=13.9
Pod undocumented
138  
139 1 my ($n, $nmax) = (0, scalar @$r_elems);
140 1 my $r_elem_order = [ ]; # create an array reference
141  
142 1 ▶ for ($n = 0; $n < $nmax; $n += 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < $nmax) 7 1 8
143  
144 7 ▶ $n > 0 and # normal element case
Branch: 1 branch
BranchTrueFalseTotal
$n > 0 and push(@$r_elem_order, $$r_elems[$n + 1]), next 6 1 7
145 push(@$r_elem_order, $$r_elems[$n + 1]),
146 next;
147  
148 # If we get here, $n == 0 (record start). If the record
149 # starts with a label-less value, use '_' as the name.
150 #
151 1 ▶ $$r_elems[$n + 2] and
Branch: 1 branch
BranchTrueFalseTotal
$$r_elems[$n + 2] and push @$r_elem_order, "_" 1 0 1
152 push(@$r_elem_order, '_'),
153 }
154 1 return $r_elem_order;
155 }
156  
157 # Called in place of TextWrap::Wrap::wrap, returns string without wrapping.
158 # Second arg is a dummy.
159 #
160 1 ▶sub text_nowrap { my( $line1ind, $line2ind, $val)=(shift, shift, shift);
Subroutine text_nowrap: called CC=1 SCAR=0.0
Pod undocumented
161 1 return $line1ind . $val;
162 }
163  
164 package File::OM::ANVL;
165  
166 61 our @ISA = ('File::OM');
167  
168 184 ▶sub elem { # OM::ANVL
Subroutine elem: called CC=13 SCAR=25.8
169 184 my $self = shift;
170 184 my ($name, $value, $lineno, $elemnum) = (shift, shift, shift, shift);
171 184 my ($s, $z) = ('', ''); # built string and catchup string
172  
173 $self->{record_is_open} or # call orec() to open record first
174 ($z = $self->orec(undef, $lineno), # may call ostream()
175 184 ▶ $self->{record_is_open} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"record_is_open"} or $z = $self->orec(undef, $lineno), $self->{"record_is_open"} = 1 177 7 184
176 184 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 155 29 184
177  
178 defined($elemnum) and
179 $self->{elemnum} = $elemnum
180 or
181 184 ▶ $self->{elemnum}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $elemnum and $self->{"elemnum"} = $elemnum or ++$self->{"elemnum"} 0 184 184
Condition33%1/3
defined $elemnum and $self->{"elemnum"} = $elemnum
!ll&&!rl&&r
18400
MC/DC0%0/2
defined $elemnum and $self->{"elemnum"} = $elemnum
defined $elemnum $self->{"elemnum"} = $elemnum
Truth table33%1/3
A and B
A= defined $elemnumB= $self->{"elemnum"} = $elemnum
ABresult
0X0
100
111
182  
183 # Parse $lineno, which is empty or has form LinenumType, where
184 # Type is either ':' (real element) or '#' (comment).
185 184 ▶ defined($lineno) or $lineno = '1:';
Branch: 1 branch
BranchTrueFalseTotal
defined $lineno or $lineno = "1:" 155 29 184
186 184 my ($num, $type) =
187 $lineno =~ /^(\d*)\s*(.)/;
188  
189 184 local ($Text::Wrap::columns, $Text::Wrap::huge, $Text::Wrap::unexapand);
190 184 my $wrapper;
191 $self->{wrap} and
192 ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge,
193 $Text::Wrap::unexpand) =
194 184 ▶ (\&Text::Wrap::wrap, $self->{wrap}, 'overflow', 0)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge, $Text::Wrap::unexpand) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow", 0) or $wrapper = \&File::OM::text_nowrap 182 2 184
Condition66%2/3
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge, $Text::Wrap::unexpand) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow", 0)
!ll&&!rl&&r
20182
MC/DC50%1/2
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge, $Text::Wrap::unexpand) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow", 0)
$self->{"wrap"} ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge, $Text::Wrap::unexpand) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow", 0)
Truth table66%2/3
A and B
A= $self->{"wrap"}B= ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge, $Text::Wrap::unexpand) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow", 0)
ABresult
0X0
100
111
195 or
196 $wrapper = \&File::OM::text_nowrap;
197 ;
198  
199 184 ▶ if ($type eq '#') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq '#') { } 2 182 184
elsif (defined $name) { } 156 26 182
200 2 $self->{element_name} = undef; # indicates comment
201 2 $self->{elemnum}--; # doesn't count as an element
202 #$s .= Text::Wrap::wrap( # wrap lines with '#' as
203 2 $s .= &$wrapper( # wrap lines with '#' as
204 '#', # first line "indent" and
205 '# ', # '# ' for all other indents
206 $self->comment_encode($value) # main part to wrap
207 );
208 2 $s .= "\n"; # close comment
209 }
210 # XXX what if ref($value) eq "ARRAY" -> can be used for repeated vals?
211 # XXX does undefined $name mean comment?
212 # XXX document what undef for $name means
213 elsif (defined $name) { # no element if no name
214 # XXX would it look cooler with :\t after the label??
215 # xxx this should be stacked
216 156 $self->{element_name} = $self->name_encode($name);
217 156 my $enc_val = $self->value_encode($value); # encoded value
218  
219 $s .= $enc_val =~ /^\s*$/ ? # wrap() loses label of
220 "$self->{element_name}:$enc_val" : # blank value
221 &$wrapper( # wrap lines; this 1st
222 $self->{element_name} # "indent" won't break
223 156 ▶ . ':', # label across lines
Branch: 1 branch
BranchTrueFalseTotal
$enc_val =~ /^\s*$/ ? : 7 149 156
224 "\t", # tab for other indents
225 $enc_val) # main part to wrap
226 ;
227 156 $s .= "\n";
228 # M_ELEMENT and C_ELEMENT would start here
229 }
230 $self->{outhandle} and
231 184 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 29 29
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
29155
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
232 or
233 return $s;
234 }
235  
236 # XXX need something that will spit out whole input ANVL record
237 0 ▶sub anvl_rec { # OM::ANVL
Subroutine anvl_rec: not called CC=11 SCAR=48.8
238 0 my $self = shift;
239 0 my $rec = shift;
240 # XXX ignore lineno for now
241 0 my ($name, $value, $lineno, $elemnum) = (shift, shift, shift, shift);
242 0 my ($s, $z) = ('', ''); # built string and catchup string
243  
244 $self->{record_is_open} or # call orec() to open record first
245 ($z = $self->orec(undef, $lineno), # may call ostream()
246 0 ▶ $self->{record_is_open} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"record_is_open"} or $z = $self->orec(undef, $lineno), $self->{"record_is_open"} = 1 0 0 0
247 0 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 0 0 0
248  
249 #defined($elemnum) and
250 # $self->{elemnum} = $elemnum
251 #or
252 # $self->{elemnum}++;
253  
254 # Parse $lineno, which is empty or has form LinenumType, where
255 # Type is either ':' (real element) or '#' (comment).
256 0 ▶ defined($lineno) or $lineno = '1:';
Branch: 1 branch
BranchTrueFalseTotal
defined $lineno or $lineno = "1:" 0 0 0
257 0 my ($num, $type) =
258 $lineno =~ /^(\d*)\s*(.)/;
259  
260 0 local ($Text::Wrap::columns, $Text::Wrap::huge);
261 0 my $wrapper;
262 $self->{wrap} and
263 ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) =
264 0 ▶ (\&Text::Wrap::wrap, $self->{wrap}, 'overflow')
Branch: 1 branch
BranchTrueFalseTotal
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow") or $wrapper = \&File::OM::text_nowrap 0 0 0
Condition0%0/3
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
$self->{"wrap"} ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
Truth table0%0/3
A and B
A= $self->{"wrap"}B= ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
ABresult
0X0
100
111
265 or
266 $wrapper = \&File::OM::text_nowrap;
267 ;
268  
269  
270 0 ▶ if ($type eq '#') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq '#') { } 0 0 0
elsif (defined $name) { } 0 0 0
271 0 $self->{element_name} = undef; # indicates comment
272 0 $self->{elemnum}--; # doesn't count as an element
273 #$s .= Text::Wrap::wrap( # wrap lines with '#' as
274 0 $s .= &$wrapper( # wrap lines with '#' as
275 '#', # first line "indent" and
276 '# ', # '# ' for all other indents
277 $self->comment_encode($value) # main part to wrap
278 );
279 0 $s .= "\n"; # close comment
280 }
281 # XXX what if ref($value) eq "ARRAY" -> can be used for repeated vals?
282 # XXX does undefined $name mean comment?
283 # XXX document what undef for $name means
284 elsif (defined $name) { # no element if no name
285 # XXX would it look cooler with :\t after the label??
286 # xxx this should be stacked
287 0 $self->{element_name} = $self->name_encode($name);
288 0 my $enc_val = $self->value_encode($value); # encoded value
289 $s .= $enc_val =~ /^\s*$/ ? # wrap() loses label of
290 "$self->{element_name}:$enc_val" : # blank value
291 &$wrapper( # wrap lines; this 1st
292 $self->{element_name} # "indent" won't break
293 0 ▶ . ':', # label across lines
Branch: 1 branch
BranchTrueFalseTotal
$enc_val =~ /^\s*$/ ? : 0 0 0
294 "\t", # tab for other indents
295 $enc_val) # main part to wrap
296 ;
297 0 $s .= "\n";
298 # M_ELEMENT and C_ELEMENT would start here
299 }
300 $self->{outhandle} and
301 0 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 0 0
Condition0%0/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
00
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table0%0/2
A
A= $self->{"outhandle"}
Aresult
00
11
302 or
303 return $s;
304 }
305  
306 63 ▶sub orec { # OM::ANVL
Subroutine orec: called CC=9 SCAR=22.0
307 63 my $self = shift;
308 63 my ($recnum, $lineno) = (shift, shift);
309 63 my ($s, $z) = ('', ''); # built string and catchup string
310  
311 63 $self->{elemnum} = 0;
312 $self->{stream_is_open} or # call ostream() to open stream first
313 ($z = $self->ostream(),
314 63 ▶ $self->{stream_is_open} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"stream_is_open"} or $z = $self->ostream, $self->{"stream_is_open"} = 1 56 7 63
315 63 $self->{record_is_open} = 1;
316 63 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 57 6 63
317  
318 defined($recnum) and
319 $self->{recnum} = $recnum
320 or
321 63 ▶ $self->{recnum}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $recnum and $self->{"recnum"} = $recnum or ++$self->{"recnum"} 56 7 63
Condition66%2/3
defined $recnum and $self->{"recnum"} = $recnum
!ll&&!rl&&r
7056
MC/DC50%1/2
defined $recnum and $self->{"recnum"} = $recnum
defined $recnum $self->{"recnum"} = $recnum
Truth table66%2/3
A and B
A= defined $recnumB= $self->{"recnum"} = $recnum
ABresult
0X0
100
111
322  
323 63 ▶ defined($lineno) or $lineno = '1:';
Branch: 1 branch
BranchTrueFalseTotal
defined $lineno or $lineno = "1:" 56 7 63
324 # xxxx really? will someone pass that in?
325  
326 $self->{verbose} and
327 63 ▶ $s .= "# from record $self->{recnum}, line $lineno\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"verbose"} and $s .= qq[# from record $self->{"recnum"}, line $lineno\n] 19 44 63
328 $self->{outhandle} and
329 63 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 6 6
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
657
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
330 or
331 return $s;
332 }
333  
334 63 ▶sub crec { # OM::ANVL
Subroutine crec: called CC=3 SCAR=11.0
335 63 my ($self, $recnum) = (shift, shift);
336 63 $self->{record_is_open} = 0;
337 63 my $s = "\n";
338 $self->{outhandle} and
339 63 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 6 6
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
657
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
340 or
341 return $s;
342 }
343  
344 # xxx anvl -m anvln? n=normalized?
345 28 ▶sub ostream { # OM::ANVL
Subroutine ostream: called CC=3 SCAR=11.0
346 28 my $self = shift;
347  
348 28 $self->{recnum} = 0;
349 28 $self->{stream_is_open} = 1;
350 28 my $s = '';
351 $self->{outhandle} and
352 28 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 6 6
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
622
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
353 or
354 return $s;
355 }
356  
357 28 ▶sub cstream { # OM::ANVL
Subroutine cstream: called CC=5 SCAR=16.1
358 28 my $self = shift;
359 28 my ($s, $z) = ('', ''); # built string and catchup string
360 $self->{record_is_open} and # wrap up any loose ends
361 28 ▶ $z = $self->crec();
Branch: 1 branch
BranchTrueFalseTotal
$self->{"record_is_open"} and $z = $self->crec 7 21 28
362 28 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 22 6 28
363 28 $self->{stream_is_open} = 0;
364 $self->{outhandle} and
365 28 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 6 6
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
622
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
366 or
367 return $s;
368 }
369  
370 156 ▶sub name_encode { # OM::ANVL
Subroutine name_encode: called CC=2 SCAR=6.9
371 156 my ($self, $s) = (shift, shift);
372 156 ▶ defined($s) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s or return "" 156 0 156
373 #$s =~ s/^\s+//;
374 #$s =~ s/\s+$//; # trim both ends
375 #$s =~ s/\s+/ /g; # squeeze multiple \s to one space
376 # xxx keep doubling %?
377 156 $s =~ s/%/%%/g; # to preserve literal %, double it
378 # xxx what about granvl?
379 # yyy must be decoded by receiver
380 #$s =~ s/:/%3a/g; # URL-encode all colons (%cn)
381  
382 156 $s =~ s{ # URL-encode all colons and whitespace
383 ([=:<\s]) # \s matches [ \t\n\f] etc.
384 }{ # = and < anticipate ANVL extensions
385 12 sprintf("%%%02x", ord($1)) # replacement hex code
386 }xeg;
387  
388 # This next line takes care of the mainstream case of names that
389 # contain spaces. It makes sure that for every run of one or more
390 # spaces, the first space won't be encoded.
391 #
392 156 $s =~ s/%20((?:%20)*)/ $1/g;
393 156 $s =~ s/^ /%20/; # but make sure any initial space is encoded
394 156 $s =~ s/ $/%20/; # and make sure any final space is encoded
395  
396 156 return $s;
397  
398 # XXXX must convert XML namespaces to make safe for ANVL
399 # foo:bar ->? bar.foo (sort friendly, and puts namespace into
400 # proper subordinate position similar to dictionaries)?
401 # or if not namespace, foo:bar ->? foo%xxbar
402 }
403  
404 # Encoding of names and values is done upon output in ANVL.
405 # Default is to wrap long lines.
406  
407 156 ▶sub value_encode { # OM::ANVL
Subroutine value_encode: called CC=5 SCAR=16.5
408 156 my ($self, $s, $anvl_mode) = (shift, shift, shift);
409 156 ▶ defined($s) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s or return "" 155 1 156
410 155 ▶ $anvl_mode ||= 'ANVL';
Condition50%1/2
$anvl_mode ||= "ANVL"
l!l
0155
MC/DC0%0/1
$anvl_mode ||= "ANVL"
$anvl_mode
Truth table50%1/2
A
A= $anvl_mode
Aresult
11
00
411  
412 155 my $value = $s; # save original value
413 #my ($initial_newlines) = # save initial newlines
414 # $s =~ /^(\n*)/; # always defined, often ""
415  
416 ## value after colon starts with either preserved newlines,
417 # a space, or, if value is "" (as opposed to 0), nothing
418 #
419 #my $value_start = $initial_newlines || ($value eq "" ? '' : ' ');
420 #my $value_start = $initial_newlines || ($value eq "" ? '' : ' ');
421 155 ▶ my $value_start = $value eq "" ? '' : ' ';
Branch: 1 branch
BranchTrueFalseTotal
$value eq '' ? : 6 149 155
422  
423 #my $value_start = $initial_newlines || ($value ? ' ' : '');
424 # xxxx is this the right place to enforce the space after ':'?
425  
426 # xxx is there a linear whitespace char class??
427 # problem is that \s includes \n
428 #$s =~ s/^\s+//;
429 #$s =~ s/\s+$//; # trim both ends
430  
431 155 $s =~ s/%/%%/g; # to preserve literal %, double it
432 # yyy must be decoded by receiver
433 155 $s =~ s{ # URL-encode newlines in portable way
434 (\n) # \n matches all platforms' ends of lines
435 }{ #
436 13 sprintf("%%%02x", ord($1)) # replacement hex code
437 }xeg;
438 155 ▶ if ($anvl_mode eq 'ANVLS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($anvl_mode eq "ANVLS") 0 155 155
439 0 $s =~ s/\|/%7c/g; # URL-encode all vertical bars (%vb)
440 0 $s =~ s/;/%3b/g; # URL-encode all semi-colons (%sc)
441 # XXX what about others, such as (:...) (=...)
442 };
443 155 return $value_start . $s;
444 }
445  
446 2 ▶sub comment_encode { # OM::ANVL
Subroutine comment_encode: called CC=2 SCAR=7.0
447 2 my ($self, $s) = (shift, shift);
448 2 ▶ defined($s) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s or return "" 2 0 2
449 2 $s =~ s/\n/\\n/g; # escape \n yyy??
450 2 return $s;
451 }
452  
453 package File::OM::CSV;
454  
455 61 our @ISA = ('File::OM');
456  
457 57 ▶sub elem { # OM::CSV
Subroutine elem: called CC=13 SCAR=29.6
458 57 my $self = shift;
459 57 my ($name, $value, $lineno, $elemnum) = (shift, shift, shift, shift);
460 57 my ($s, $z) = ('', ''); # built string and catchup string
461  
462 $self->{record_is_open} or # call orec() to open record first
463 ($z = $self->orec(undef, $lineno), # may call ostream()
464 57 ▶ $self->{record_is_open} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"record_is_open"} or $z = $self->orec(undef, $lineno), $self->{"record_is_open"} = 1 57 0 57
465 57 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 57 0 57
466  
467 defined($elemnum) and
468 $self->{elemnum} = $elemnum
469 or
470 57 ▶ $self->{elemnum}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $elemnum and $self->{"elemnum"} = $elemnum or ++$self->{"elemnum"} 0 57 57
Condition33%1/3
defined $elemnum and $self->{"elemnum"} = $elemnum
!ll&&!rl&&r
5700
MC/DC0%0/2
defined $elemnum and $self->{"elemnum"} = $elemnum
defined $elemnum $self->{"elemnum"} = $elemnum
Truth table33%1/3
A and B
A= defined $elemnumB= $self->{"elemnum"} = $elemnum
ABresult
0X0
100
111
471  
472 # Parse $lineno, which is empty or has form LinenumType, where
473 # Type is either ':' (real element) or '#' (comment).
474 57 ▶ defined($lineno) or $lineno = '1:';
Branch: 1 branch
BranchTrueFalseTotal
defined $lineno or $lineno = "1:" 57 0 57
475 57 my ($num, $type) =
476 $lineno =~ /^(\d*)\s*(.)/;
477  
478 57 local ($Text::Wrap::columns, $Text::Wrap::huge);
479 57 my $wrapper;
480 $self->{wrap} and
481 ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) =
482 57 ▶ (\&Text::Wrap::wrap, $self->{wrap}, 'overflow')
Branch: 1 branch
BranchTrueFalseTotal
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow") or $wrapper = \&File::OM::text_nowrap 57 0 57
Condition33%1/3
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
!ll&&!rl&&r
0057
MC/DC0%0/2
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
$self->{"wrap"} ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
Truth table33%1/3
A and B
A= $self->{"wrap"}B= ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
ABresult
0X0
100
111
483 or
484 $wrapper = \&File::OM::text_nowrap;
485 ;
486  
487  
488 57 ▶ $self->{elemnum} > 1 and # we've output an element already,
Branch: 1 branch
BranchTrueFalseTotal
$self->{"elemnum"} > 1 and $s .= ',' 39 18 57
489 $s .= ","; # so output a separator character
490  
491 57 ▶ if ($type eq '#') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq '#') { } 0 57 57
elsif (defined $name) { } 54 3 57
492 0 $self->{element_name} = undef; # indicates comment
493 0 $s .= &$wrapper( # wrap lines with '#' as
494 '#', # first line "indent" and
495 '# ', # '# ' for all other indents
496 $self->comment_encode($value) # main part to wrap
497 );
498 }
499 elsif (defined $name) { # no element if no name
500 # xxx this should be stacked
501 54 $self->{element_name} = $self->name_encode($name);
502 54 my $enc_val =
503 $s .= &$wrapper('', '',
504 $self->value_encode($value)); # encoded value
505 # M_ELEMENT and C_ELEMENT would start here
506 }
507 $self->{outhandle} and
508 57 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 0 0
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
057
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
Aresult
00
11
509 or
510 return $s;
511 }
512  
513 18 ▶sub orec { # OM::CSV
Subroutine orec: called CC=11 SCAR=25.9
514 18 my $self = shift;
515 18 my ($recnum, $lineno) = (shift, shift);
516 18 my ($s, $z) = ('', ''); # built string and catchup string
517  
518 18 $self->{elemnum} = 0;
519 $self->{stream_is_open} or # call ostream() to open stream first
520 ($z = $self->ostream(),
521 18 ▶ $self->{stream_is_open} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"stream_is_open"} or $z = $self->ostream, $self->{"stream_is_open"} = 1 18 0 18
522 18 $self->{record_is_open} = 1;
523 18 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 18 0 18
524  
525 defined($recnum) and
526 $self->{recnum} = $recnum
527 or
528 18 ▶ $self->{recnum}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $recnum and $self->{"recnum"} = $recnum or ++$self->{"recnum"} 18 0 18
Condition33%1/3
defined $recnum and $self->{"recnum"} = $recnum
!ll&&!rl&&r
0018
MC/DC0%0/2
defined $recnum and $self->{"recnum"} = $recnum
defined $recnum $self->{"recnum"} = $recnum
Truth table33%1/3
A and B
A= defined $recnumB= $self->{"recnum"} = $recnum
ABresult
0X0
100
111
529  
530 18 ▶ defined($lineno) or $lineno = '1:';
Branch: 1 branch
BranchTrueFalseTotal
defined $lineno or $lineno = "1:" 18 0 18
531 # xxxx really? will someone pass that in?
532  
533 18 ▶ if ($self->{recnum} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"recnum"} == 1) 6 12 18
534  
535 # We're one of the few orec's that use these args.
536 # We do it only to output and possibly define headers.
537 #
538 6 my ($r_elems, $r_elem_order) = (shift, shift);
539  
540 # If the number and order of elements are not defined,
541 # construct them from the ordering implied by record 1.
542 #
543 6 ▶ $r_elem_order or
Branch: 1 branch
BranchTrueFalseTotal
$r_elem_order or $r_elem_order = File::OM::rec2hdr($r_elems) 5 1 6
544 $r_elem_order = File::OM::rec2hdr($r_elems);
545  
546 # We're at record 1 in a CVS file, so output a header.
547 #
548 6 $s .= join(",", map(name_encode($self, $_), @$r_elem_order))
549 . "\n";
550 }
551  
552 $self->{verbose} and
553 18 ▶ $s .= "# from record $self->{recnum}, line $lineno\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"verbose"} and $s .= qq[# from record $self->{"recnum"}, line $lineno\n] 0 18 18
554 $self->{outhandle} and
555 18 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 0 0
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
018
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
Aresult
00
11
556 or
557 return $s;
558 }
559  
560 18 ▶sub crec { # OM::CSV
Subroutine crec: called CC=3 SCAR=12.0
561 18 my ($self, $recnum) = (shift, shift);
562 18 $self->{record_is_open} = 0;
563 18 my $s = "\n";
564 $self->{outhandle} and
565 18 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 0 0
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
018
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
Aresult
00
11
566 or
567 return $s;
568 }
569  
570 6 ▶sub ostream { # OM::CSV
Subroutine ostream: called CC=3 SCAR=11.8
571 6 my $self = shift;
572  
573 6 $self->{recnum} = 0;
574 6 $self->{stream_is_open} = 1;
575 6 my $s = '';
576 $self->{outhandle} and
577 6 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 0 0
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
06
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
Aresult
00
11
578 or
579 return $s;
580 }
581  
582 6 ▶sub cstream { # OM::CSV
Subroutine cstream: called CC=5 SCAR=17.8
583 6 my $self = shift;
584 6 my ($s, $z) = ('', ''); # built string and catchup string
585 $self->{record_is_open} and # wrap up any loose ends
586 6 ▶ $z = $self->crec();
Branch: 1 branch
BranchTrueFalseTotal
$self->{"record_is_open"} and $z = $self->crec 0 6 6
587 6 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 6 0 6
588 6 $self->{stream_is_open} = 0;
589 $self->{outhandle} and
590 6 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 0 0
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
06
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
Aresult
00
11
591 or
592 return $s;
593 }
594  
595 73 ▶sub name_encode { # OM::CSV
Subroutine name_encode: called CC=2 SCAR=7.0
596 # CSV names used only in header line
597 73 my ($self, $s) = (shift, shift);
598 73 ▶ defined($s) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s or return "" 73 0 73
599  
600 # yyy should names be put inside double quotes?
601 #$s =~ s/^\s+//;
602 #$s =~ s/\s+$//; # trim both ends
603 #$s =~ s/\s+/ /g; # squeeze multiple \s to one space
604 73 $s =~ s/"/""/g; # double all internal double-quotes
605  
606 73 return $s;
607 }
608  
609 54 ▶sub value_encode { # OM::CSV
Subroutine value_encode: called CC=2 SCAR=7.0
610 54 my ($self, $s) = (shift, shift);
611 54 ▶ defined($s) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s or return "" 54 0 54
612  
613 54 $s =~ s/"/""/g; # double all internal double-quotes
614 54 $s =~ s/^/"/;
615 54 $s =~ s/$/"/;
616 #$s =~ s/^\s*/"/;
617 #$s =~ s/\s*$/"/; # trim both ends and double-quote
618  
619 54 return $s;
620 }
621  
622 0 ▶sub comment_encode { # OM::CSV
Subroutine comment_encode: not called CC=2 SCAR=17.9
623 # in CSV this would be a pseudo-comment
624 0 my ($self, $s) = (shift, shift);
625 0 ▶ defined($s) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s or return "" 0 0 0
626  
627 0 $s =~ s/"/""/g; # double all internal double-quotes
628 0 $s =~ s/^/"/;
629 0 $s =~ s/$/"/;
630 #$s =~ s/^\s*/"/;
631 #$s =~ s/\s*$/"/; # trim both ends and double-quote
632  
633 0 return $s;
634 }
635  
636 package File::OM::JSON;
637  
638 61 our @ISA = ('File::OM');
639  
640 41 ▶sub elem { # OM::JSON
Subroutine elem: called CC=13 SCAR=25.9
641 41 my $self = shift;
642 41 my ($name, $value, $lineno, $elemnum) = (shift, shift, shift, shift);
643 41 my ($s, $z) = ('', ''); # built string and catchup string
644  
645 $self->{record_is_open} or # call orec() to open record first
646 ($z = $self->orec(undef, $lineno), # may call ostream()
647 41 ▶ $self->{record_is_open} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"record_is_open"} or $z = $self->orec(undef, $lineno), $self->{"record_is_open"} = 1 37 4 41
648 41 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 30 11 41
649  
650 defined($elemnum) and
651 $self->{elemnum} = $elemnum
652 or
653 41 ▶ $self->{elemnum}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $elemnum and $self->{"elemnum"} = $elemnum or ++$self->{"elemnum"} 1 40 41
Condition66%2/3
defined $elemnum and $self->{"elemnum"} = $elemnum
!ll&&!rl&&r
4001
MC/DC50%1/2
defined $elemnum and $self->{"elemnum"} = $elemnum
defined $elemnum $self->{"elemnum"} = $elemnum
Truth table66%2/3
A and B
A= defined $elemnumB= $self->{"elemnum"} = $elemnum
ABresult
0X0
100
111
654  
655 # Parse $lineno, which is empty or has form LinenumType, where
656 # Type is either ':' (real element) or '#' (comment).
657 41 ▶ defined($lineno) or $lineno = '1:';
Branch: 1 branch
BranchTrueFalseTotal
defined $lineno or $lineno = "1:" 30 11 41
658 41 my ($num, $type) =
659 $lineno =~ /^(\d*)\s*(.)/;
660  
661 41 ▶ $type eq '#' and $name = '#'; # JSON pseudo-comment!
Branch: 1 branch
BranchTrueFalseTotal
$type eq "#" and $name = "#" 0 41 41
662 41 ▶ $type eq '#' and $self->{elemnum}--; # doesn't count as elem
Branch: 1 branch
BranchTrueFalseTotal
$type eq "#" and --$self->{"elemnum"} 0 41 41
663 41 ▶ if (defined $name) { # no element if no name
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 41 0 41
664 41 $self->{element_name} = $self->name_encode($name);
665 # either real element or pseudo-comment element was used
666 $self->{elemnum} > 1 || $self->{verbose} and
667 41 ▶ $s .= ',';
Branch: 1 branch
BranchTrueFalseTotal
$self->{"elemnum"} > 1 || $self->{"verbose"} and $s .= ',' 35 6 41
Condition100%3/3
$self->{"elemnum"} > 1 or $self->{"verbose"}
l!l&&r!l&&!r
3236
MC/DC100%2/2
$self->{"elemnum"} > 1 or $self->{"verbose"}
$self->{"elemnum"} > 1 $self->{"verbose"}
Truth table100%3/3
A or B
A= $self->{"elemnum"} > 1B= $self->{"verbose"}
ABresult
1X1
011
000
668 41 $s .= "\n" . $self->{indent};
669 41 $s .= '"' . $self->{element_name} . '": "'
670 . $self->value_encode($value) . '"';
671 }
672 $self->{outhandle} and
673 41 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 11 11
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
1130
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
674 or
675 return $s;
676 }
677  
678 10 ▶sub orec { # OM::JSON
Subroutine orec: called CC=10 SCAR=23.0
679 10 my $self = shift;
680 10 my ($recnum, $lineno) = (shift, shift);
681 10 my ($s, $z) = ('', ''); # built string and catchup string
682  
683 10 $self->{elemnum} = 0;
684 $self->{stream_is_open} or # call ostream() to open stream first
685 ($z = $self->ostream(),
686 10 ▶ $self->{stream_is_open} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"stream_is_open"} or $z = $self->ostream, $self->{"stream_is_open"} = 1 6 4 10
687 10 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 6 4 10
688 10 $self->{record_is_open} = 1;
689  
690 defined($recnum) and
691 $self->{recnum} = $recnum
692 or
693 10 ▶ $self->{recnum}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $recnum and $self->{"recnum"} = $recnum or ++$self->{"recnum"} 5 5 10
Condition66%2/3
defined $recnum and $self->{"recnum"} = $recnum
!ll&&!rl&&r
505
MC/DC50%1/2
defined $recnum and $self->{"recnum"} = $recnum
defined $recnum $self->{"recnum"} = $recnum
Truth table66%2/3
A and B
A= defined $recnumB= $self->{"recnum"} = $recnum
ABresult
0X0
100
111
694  
695 10 ▶ defined($lineno) or $lineno = '1:';
Branch: 1 branch
BranchTrueFalseTotal
defined $lineno or $lineno = "1:" 5 5 10
696 # yyy really? will someone pass that in?
697  
698 10 ▶ $self->{recnum} > 1 and $s .= ',';
Branch: 1 branch
BranchTrueFalseTotal
$self->{"recnum"} > 1 and $s .= ',' 3 7 10
699 10 $s .= "\n" . $self->{indent} . '{'; # use indent and
700 $self->{verbose} and
701 10 ▶ $s .= qq@ "#": "from record $self->{recnum}, line $lineno"@;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"verbose"} and $s .= qq[ "#": "from record $self->{"recnum"}, line $lineno"] 3 7 10
702 10 $self->{indent} =~ s/$/$self->{indent_step}/; # increase indent
703 $self->{outhandle} and
704 10 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 4 4
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
46
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
705 or
706 return $s;
707 }
708  
709 10 ▶sub crec { # OM::JSON
Subroutine crec: called CC=3 SCAR=11.0
710 10 my ($self, $recnum) = (shift, shift);
711 10 $self->{record_is_open} = 0;
712 10 $self->{indent} =~ s/$self->{indent_step}$//; # decrease indent
713 10 my $s = "\n" . $self->{indent} . '}'; # and use indent
714 $self->{outhandle} and
715 10 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 4 4
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
46
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
716 or
717 return $s;
718 }
719  
720 7 ▶sub ostream { # OM::JSON
Subroutine ostream: called CC=4 SCAR=14.0
721 7 my $self = shift;
722  
723 7 $self->{recnum} = 0;
724 7 $self->{stream_is_open} = 1;
725 7 ▶ $self->{indent_step} ||= ' '; # standard indent width
Condition50%1/2
$self->{"indent_step"} ||= " "
l!l
70
MC/DC0%0/1
$self->{"indent_step"} ||= " "
$self->{"indent_step"}
Truth table50%1/2
A
A= $self->{"indent_step"}
Aresult
11
00
726 7 $self->{indent} = $self->{indent_step}; # current indent width
727 7 my $s = '[';
728 $self->{outhandle} and
729 7 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 3 3
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
34
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
730 or
731 return $s;
732 }
733  
734 7 ▶sub cstream { # OM::JSON
Subroutine cstream: called CC=5 SCAR=16.1
735 7 my $self = shift;
736 7 my ($s, $z) = ('', ''); # built string and catchup string
737 $self->{record_is_open} and # wrap up any loose ends
738 7 ▶ $z = $self->crec();
Branch: 1 branch
BranchTrueFalseTotal
$self->{"record_is_open"} and $z = $self->crec 4 3 7
739 7 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 4 3 7
740 7 $self->{stream_is_open} = 0;
741 7 $self->{indent} =~ s/$self->{indent_step}$//; # decrease indent
742 7 $s .= "\n]\n";
743 $self->{outhandle} and
744 7 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 3 3
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
34
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
745 or
746 return $s;
747 }
748  
749 84 ▶sub name_encode { # OM::JSON
Subroutine name_encode: called CC=2 SCAR=7.0
750 84 my ($self, $s) = (shift, shift);
751 84 ▶ defined($s) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s or return "" 84 0 84
752 84 $s =~ s/(["\\])/\\$1/g; # excape " and \
753 84 $s =~ s{
754 ([\x00-\x1f]) # escape all control chars
755 }{
756 2 sprintf("\\u00%02x", ord($1)) # replacement hex code
757 }xeg;
758 84 return $s;
759 }
760  
761 42 ▶sub value_encode { # OM::JSON
Subroutine value_encode: called CC=1 SCAR=0.0
762 42 my $self = shift;
763 42 return $self->name_encode(@_);
764 }
765  
766 0 ▶sub comment_encode { # OM::JSON
Subroutine comment_encode: not called CC=1 SCAR=6.9
767 0 my $self = shift;
768 0 return $self->name_encode(@_);
769 }
770  
771 package File::OM::Plain;
772  
773 61 our @ISA = ('File::OM');
774  
775 30 ▶sub elem { # OM::Plain
Subroutine elem: called CC=13 SCAR=26.8
776 30 my $self = shift;
777 30 my ($name, $value, $lineno, $elemnum) = (shift, shift, shift, shift);
778 30 my ($s, $z) = ('', ''); # built string and catchup string
779  
780 $self->{record_is_open} or # call orec() to open record first
781 ($z = $self->orec(undef, $lineno), # may call ostream()
782 30 ▶ $self->{record_is_open} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"record_is_open"} or $z = $self->orec(undef, $lineno), $self->{"record_is_open"} = 1 26 4 30
783 30 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 25 5 30
784  
785 defined($elemnum) and
786 $self->{elemnum} = $elemnum
787 or
788 30 ▶ $self->{elemnum}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $elemnum and $self->{"elemnum"} = $elemnum or ++$self->{"elemnum"} 0 30 30
Condition33%1/3
defined $elemnum and $self->{"elemnum"} = $elemnum
!ll&&!rl&&r
3000
MC/DC0%0/2
defined $elemnum and $self->{"elemnum"} = $elemnum
defined $elemnum $self->{"elemnum"} = $elemnum
Truth table33%1/3
A and B
A= defined $elemnumB= $self->{"elemnum"} = $elemnum
ABresult
0X0
100
111
789  
790 # Parse $lineno, which is empty or has form LinenumType, where
791 # Type is either ':' (real element) or '#' (comment).
792 30 ▶ defined($lineno) or $lineno = '1:';
Branch: 1 branch
BranchTrueFalseTotal
defined $lineno or $lineno = "1:" 25 5 30
793 30 my ($num, $type) =
794 $lineno =~ /^(\d*)\s*(.)/;
795  
796 30 local ($Text::Wrap::columns, $Text::Wrap::huge);
797 30 my $wrapper;
798 $self->{wrap} and
799 ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) =
800 30 ▶ (\&Text::Wrap::wrap, $self->{wrap}, 'overflow')
Branch: 1 branch
BranchTrueFalseTotal
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow") or $wrapper = \&File::OM::text_nowrap 30 0 30
Condition33%1/3
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
!ll&&!rl&&r
0030
MC/DC0%0/2
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
$self->{"wrap"} ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
Truth table33%1/3
A and B
A= $self->{"wrap"}B= ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
ABresult
0X0
100
111
801 or
802 $wrapper = \&File::OM::text_nowrap;
803 ;
804  
805 30 ▶ if ($type eq '#') { # Plain pseudo-comment!
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq '#') { } 1 29 30
elsif (defined $value and defined $name) { } 29 0 29
806 1 $self->{element_name} = undef; # indicates comment
807 1 $self->{elemnum}--; # doesn't count as an element
808 1 $s .= &$wrapper( # wrap lines with '#' as
809 '#', # first line "indent" and
810 '# ', # '# ' for all other indents
811 $self->comment_encode($value) # main part to wrap
812 );
813 1 $s .= "\n"; # close comment
814 }
815 ▶ elsif (defined($value) and defined($name)) { # no element if no name
Condition33%1/3
defined $value and defined $name
!ll&&!rl&&r
0029
MC/DC0%0/2
defined $value and defined $name
defined $value defined $name
Truth table33%1/3
A and B
A= defined $valueB= defined $name
ABresult
0X0
100
111
816 # It is a feature of Plain not to print if value is empty.
817 29 $self->{element_name} = $self->name_encode($name);
818 29 $s .= &$wrapper( # wrap lines with '' as
819 '', # first line "indent" and
820 '', # '' for all other indents
821 $self->value_encode($value) # main part to wrap
822 );
823 29 $s .= "\n";
824 }
825 $self->{outhandle} and
826 30 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 5 5
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
525
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
827 or
828 return $s;
829 }
830  
831 8 ▶sub orec { # OM::Plain
Subroutine orec: called CC=9 SCAR=22.0
832 8 my $self = shift;
833 8 my ($recnum, $lineno) = (shift, shift);
834 8 my ($s, $z) = ('', ''); # built string and catchup string
835  
836 8 $self->{elemnum} = 0;
837 $self->{stream_is_open} or # call ostream() to open stream first
838 ($z = $self->ostream(),
839 8 ▶ $self->{stream_is_open} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"stream_is_open"} or $z = $self->ostream, $self->{"stream_is_open"} = 1 4 4 8
840 8 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 5 3 8
841 8 $self->{record_is_open} = 1;
842  
843 defined($recnum) and
844 $self->{recnum} = $recnum
845 or
846 8 ▶ $self->{recnum}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $recnum and $self->{"recnum"} = $recnum or ++$self->{"recnum"} 4 4 8
Condition66%2/3
defined $recnum and $self->{"recnum"} = $recnum
!ll&&!rl&&r
404
MC/DC50%1/2
defined $recnum and $self->{"recnum"} = $recnum
defined $recnum $self->{"recnum"} = $recnum
Truth table66%2/3
A and B
A= defined $recnumB= $self->{"recnum"} = $recnum
ABresult
0X0
100
111
847  
848 8 ▶ defined($lineno) or $lineno = '1:';
Branch: 1 branch
BranchTrueFalseTotal
defined $lineno or $lineno = "1:" 5 3 8
849  
850 $self->{verbose} and
851 8 ▶ $s .= "# from record $recnum, line $lineno\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"verbose"} and $s .= "# from record $recnum, line $lineno\n" 3 5 8
852 $self->{outhandle} and
853 8 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 3 3
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
35
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
854 or
855 return $s;
856 }
857  
858 8 ▶sub crec { # OM::Plain
Subroutine crec: called CC=3 SCAR=11.0
859 8 my ($self, $recnum) = (shift, shift);
860 8 $self->{record_is_open} = 0;
861 8 my $s = "\n";
862 $self->{outhandle} and
863 8 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 3 3
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
35
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
864 or
865 return $s;
866 }
867  
868 6 ▶sub ostream { # OM::Plain
Subroutine ostream: called CC=3 SCAR=11.0
869 6 my $self = shift;
870 6 my $s = '';
871  
872 6 $self->{recnum} = 0;
873 6 $self->{stream_is_open} = 1;
874 $self->{outhandle} and
875 6 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 3 3
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
33
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
876 or
877 return $s;
878 #$$o{indent_step} ||= ''; # standard indent width
879 #$$o{indent} = $$o{indent_step}; # current indent width
880 }
881  
882 6 ▶sub cstream { # OM::Plain
Subroutine cstream: called CC=5 SCAR=16.1
883 6 my $self = shift;
884 6 my ($s, $z) = ('', ''); # built string and catchup string
885 $self->{record_is_open} and # wrap up any loose ends
886 6 ▶ $z = $self->crec();
Branch: 1 branch
BranchTrueFalseTotal
$self->{"record_is_open"} and $z = $self->crec 4 2 6
887 6 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 3 3 6
888 6 $self->{stream_is_open} = 0;
889 $self->{outhandle} and
890 6 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 3 3
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
33
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
891 or
892 return $s;
893 }
894  
895 29 ▶sub name_encode { # OM::Plain
Subroutine name_encode: called CC=1 SCAR=0.0
896 29 my ($self, $s) = (shift, shift);
897 29 return $s;
898 }
899  
900 29 ▶sub value_encode { # OM::Plain
Subroutine value_encode: called CC=1 SCAR=0.0
901 29 my ($self, $s) = (shift, shift);
902 29 return $s;
903 }
904  
905 1 ▶sub comment_encode { # OM::Plain
Subroutine comment_encode: called CC=1 SCAR=0.0
906 1 my ($self, $s) = (shift, shift);
907 1 return $s;
908 }
909  
910 # XXXXXXXXXX just a copy of CSV for now
911 package File::OM::PSV;
912  
913 61 our @ISA = ('File::OM');
914  
915 21 ▶sub elem { # OM::PSV
Subroutine elem: called CC=13 SCAR=30.3
916 21 my $self = shift;
917 21 my ($name, $value, $lineno, $elemnum) = (shift, shift, shift, shift);
918 21 my ($s, $z) = ('', ''); # built string and catchup string
919  
920 $self->{record_is_open} or # call orec() to open record first
921 ($z = $self->orec(undef, $lineno), # may call ostream()
922 21 ▶ $self->{record_is_open} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"record_is_open"} or $z = $self->orec(undef, $lineno), $self->{"record_is_open"} = 1 21 0 21
923 21 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 21 0 21
924  
925 defined($elemnum) and
926 $self->{elemnum} = $elemnum
927 or
928 21 ▶ $self->{elemnum}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $elemnum and $self->{"elemnum"} = $elemnum or ++$self->{"elemnum"} 0 21 21
Condition33%1/3
defined $elemnum and $self->{"elemnum"} = $elemnum
!ll&&!rl&&r
2100
MC/DC0%0/2
defined $elemnum and $self->{"elemnum"} = $elemnum
defined $elemnum $self->{"elemnum"} = $elemnum
Truth table33%1/3
A and B
A= defined $elemnumB= $self->{"elemnum"} = $elemnum
ABresult
0X0
100
111
929  
930 # Parse $lineno, which is empty or has form LinenumType, where
931 # Type is either ':' (real element) or '#' (comment).
932 21 ▶ defined($lineno) or $lineno = '1:';
Branch: 1 branch
BranchTrueFalseTotal
defined $lineno or $lineno = "1:" 21 0 21
933 21 my ($num, $type) =
934 $lineno =~ /^(\d*)\s*(.)/;
935  
936 21 local ($Text::Wrap::columns, $Text::Wrap::huge);
937 21 my $wrapper;
938 $self->{wrap} and
939 ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) =
940 21 ▶ (\&Text::Wrap::wrap, $self->{wrap}, 'overflow')
Branch: 1 branch
BranchTrueFalseTotal
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow") or $wrapper = \&File::OM::text_nowrap 21 0 21
Condition33%1/3
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
!ll&&!rl&&r
0021
MC/DC0%0/2
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
$self->{"wrap"} ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
Truth table33%1/3
A and B
A= $self->{"wrap"}B= ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
ABresult
0X0
100
111
941 or
942 $wrapper = \&File::OM::text_nowrap;
943 ;
944  
945  
946 21 ▶ $self->{elemnum} > 1 and # we've output an element already,
Branch: 1 branch
BranchTrueFalseTotal
$self->{"elemnum"} > 1 and $s .= '|' 15 6 21
947 $s .= "|"; # so output a separator character
948  
949 21 ▶ if ($type eq '#') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq '#') { } 0 21 21
elsif (defined $name) { } 21 0 21
950 0 $self->{element_name} = undef; # indicates comment
951 0 $s .= &$wrapper( # wrap lines with '#' as
952 '#', # first line "indent" and
953 '# ', # '# ' for all other indents
954 $self->comment_encode($value) # main part to wrap
955 );
956 }
957 elsif (defined $name) { # no element if no name
958 # xxx this should be stacked
959 21 $self->{element_name} = $self->name_encode($name);
960 21 my $enc_val =
961 $s .= &$wrapper('', '',
962 $self->value_encode($value)); # encoded value
963 # M_ELEMENT and C_ELEMENT would start here
964 }
965 $self->{outhandle} and
966 21 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 0 0
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
021
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
Aresult
00
11
967 or
968 return $s;
969 }
970  
971 6 ▶sub orec { # OM::PSV
Subroutine orec: called CC=11 SCAR=26.5
972 6 my $self = shift;
973 6 my ($recnum, $lineno) = (shift, shift);
974 6 my ($s, $z) = ('', ''); # built string and catchup string
975  
976 6 $self->{elemnum} = 0;
977 $self->{stream_is_open} or # call ostream() to open stream first
978 ($z = $self->ostream(),
979 6 ▶ $self->{stream_is_open} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"stream_is_open"} or $z = $self->ostream, $self->{"stream_is_open"} = 1 6 0 6
980 6 $self->{record_is_open} = 1;
981 6 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 6 0 6
982  
983 defined($recnum) and
984 $self->{recnum} = $recnum
985 or
986 6 ▶ $self->{recnum}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $recnum and $self->{"recnum"} = $recnum or ++$self->{"recnum"} 6 0 6
Condition33%1/3
defined $recnum and $self->{"recnum"} = $recnum
!ll&&!rl&&r
006
MC/DC0%0/2
defined $recnum and $self->{"recnum"} = $recnum
defined $recnum $self->{"recnum"} = $recnum
Truth table33%1/3
A and B
A= defined $recnumB= $self->{"recnum"} = $recnum
ABresult
0X0
100
111
987  
988 6 ▶ defined($lineno) or $lineno = '1:';
Branch: 1 branch
BranchTrueFalseTotal
defined $lineno or $lineno = "1:" 6 0 6
989 # xxxx really? will someone pass that in?
990  
991 6 ▶ if ($self->{recnum} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"recnum"} == 1) 2 4 6
992  
993 # We're one of the few orec's that use these args.
994 # We do it only to output and possibly define headers.
995 #
996 2 my ($r_elems, $r_elem_order) = (shift, shift);
997  
998 # If the number and order of elements are not defined,
999 # construct them from the ordering implied by record 1.
1000 #
1001 2 ▶ $r_elem_order or
Branch: 1 branch
BranchTrueFalseTotal
$r_elem_order or $r_elem_order = File::OM::rec2hdr($r_elems) 2 0 2
1002 $r_elem_order = File::OM::rec2hdr($r_elems);
1003  
1004 # We're at record 1 in a CVS file, so output a header.
1005 #
1006 2 $s .= join("|", map(name_encode($self, $_), @$r_elem_order))
1007 . "\n";
1008 }
1009  
1010 $self->{verbose} and
1011 6 ▶ $s .= "# from record $self->{recnum}, line $lineno\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"verbose"} and $s .= qq[# from record $self->{"recnum"}, line $lineno\n] 0 6 6
1012 $self->{outhandle} and
1013 6 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 0 0
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
06
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
Aresult
00
11
1014 or
1015 return $s;
1016 }
1017  
1018 6 ▶sub crec { # OM::PSV
Subroutine crec: called CC=3 SCAR=12.0
1019 6 my ($self, $recnum) = (shift, shift);
1020 6 $self->{record_is_open} = 0;
1021 6 my $s = "\n";
1022 $self->{outhandle} and
1023 6 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 0 0
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
06
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
Aresult
00
11
1024 or
1025 return $s;
1026 }
1027  
1028 2 ▶sub ostream { # OM::PSV
Subroutine ostream: called CC=3 SCAR=11.8
1029 2 my $self = shift;
1030  
1031 2 $self->{recnum} = 0;
1032 2 $self->{stream_is_open} = 1;
1033 2 my $s = '';
1034 $self->{outhandle} and
1035 2 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 0 0
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
02
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
Aresult
00
11
1036 or
1037 return $s;
1038 }
1039  
1040 2 ▶sub cstream { # OM::PSV
Subroutine cstream: called CC=5 SCAR=17.8
1041 2 my $self = shift;
1042 2 my ($s, $z) = ('', ''); # built string and catchup string
1043 $self->{record_is_open} and # wrap up any loose ends
1044 2 ▶ $z = $self->crec();
Branch: 1 branch
BranchTrueFalseTotal
$self->{"record_is_open"} and $z = $self->crec 0 2 2
1045 2 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 2 0 2
1046 2 $self->{stream_is_open} = 0;
1047 $self->{outhandle} and
1048 2 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 0 0
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
02
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
Aresult
00
11
1049 or
1050 return $s;
1051 }
1052  
1053 28 ▶sub name_encode { # OM::PSV
Subroutine name_encode: called CC=2 SCAR=7.0
1054 # PSV names used only in header line
1055 28 my ($self, $s) = (shift, shift);
1056 28 ▶ defined($s) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s or return "" 28 0 28
1057  
1058 # xxx document how we don't trim, but encode spaces
1059 # xxxxxxx and then encode!!
1060 #$s =~ s/^\s+//;
1061 #$s =~ s/\s+$//; # trim both ends
1062 #$s =~ s/\s+/ /g; # squeeze multiple \s to one space
1063 28 $s =~ s/%/%%/g; # to preserve literal %, double it
1064 # yyy must be decoded by receiver
1065 28 $s =~ s/\|/%7c/g; # URL-encode all colons
1066 28 $s =~ s/\n/%0a/g; # URL-encode all newlines
1067  
1068 28 return $s;
1069 }
1070  
1071 21 ▶sub value_encode { # OM::PSV
Subroutine value_encode: called CC=2 SCAR=7.0
1072 21 my ($self, $s) = (shift, shift);
1073 21 ▶ defined($s) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s or return "" 21 0 21
1074  
1075 # xxx document how we don't trim, but encode spaces
1076 # xxxxxxx and then encode!!
1077 #$s =~ s/^\s+//;
1078 #$s =~ s/\s+$//; # trim both ends
1079 #$s =~ s/\s+/ /g; # squeeze multiple \s to one space
1080 21 $s =~ s/%/%%/g; # to preserve literal %, double it
1081 # yyy must be decoded by receiver
1082 21 $s =~ s/\|/%7c/g; # URL-encode all colons
1083 21 $s =~ s/\n/%0a/g; # URL-encode all newlines
1084  
1085 21 return $s;
1086 }
1087  
1088 0 ▶sub comment_encode { # OM::PSV
Subroutine comment_encode: not called CC=2 SCAR=17.9
1089 # in PSV this would be a pseudo-comment
1090 0 my ($self, $s) = (shift, shift);
1091 0 ▶ defined($s) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s or return "" 0 0 0
1092  
1093 0 $s =~ s/%/%%/g; # to preserve literal %, double it
1094 # yyy must be decoded by receiver
1095 0 $s =~ s/\|/%7c/g; # URL-encode all colons
1096 0 $s =~ s/\n/%0a/g; # URL-encode all newlines
1097  
1098 0 return $s;
1099 }
1100  
1101 package File::OM::Turtle;
1102  
1103 61 our @ISA = ('File::OM');
1104  
1105 65 ▶sub elem { # OM::Turtle
Subroutine elem: called CC=11 SCAR=24.2
1106  
1107 65 my $self = shift;
1108 65 my ($name, $value, $lineno, $elemnum) = (shift, shift, shift, shift);
1109 65 my ($s, $z) = ('', ''); # built string and catchup string
1110  
1111 $self->{record_is_open} or # call orec() to open record first
1112 ($z = $self->orec(undef, $lineno), # may call ostream()
1113 65 ▶ $self->{record_is_open} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"record_is_open"} or $z = $self->orec(undef, $lineno), $self->{"record_is_open"} = 1 63 2 65
1114 65 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 61 4 65
1115  
1116 defined($elemnum) and
1117 $self->{elemnum} = $elemnum
1118 or
1119 65 ▶ $self->{elemnum}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $elemnum and $self->{"elemnum"} = $elemnum or ++$self->{"elemnum"} 0 65 65
Condition33%1/3
defined $elemnum and $self->{"elemnum"} = $elemnum
!ll&&!rl&&r
6500
MC/DC0%0/2
defined $elemnum and $self->{"elemnum"} = $elemnum
defined $elemnum $self->{"elemnum"} = $elemnum
Truth table33%1/3
A and B
A= defined $elemnumB= $self->{"elemnum"} = $elemnum
ABresult
0X0
100
111
1120  
1121 # Parse $lineno, which is empty or has form LinenumType, where
1122 # Type is either ':' (real element) or '#' (comment).
1123 65 ▶ defined($lineno) or $lineno = '1:';
Branch: 1 branch
BranchTrueFalseTotal
defined $lineno or $lineno = "1:" 60 5 65
1124 65 my ($num, $type) =
1125 $lineno =~ /^(\d*)\s*(.)/;
1126  
1127 65 ▶ if ($type eq '#') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq '#') { } 5 60 65
elsif (defined $name) { } 60 0 60
1128 5 $self->{element_name} = undef; # indicates comment
1129 5 $self->{elemnum}--; # doesn't count as an element
1130 5 $s .= "\n#" . $self->comment_encode($value) . "\n";
1131 #
1132 # To create syntactically correct Turtle, we need
1133 # to end a comment with a newline at the end; this
1134 # can, however, result in ugly Turtle, since the
1135 # ';' or '.' that ends an element will have to
1136 # follow on the next line after that, and the only
1137 # remedy is to peek ahead at the next element.
1138 }
1139 elsif (defined $name) { # no element if no name
1140 60 $self->{element_name} = $self->name_encode($name);
1141 60 ▶ $self->{elemnum} > 1 and $s .= ' ;';
Branch: 1 branch
BranchTrueFalseTotal
$self->{"elemnum"} > 1 and $s .= ' ;' 45 15 60
1142 60 $s .= "\n" . $self->{turtle_indent};
1143 $s .= $self->{turtle_stream_prefix}
1144 60 . ":$self->{element_name} "
1145 . '"""'
1146 . $self->value_encode($value)
1147 . '"""';
1148 }
1149 $self->{outhandle} and
1150 65 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 4 4
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
461
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
1151 or
1152 return $s;
1153 }
1154  
1155 15 ▶sub orec { # OM::Turtle
Subroutine orec: called CC=10 SCAR=23.0
1156 15 my $self = shift;
1157 15 my ($recnum, $lineno) = (shift, shift);
1158 15 my ($s, $z) = ('', ''); # built string and catchup string
1159  
1160 15 $self->{elemnum} = 0;
1161 $self->{stream_is_open} or # call ostream() to open stream first
1162 ($z = $self->ostream(),
1163 15 ▶ $self->{stream_is_open} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"stream_is_open"} or $z = $self->ostream, $self->{"stream_is_open"} = 1 12 3 15
1164 15 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 13 2 15
1165 15 $self->{record_is_open} = 1;
1166  
1167 defined($recnum) and
1168 $self->{recnum} = $recnum
1169 or
1170 15 ▶ $self->{recnum}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $recnum and $self->{"recnum"} = $recnum or ++$self->{"recnum"} 13 2 15
Condition66%2/3
defined $recnum and $self->{"recnum"} = $recnum
!ll&&!rl&&r
2013
MC/DC50%1/2
defined $recnum and $self->{"recnum"} = $recnum
defined $recnum $self->{"recnum"} = $recnum
Truth table66%2/3
A and B
A= defined $recnumB= $self->{"recnum"} = $recnum
ABresult
0X0
100
111
1171  
1172 15 ▶ defined($lineno) or $lineno = '1:';
Branch: 1 branch
BranchTrueFalseTotal
defined $lineno or $lineno = "1:" 12 3 15
1173  
1174 $self->{verbose} and
1175 15 ▶ $s .= "# from record $recnum, line $lineno\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"verbose"} and $s .= "# from record $recnum, line $lineno\n" 3 12 15
1176 defined($self->{subject}) or
1177 15 ▶ $self->{subject} = $self->{turtle_nosubject};
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"subject"} or $self->{"subject"} = $self->{"turtle_nosubject"} 12 3 15
1178 15 $s .= "<$self->{subject}>";
1179  
1180 $self->{outhandle} and
1181 15 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 2 2
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
213
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
1182 or
1183 return $s;
1184 }
1185  
1186 15 ▶sub crec { # OM::Turtle
Subroutine crec: called CC=3 SCAR=11.0
1187 15 my ($self, $recnum) = (shift, shift);
1188 15 $self->{record_is_open} = 0;
1189 15 my $s = " .\n\n";
1190 $self->{outhandle} and
1191 15 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 2 2
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
213
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
1192 or
1193 return $s;
1194 }
1195  
1196 13 ▶sub ostream { # OM::Turtle
Subroutine ostream: called CC=3 SCAR=11.0
1197 13 my $self = shift;
1198 13 my $s = '';;
1199  
1200 13 $self->{recnum} = 0;
1201 13 $self->{stream_is_open} = 1;
1202 # add the Turtle preamble
1203 $s .= "\@prefix $self->{turtle_stream_prefix}: <"
1204 13 . $self->{turtle_predns} . "> .\n";
1205 $self->{outhandle} and
1206 13 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 2 2
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
211
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
1207 or
1208 return $s;
1209 }
1210  
1211 13 ▶sub cstream { # OM::Turtle
Subroutine cstream: called CC=5 SCAR=16.1
1212 13 my $self = shift;
1213 13 my ($s, $z) = ('', ''); # built string and catchup string
1214 $self->{record_is_open} and # wrap up any loose ends
1215 13 ▶ $z = $self->crec();
Branch: 1 branch
BranchTrueFalseTotal
$self->{"record_is_open"} and $z = $self->crec 3 10 13
1216 13 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 11 2 13
1217 13 $self->{stream_is_open} = 0;
1218 $self->{outhandle} and
1219 13 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 2 2
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
211
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
1220 or
1221 return $s;
1222 }
1223  
1224 60 ▶sub name_encode { # OM::Turtle
Subroutine name_encode: called CC=2 SCAR=7.0
1225 60 my ($self, $s) = (shift, shift);
1226 60 ▶ defined($s) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s or return "" 60 0 60
1227 60 $s =~ s/(["\\])/\\$1/g;
1228 60 return $s;
1229 # \" \\
1230 }
1231  
1232 61 ▶sub value_encode { # OM::Turtle
Subroutine value_encode: called CC=2 SCAR=7.0
1233 61 my ($self, $s) = (shift, shift);
1234 61 ▶ defined($s) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s or return "" 61 0 61
1235 61 $s =~ s/(["\\])/\\$1/g;
1236 61 return $s;
1237 }
1238  
1239 5 ▶sub comment_encode { # OM::Turtle
Subroutine comment_encode: called CC=2 SCAR=7.0
1240 5 my ($self, $s) = (shift, shift);
1241 5 ▶ defined($s) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s or return "" 5 0 5
1242 5 $s =~ s/\n/\\n/g; # escape \n
1243 5 return $s;
1244 }
1245  
1246 package File::OM::XML;
1247  
1248 61 our @ISA = ('File::OM');
1249  
1250 56 ▶sub elem { # OM::XML
Subroutine elem: called CC=14 SCAR=27.1
1251 56 my $self = shift;
1252 56 my ($name, $value, $lineno, $elemnum) = (shift, shift, shift, shift);
1253 56 my ($s, $z) = ('', ''); # built string and catchup string
1254  
1255 $self->{record_is_open} or # call orec() to open record first
1256 ($z = $self->orec(undef, $lineno), # may call ostream()
1257 56 ▶ $self->{record_is_open} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"record_is_open"} or $z = $self->orec(undef, $lineno), $self->{"record_is_open"} = 1 50 6 56
1258 56 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 46 10 56
1259  
1260 defined($elemnum) and
1261 $self->{elemnum} = $elemnum
1262 or
1263 56 ▶ $self->{elemnum}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $elemnum and $self->{"elemnum"} = $elemnum or ++$self->{"elemnum"} 0 56 56
Condition33%1/3
defined $elemnum and $self->{"elemnum"} = $elemnum
!ll&&!rl&&r
5600
MC/DC0%0/2
defined $elemnum and $self->{"elemnum"} = $elemnum
defined $elemnum $self->{"elemnum"} = $elemnum
Truth table33%1/3
A and B
A= defined $elemnumB= $self->{"elemnum"} = $elemnum
ABresult
0X0
100
111
1264  
1265 # Parse $lineno, which is empty or has form LinenumType, where
1266 # Type is either ':' (real element) or '#' (comment).
1267 56 ▶ defined($lineno) or $lineno = '1:';
Branch: 1 branch
BranchTrueFalseTotal
defined $lineno or $lineno = "1:" 47 9 56
1268 56 my ($num, $type) =
1269 $lineno =~ /^(\d*)\s*(.)/;
1270  
1271 56 local ($Text::Wrap::columns, $Text::Wrap::huge);
1272 56 my $wrapper;
1273 $self->{wrap} and
1274 ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) =
1275 56 ▶ (\&Text::Wrap::wrap, $self->{wrap}, 'overflow')
Branch: 1 branch
BranchTrueFalseTotal
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow") or $wrapper = \&File::OM::text_nowrap 56 0 56
Condition33%1/3
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
!ll&&!rl&&r
0056
MC/DC0%0/2
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
$self->{"wrap"} ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
Truth table33%1/3
A and B
A= $self->{"wrap"}B= ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
ABresult
0X0
100
111
1276 or
1277 $wrapper = \&File::OM::text_nowrap;
1278 ;
1279  
1280  
1281 56 ▶ if ($type eq '#') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq '#') { } 4 52 56
elsif (defined $name) { } 52 0 52
1282 # xxx this should be stacked
1283 4 $self->{element_name} = undef; # indicates comment
1284 4 $self->{elemnum}--; # doesn't count as an element
1285  
1286 4 my $enc_com = $self->comment_encode($value); # encoded value
1287 $s .= $enc_com =~ /^\s*$/ ? # wrap() loses label of
1288 $self->{indent} . # a blank value so put
1289 "<!--$enc_com" : # here instead
1290 &$wrapper( # wrap lines; this 1st
1291 "$self->{indent}<!--", # "indent" won't break
1292 $self->{indent}, # other line indents
1293 4 ▶ $enc_com) # main part to wrap
Branch: 1 branch
BranchTrueFalseTotal
$enc_com =~ /^\s*$/ ? : 0 4 4
1294 ;
1295 #$s .= "$self->{indent}<!-- " .
1296 # $self->comment_encode($value);
1297 # M_ELEMENT and C_ELEMENT would start here
1298 4 $s .= "-->\n"; # close comment
1299 }
1300 elsif (defined $name) { # no element if no name
1301 # xxx we're saving this to no end; in full form
1302 # (open and close element) the element name would
1303 # be saved on a stack and the indent increased
1304 # across all outformat types.
1305 #
1306 52 $self->{element_name} = $self->name_encode($name);
1307 52 my $enc_val = $self->value_encode($value); # encoded value
1308 $s .= $enc_val =~ /^\s*$/ ? # wrap() loses label of
1309 $self->{indent} . # a blank value so put
1310 "<$self->{element_name}>" : # here instead
1311 &$wrapper( # wrap lines; this 1st
1312 $self->{indent} . # "indent" won't break
1313 "<$self->{element_name}>", # label
1314 $self->{indent}, # other line indents
1315 52 ▶ $enc_val) # main part to wrap
Branch: 1 branch
BranchTrueFalseTotal
$enc_val =~ /^\s*$/ ? : 5 47 52
1316 ;
1317 #$s .= $self->{indent} . "<$self->{element_name}>"
1318 # . $self->value_encode($value);
1319 # M_ELEMENT and C_ELEMENT would start here
1320 52 $s .= "</$self->{element_name}>\n";
1321 }
1322 $self->{outhandle} and
1323 56 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 10 10
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
1046
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
1324 or
1325 return $s;
1326 }
1327  
1328 17 ▶sub orec { # OM::XML
Subroutine orec: called CC=9 SCAR=22.0
1329 17 my $self = shift;
1330 17 my ($recnum, $lineno) = (shift, shift);
1331 17 my ($s, $z) = ('', ''); # built string and catchup string
1332  
1333 17 $self->{elemnum} = 0;
1334 $self->{stream_is_open} or # call ostream() to open stream first
1335 ($z = $self->ostream(),
1336 17 ▶ $self->{stream_is_open} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"stream_is_open"} or $z = $self->ostream, $self->{"stream_is_open"} = 1 11 6 17
1337 17 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 11 6 17
1338 17 $self->{record_is_open} = 1;
1339  
1340 defined($recnum) and
1341 $self->{recnum} = $recnum
1342 or
1343 17 ▶ $self->{recnum}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $recnum and $self->{"recnum"} = $recnum or ++$self->{"recnum"} 10 7 17
Condition66%2/3
defined $recnum and $self->{"recnum"} = $recnum
!ll&&!rl&&r
7010
MC/DC50%1/2
defined $recnum and $self->{"recnum"} = $recnum
defined $recnum $self->{"recnum"} = $recnum
Truth table66%2/3
A and B
A= defined $recnumB= $self->{"recnum"} = $recnum
ABresult
0X0
100
111
1344  
1345 17 ▶ defined($lineno) or $lineno = '1:';
Branch: 1 branch
BranchTrueFalseTotal
defined $lineno or $lineno = "1:" 11 6 17
1346  
1347 $s .= $self->{indent} . # use indent and
1348 17 "<$self->{xml_record_name}>";
1349 17 $self->{indent} =~ s/$/$self->{indent_step}/; # increase indent
1350 $self->{verbose} and
1351 17 ▶ $s .= " <!-- from record $self->{recnum}, line $lineno -->";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"verbose"} and $s .= qq[ <!-- from record $self->{"recnum"}, line $lineno -->] 6 11 17
1352 17 $s .= "\n";
1353 $self->{outhandle} and
1354 17 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 6 6
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
611
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
1355 or
1356 return $s;
1357 }
1358  
1359 16 ▶sub crec { # OM::XML
Subroutine crec: called CC=3 SCAR=11.0
1360 16 my ($self, $recnum) = (shift, shift);
1361 16 $self->{record_is_open} = 0;
1362 16 $self->{indent} =~ s/$self->{indent_step}$//; # decrease indent
1363 my $s = $self->{indent} . # and use indent
1364 16 "</$self->{xml_record_name}>\n";
1365 $self->{outhandle} and
1366 16 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 5 5
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
511
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
1367 or
1368 return $s;
1369 }
1370  
1371 14 ▶sub ostream { # OM::XML
Subroutine ostream: called CC=3 SCAR=11.0
1372 14 my $self = shift;
1373  
1374 14 $self->{recnum} = 0;
1375 14 $self->{stream_is_open} = 1;
1376 14 $self->{indent} = $self->{indent_start}; # current indent width
1377 14 $self->{indent} =~ s/$/$self->{indent_step}/; # increase indent
1378 14 my $s = "<$self->{xml_stream_name}>\n";
1379 $self->{outhandle} and
1380 14 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 5 5
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
59
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
1381 or
1382 return $s;
1383 }
1384  
1385 14 ▶sub cstream { # OM::XML
Subroutine cstream: called CC=5 SCAR=16.1
1386 14 my $self = shift;
1387 14 my ($s, $z) = ('', ''); # built string and catchup string
1388 $self->{record_is_open} and # wrap up any loose ends
1389 14 ▶ $z = $self->crec();
Branch: 1 branch
BranchTrueFalseTotal
$self->{"record_is_open"} and $z = $self->crec 6 8 14
1390 14 ▶ $self->{outhandle} or $s .= $z; # don't retain print status
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} or $s .= $z 9 5 14
1391 14 $self->{stream_is_open} = 0;
1392 14 $self->{indent} =~ s/$self->{indent_step}$//; # decrease indent
1393 14 $s .= "</$self->{xml_stream_name}>\n";
1394 $self->{outhandle} and
1395 14 ▶ return (print { $self->{outhandle} } $s)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s) or return $s 0 5 5
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
!ll
59
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
Aresult
00
11
1396 or
1397 return $s;
1398 }
1399  
1400 106 ▶sub name_encode { # OM::XML
Subroutine name_encode: called CC=2 SCAR=6.9
1401 106 my $self = shift;
1402 106 local $_ = shift(@_);
1403 106 ▶ defined($_) or $_ = '';
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or $_ = "" 106 0 106
1404  
1405 106 s/&/&amp;/g;
1406 106 s/'/&apos;/g;
1407 106 s/</&lt;/g;
1408 106 s/>/&gt;/g;
1409 106 s/\\/\\\\/g;
1410 106 s/"/\\"/g;
1411  
1412 106 return $_;
1413  
1414 # &apos; &amp; &lt; &gt; (unparsed \" \\ )
1415 # XXXX CDATA sections begin with the string " <![CDATA[ "
1416 # and end with the string " ]]> "
1417 }
1418  
1419 53 ▶sub value_encode { # OM::XML
Subroutine value_encode: called CC=1 SCAR=0.0
1420 53 my $self = shift;
1421 53 return $self->name_encode(@_);
1422 }
1423  
1424 5 ▶sub comment_encode { # OM::XML
Subroutine comment_encode: called CC=2 SCAR=7.0
1425 5 my ($self, $s) = (shift, shift);
1426 5 ▶ defined($s) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s or return "" 5 0 5
1427 5 $s =~ s/-->/--&gt;/g;
1428 5 return $s;
1429 }
1430  
1431 61 1;
1432  
1433 __END__
« blib/lib/File/ANVL.pm ↑ Summary blib/lib/File/ERC.pm »