| 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() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 81 | 81 | my $self = om_opt_defaults(); | |||||||||||||||||||||||||||
| 82 | 81 | ▶ | my $format = lc (shift || ''); | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || ''
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 83 | 81 | ▶ | if ($format) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 77 | $format = $outputformats{$format}; # canonical name | |||||||||||||||||||||||||||
| 85 | 77 | ▶ | $format or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 110 | 85 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | $self->{outhandle} and | ||||||||||||||||||||||||||||
| 112 | 85 | ▶ | return (print { $self->{outhandle} } $s) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$name or $value
MC/DC50%1/2
$name or $value
$name
$value
Truth table66%2/3
A or B
A= $nameB= $value
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 7 | ▶ | $n > 0 and # normal element case | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 176 | 184 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | defined($elemnum) and | ||||||||||||||||||||||||||||
| 179 | $self->{elemnum} = $elemnum | ||||||||||||||||||||||||||||
| 180 | or | ||||||||||||||||||||||||||||
| 181 | 184 | ▶ | $self->{elemnum}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $elemnum and $self->{"elemnum"} = $elemnum
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge, $Text::Wrap::unexpand) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow", 0)
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)
| |||||||||||||||||||||||||||||
| 195 | or | ||||||||||||||||||||||||||||
| 196 | $wrapper = \&File::OM::text_nowrap; | ||||||||||||||||||||||||||||
| 197 | ; | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 184 | ▶ | if ($type eq '#') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 247 | 0 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
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")
| |||||||||||||||||||||||||||||
| 265 | or | ||||||||||||||||||||||||||||
| 266 | $wrapper = \&File::OM::text_nowrap; | ||||||||||||||||||||||||||||
| 267 | ; | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 0 | ▶ | if ($type eq '#') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table0%0/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 315 | 63 | $self->{record_is_open} = 1; | |||||||||||||||||||||||||||
| 316 | 63 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | defined($recnum) and | ||||||||||||||||||||||||||||
| 319 | $self->{recnum} = $recnum | ||||||||||||||||||||||||||||
| 320 | or | ||||||||||||||||||||||||||||
| 321 | 63 | ▶ | $self->{recnum}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $recnum and $self->{"recnum"} = $recnum
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
| |||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 63 | ▶ | defined($lineno) or $lineno = '1:'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 328 | $self->{outhandle} and | ||||||||||||||||||||||||||||
| 329 | 63 | ▶ | return (print { $self->{outhandle} } $s) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 362 | 28 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | 28 | $self->{stream_is_open} = 0; | |||||||||||||||||||||||||||
| 364 | $self->{outhandle} and | ||||||||||||||||||||||||||||
| 365 | 28 | ▶ | return (print { $self->{outhandle} } $s) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 410 | 155 | ▶ | $anvl_mode ||= 'ANVL'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$anvl_mode ||= "ANVL"
MC/DC0%0/1
$anvl_mode ||= "ANVL"
$anvl_mode
Truth table50%1/2
A
A= $anvl_mode
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 465 | 57 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | defined($elemnum) and | ||||||||||||||||||||||||||||
| 468 | $self->{elemnum} = $elemnum | ||||||||||||||||||||||||||||
| 469 | or | ||||||||||||||||||||||||||||
| 470 | 57 | ▶ | $self->{elemnum}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $elemnum and $self->{"elemnum"} = $elemnum
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
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")
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 489 | $s .= ","; # so output a separator character | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | 57 | ▶ | if ($type eq '#') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 522 | 18 | $self->{record_is_open} = 1; | |||||||||||||||||||||||||||
| 523 | 18 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | defined($recnum) and | ||||||||||||||||||||||||||||
| 526 | $self->{recnum} = $recnum | ||||||||||||||||||||||||||||
| 527 | or | ||||||||||||||||||||||||||||
| 528 | 18 | ▶ | $self->{recnum}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $recnum and $self->{"recnum"} = $recnum
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
| |||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | 18 | ▶ | defined($lineno) or $lineno = '1:'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 531 | # xxxx really? will someone pass that in? | ||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | 18 | ▶ | if ($self->{recnum} == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 554 | $self->{outhandle} and | ||||||||||||||||||||||||||||
| 555 | 18 | ▶ | return (print { $self->{outhandle} } $s) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 587 | 6 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 588 | 6 | $self->{stream_is_open} = 0; | |||||||||||||||||||||||||||
| 589 | $self->{outhandle} and | ||||||||||||||||||||||||||||
| 590 | 6 | ▶ | return (print { $self->{outhandle} } $s) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 648 | 41 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||
| 650 | defined($elemnum) and | ||||||||||||||||||||||||||||
| 651 | $self->{elemnum} = $elemnum | ||||||||||||||||||||||||||||
| 652 | or | ||||||||||||||||||||||||||||
| 653 | 41 | ▶ | $self->{elemnum}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $elemnum and $self->{"elemnum"} = $elemnum
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 658 | 41 | my ($num, $type) = | |||||||||||||||||||||||||||
| 659 | $lineno =~ /^(\d*)\s*(.)/; | ||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | 41 | ▶ | $type eq '#' and $name = '#'; # JSON pseudo-comment! | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 662 | 41 | ▶ | $type eq '#' and $self->{elemnum}--; # doesn't count as elem | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 663 | 41 | ▶ | if (defined $name) { # no element if no name | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$self->{"elemnum"} > 1 or $self->{"verbose"}
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"}
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 687 | 10 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $recnum and $self->{"recnum"} = $recnum
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
| |||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||
| 695 | 10 | ▶ | defined($lineno) or $lineno = '1:'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 696 | # yyy really? will someone pass that in? | ||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||
| 698 | 10 | ▶ | $self->{recnum} > 1 and $s .= ','; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 702 | 10 | $self->{indent} =~ s/$/$self->{indent_step}/; # increase indent | |||||||||||||||||||||||||||
| 703 | $self->{outhandle} and | ||||||||||||||||||||||||||||
| 704 | 10 | ▶ | return (print { $self->{outhandle} } $s) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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"} ||= " "
MC/DC0%0/1
$self->{"indent_step"} ||= " "
$self->{"indent_step"}
Truth table50%1/2
A
A= $self->{"indent_step"}
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 739 | 7 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 783 | 30 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||
| 785 | defined($elemnum) and | ||||||||||||||||||||||||||||
| 786 | $self->{elemnum} = $elemnum | ||||||||||||||||||||||||||||
| 787 | or | ||||||||||||||||||||||||||||
| 788 | 30 | ▶ | $self->{elemnum}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $elemnum and $self->{"elemnum"} = $elemnum
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
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")
| |||||||||||||||||||||||||||||
| 801 | or | ||||||||||||||||||||||||||||
| 802 | $wrapper = \&File::OM::text_nowrap; | ||||||||||||||||||||||||||||
| 803 | ; | ||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||
| 805 | 30 | ▶ | if ($type eq '#') { # Plain pseudo-comment! | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 840 | 8 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $recnum and $self->{"recnum"} = $recnum
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
| |||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||
| 848 | 8 | ▶ | defined($lineno) or $lineno = '1:'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||
| 850 | $self->{verbose} and | ||||||||||||||||||||||||||||
| 851 | 8 | ▶ | $s .= "# from record $recnum, line $lineno\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 852 | $self->{outhandle} and | ||||||||||||||||||||||||||||
| 853 | 8 | ▶ | return (print { $self->{outhandle} } $s) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 887 | 6 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 888 | 6 | $self->{stream_is_open} = 0; | |||||||||||||||||||||||||||
| 889 | $self->{outhandle} and | ||||||||||||||||||||||||||||
| 890 | 6 | ▶ | return (print { $self->{outhandle} } $s) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 923 | 21 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||
| 925 | defined($elemnum) and | ||||||||||||||||||||||||||||
| 926 | $self->{elemnum} = $elemnum | ||||||||||||||||||||||||||||
| 927 | or | ||||||||||||||||||||||||||||
| 928 | 21 | ▶ | $self->{elemnum}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $elemnum and $self->{"elemnum"} = $elemnum
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
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")
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 947 | $s .= "|"; # so output a separator character | ||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||
| 949 | 21 | ▶ | if ($type eq '#') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 980 | 6 | $self->{record_is_open} = 1; | |||||||||||||||||||||||||||
| 981 | 6 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||
| 983 | defined($recnum) and | ||||||||||||||||||||||||||||
| 984 | $self->{recnum} = $recnum | ||||||||||||||||||||||||||||
| 985 | or | ||||||||||||||||||||||||||||
| 986 | 6 | ▶ | $self->{recnum}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $recnum and $self->{"recnum"} = $recnum
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
| |||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||
| 988 | 6 | ▶ | defined($lineno) or $lineno = '1:'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 989 | # xxxx really? will someone pass that in? | ||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||
| 991 | 6 | ▶ | if ($self->{recnum} == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 1012 | $self->{outhandle} and | ||||||||||||||||||||||||||||
| 1013 | 6 | ▶ | return (print { $self->{outhandle} } $s) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 1045 | 2 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1046 | 2 | $self->{stream_is_open} = 0; | |||||||||||||||||||||||||||
| 1047 | $self->{outhandle} and | ||||||||||||||||||||||||||||
| 1048 | 2 | ▶ | return (print { $self->{outhandle} } $s) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC0%0/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table50%1/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 1114 | 65 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1115 | |||||||||||||||||||||||||||||
| 1116 | defined($elemnum) and | ||||||||||||||||||||||||||||
| 1117 | $self->{elemnum} = $elemnum | ||||||||||||||||||||||||||||
| 1118 | or | ||||||||||||||||||||||||||||
| 1119 | 65 | ▶ | $self->{elemnum}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $elemnum and $self->{"elemnum"} = $elemnum
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 1124 | 65 | my ($num, $type) = | |||||||||||||||||||||||||||
| 1125 | $lineno =~ /^(\d*)\s*(.)/; | ||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||
| 1127 | 65 | ▶ | if ($type eq '#') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 1164 | 15 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $recnum and $self->{"recnum"} = $recnum
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
| |||||||||||||||||||||||||||||
| 1171 | |||||||||||||||||||||||||||||
| 1172 | 15 | ▶ | defined($lineno) or $lineno = '1:'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1173 | |||||||||||||||||||||||||||||
| 1174 | $self->{verbose} and | ||||||||||||||||||||||||||||
| 1175 | 15 | ▶ | $s .= "# from record $recnum, line $lineno\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1176 | defined($self->{subject}) or | ||||||||||||||||||||||||||||
| 1177 | 15 | ▶ | $self->{subject} = $self->{turtle_nosubject}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1178 | 15 | $s .= "<$self->{subject}>"; | |||||||||||||||||||||||||||
| 1179 | |||||||||||||||||||||||||||||
| 1180 | $self->{outhandle} and | ||||||||||||||||||||||||||||
| 1181 | 15 | ▶ | return (print { $self->{outhandle} } $s) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 1216 | 13 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1217 | 13 | $self->{stream_is_open} = 0; | |||||||||||||||||||||||||||
| 1218 | $self->{outhandle} and | ||||||||||||||||||||||||||||
| 1219 | 13 | ▶ | return (print { $self->{outhandle} } $s) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 1258 | 56 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1259 | |||||||||||||||||||||||||||||
| 1260 | defined($elemnum) and | ||||||||||||||||||||||||||||
| 1261 | $self->{elemnum} = $elemnum | ||||||||||||||||||||||||||||
| 1262 | or | ||||||||||||||||||||||||||||
| 1263 | 56 | ▶ | $self->{elemnum}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $elemnum and $self->{"elemnum"} = $elemnum
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$self->{"wrap"} and ($wrapper, $Text::Wrap::columns, $Text::Wrap::huge) = (\&Text::Wrap::wrap, $self->{"wrap"}, "overflow")
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")
| |||||||||||||||||||||||||||||
| 1276 | or | ||||||||||||||||||||||||||||
| 1277 | $wrapper = \&File::OM::text_nowrap; | ||||||||||||||||||||||||||||
| 1278 | ; | ||||||||||||||||||||||||||||
| 1279 | |||||||||||||||||||||||||||||
| 1280 | |||||||||||||||||||||||||||||
| 1281 | 56 | ▶ | if ($type eq '#') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 1337 | 17 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $recnum and $self->{"recnum"} = $recnum
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
| |||||||||||||||||||||||||||||
| 1344 | |||||||||||||||||||||||||||||
| 1345 | 17 | ▶ | defined($lineno) or $lineno = '1:'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 1352 | 17 | $s .= "\n"; | |||||||||||||||||||||||||||
| 1353 | $self->{outhandle} and | ||||||||||||||||||||||||||||
| 1354 | 17 | ▶ | return (print { $self->{outhandle} } $s) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 1390 | 14 | ▶ | $self->{outhandle} or $s .= $z; # don't retain print status | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
MC/DC100%1/1
$self->{"outhandle"} and return print({$self->{"outhandle"};} $s)
$self->{"outhandle"}
Truth table100%2/2
A
A= $self->{"outhandle"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 1404 | |||||||||||||||||||||||||||||
| 1405 | 106 | s/&/&/g; | |||||||||||||||||||||||||||
| 1406 | 106 | s/'/'/g; | |||||||||||||||||||||||||||
| 1407 | 106 | s/</</g; | |||||||||||||||||||||||||||
| 1408 | 106 | s/>/>/g; | |||||||||||||||||||||||||||
| 1409 | 106 | s/\\/\\\\/g; | |||||||||||||||||||||||||||
| 1410 | 106 | s/"/\\"/g; | |||||||||||||||||||||||||||
| 1411 | |||||||||||||||||||||||||||||
| 1412 | 106 | return $_; | |||||||||||||||||||||||||||
| 1413 | |||||||||||||||||||||||||||||
| 1414 | # ' & < > (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
| |||||||||||||||||||||||||||||
| 1427 | 5 | $s =~ s/-->/-->/g; | |||||||||||||||||||||||||||
| 1428 | 5 | return $s; | |||||||||||||||||||||||||||
| 1429 | } | ||||||||||||||||||||||||||||
| 1430 | |||||||||||||||||||||||||||||
| 1431 | 61 | 1; | |||||||||||||||||||||||||||
| 1432 | |||||||||||||||||||||||||||||
| 1433 | __END__ | ||||||||||||||||||||||||||||