| 1 | package DMS::Emitter; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # DMS encode emitter — re-emit a parsed Document as DMS source. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Mirrors the Rust reference (language/rust/crates/dms/src/lib.rs::encode). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Pure Perl; no parser dependency at parse time. Used by both | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # DMS::Parser::encode and DMS::XS::Parser::encode — the document shape | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # is identical between the two backends, so the emitter walks them the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # same way. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Contract (SPEC §encode): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # decode(encode(decode(source))) is data-equivalent to decode(source), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # has the same comments at the same attached paths, and uses the same | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # literal forms for values where preserved (integer base, string form). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # Round-trip stability: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # encode(decode(encode(decode(source)))) is byte-equal to encode(decode(source)). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # SPEC v0.14 renamed to_dms/to_dms_lite to encode/encode_lite. The old | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # names remain as deprecated aliases for one release. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # A Document is a hashref: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # { meta => undef|tied-hash, body => value, comments => [...], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # original_forms => [ [path_aref, lit_href], ... ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use POSIX qw(isnan isinf); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | our $VERSION = '0.5.0'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | my $INDENT_STR = ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # Public entry point. $doc is the decode_document return value. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # SPEC §encode (v0.14): renamed from to_dms() to encode(). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 19 | ▶ | sub encode { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 19 | my ($doc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 19 | return _emit($doc, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Lite-mode entry point — emits canonical DMS source with no comments | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # and no original-form preservation (decimal integers, basic-quoted | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # strings). Mirrors the Rust reference's `encode_lite`. SPEC §encode. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # `decode(encode_lite(doc))` is data-equivalent to `doc`; it is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # *not* required to round-trip comments or literal forms. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub encode_lite { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_lite: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my ($doc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | return _emit($doc, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # Deprecated aliases (SPEC v0.14 renamed to_dms/to_dms_lite to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # encode/encode_lite). Kept for one release. Carp once per process to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # avoid flooding callers that loop. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | { my $warned; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub to_dms { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_dms: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | unless ($warned++) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | Carp::carp( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 'DMS::Emitter::to_dms() is deprecated; use encode() instead. ' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | . 'SPEC v0.14 renamed to_dms() to encode().'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | goto &encode; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | { my $warned; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub to_dms_lite { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_dms_lite: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | unless ($warned++) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | Carp::carp( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 'DMS::Emitter::to_dms_lite() is deprecated; use encode_lite() instead. ' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | . 'SPEC v0.14 renamed to_dms_lite() to encode_lite().'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | goto &encode_lite; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | sub _emit { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit: called CC=17 SCAR=31.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 19 | my ($doc, $lite) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # SPEC §"Unordered tables": full-mode `encode` refuses to round-trip | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # a Document that contains a DMS::UnorderedTable. The Document tree | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # has no stable iteration order, so re-emission cannot be byte-stable. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # Lite mode is allowed (canonical emit, no order promise). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 19 | ▶ | if (!$lite && _contains_unordered($doc->{body})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $lite and _contains_unordered($doc->{"body"})
MC/DC0%0/2
not $lite and _contains_unordered($doc->{"body"})
not $lite
_contains_unordered($doc->{"body"})
Truth table33%1/3
not(A) and B
A= not $liteB= _contains_unordered($doc->{"body"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | die "encode (full-mode round-trip) refuses Document with DMS::UnorderedTable; " | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | . "use decode_document (ordered) or encode_lite. SPEC §Unordered tables.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 19 | ▶ | if (!$lite && defined($doc->{meta}) && _contains_unordered($doc->{meta})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $lite and defined $doc->{"meta"} and _contains_unordered($doc->{"meta"})
not $lite and defined $doc->{"meta"}
MC/DC0%0/3
not $lite and defined $doc->{"meta"} and _contains_unordered($doc->{"meta"})
not $lite
defined $doc->{"meta"}
_contains_unordered($doc->{"meta"})
Truth table50%2/4
not(A) and B and C
A= not $liteB= defined $doc->{"meta"}C= _contains_unordered($doc->{"meta"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | die "encode (full-mode round-trip) refuses Document with DMS::UnorderedTable; " | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | . "use decode_document (ordered) or encode_lite. SPEC §Unordered tables.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 19 | ▶ | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | out => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | comments_by_path => {}, # path-key -> { leading=>[], trailing=>scalar/undef, floating=>[] } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | forms_by_path => {}, # path-key -> $lit | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | lite => $lite ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | doc => $doc, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | }, __PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # In lite mode, the per-path comment + original-form maps stay | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # empty: the walk then emits canonical form even when `doc.comments` | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # / `doc.original_forms` are populated. Mirrors the Rust emitter's | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # `new_lite` constructor. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 19 | ▶ | if (!$self->{lite}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # Bucket comments + original_forms by path-key (joined string). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 19 | ▶ | for my $ac (@{ $doc->{comments} || [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$doc->{'comments'} || []
MC/DC0%0/1
$doc->{'comments'} || []
$doc->{'comments'}
Truth table50%1/2
A
A= $doc->{'comments'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 21 | my $pk = _path_key($ac->{path}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 21 | ▶ | $self->{comments_by_path}{$pk} ||= { leading => [], inner => [], trailing => [], floating => [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"comments_by_path"}{$pk} ||= {"leading", [], "inner", [], "trailing", [], "floating", []}
MC/DC100%1/1
$self->{"comments_by_path"}{$pk} ||= {"leading", [], "inner", [], "trailing", [], "floating", []}
$self->{"comments_by_path"}{$pk}
Truth table100%2/2
A
A= $self->{"comments_by_path"}{$pk}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 21 | my $entry = $self->{comments_by_path}{$pk}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 21 | my $pos = $ac->{position}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 21 | ▶ | if ($pos eq 'leading') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 10 | push @{ $entry->{leading} }, $ac->{comment}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } elsif ($pos eq 'inner') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | push @{ $entry->{inner} }, $ac->{comment}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } elsif ($pos eq 'trailing') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 10 | push @{ $entry->{trailing} }, $ac->{comment}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | push @{ $entry->{floating} }, $ac->{comment}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 19 | ▶ | for my $pair (@{ $doc->{original_forms} || [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$doc->{'original_forms'} || []
MC/DC0%0/1
$doc->{'original_forms'} || []
$doc->{'original_forms'}
Truth table50%1/2
A
A= $doc->{'original_forms'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 7 | my ($p, $lit) = @$pair; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 7 | my $pk = _path_key($p); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 7 | ▶ | $self->{forms_by_path}{$pk} = $lit if !exists $self->{forms_by_path}{$pk}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 19 | $self->_emit_document; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 19 | return $self->{out}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # --- path-key encoding --- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # A path is an arrayref of plain string segments (table keys) and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # DMS::Index objects (list indices). We encode each segment with a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # distinct prefix so the join is unambiguous (a string key "0" doesn't | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # collide with index 0). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 295 | ▶ | sub _path_key { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_path_key: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 295 | my ($p) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | return join("\0", map { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 295 | ▶ | ref($_) eq 'DMS::Index' ? "I:" . $$_ : "K:$_" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } @$p); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 19 | ▶ | sub _emit_document { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_document: called CC=16 SCAR=39.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 19 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 19 | my $doc = $self->{doc}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # Front matter: emit the `+++` block when meta is defined OR when | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # any `__fm__`-prefixed comment exists. Spec §to_dms allows omitting | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # an empty-meta block when no FM comments either, but emitting `+++\n+++\n` | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # for an empty-meta doc with no FM comments would be wrong; the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # has_meta test below guards that. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # Lite mode emits no comments, so FM comments don't force a `+++` | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # block — only an explicit `meta = Some(...)` does. Mirrors the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # Rust reference (lib.rs::emit_document `!self.lite && ...`). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 19 | my $has_fm_comments = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 19 | ▶ | if (!$self->{lite}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 19 | ▶ | for my $ac (@{ $doc->{comments} || [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$doc->{'comments'} || []
MC/DC0%0/1
$doc->{'comments'} || []
$doc->{'comments'}
Truth table50%1/2
A
A= $doc->{'comments'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 21 | my $first = $ac->{path}[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 21 | ▶ | if (defined($first) && !ref($first) && $first eq '__fm__') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $first and not ref $first and $first eq "__fm__"
defined $first and not ref $first
MC/DC0%0/3
defined $first and not ref $first and $first eq "__fm__"
defined $first
not ref $first
$first eq "__fm__"
Truth table25%1/4
A and not(B) and C
A= defined $firstB= not ref $firstC= $first eq "__fm__"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $has_fm_comments = 1; last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 19 | my $fm_present = defined $doc->{meta}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 19 | ▶ | if ($fm_present || $has_fm_comments) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$fm_present or $has_fm_comments
MC/DC50%1/2
$fm_present or $has_fm_comments
$fm_present
$has_fm_comments
Truth table66%2/3
A or B
A= $fm_presentB= $has_fm_comments
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 3 | $self->{out} .= "+++\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 3 | my $fm_path = ['__fm__']; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 3 | ▶ | if (defined $doc->{meta}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 3 | $self->_emit_table_block($doc->{meta}, $fm_path, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $self->_emit_floating($fm_path, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 3 | $self->{out} .= "+++\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 19 | my $body_path = []; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 19 | my $body = $doc->{body}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 19 | ▶ | if (_is_table($body)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 19 | $self->_emit_table_block($body, $body_path, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } elsif (_is_list($body)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $self->_emit_list_block($body, $body_path, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # Scalar root. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my $nc = $self->{comments_by_path}{ _path_key($body_path) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | if ($nc) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | for my $c (@{ $nc->{leading} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $self->_emit_comment_line($c, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $self->_emit_value_inline($body, $body_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $self->_emit_trailing_for($body_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if ($nc) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | for my $c (@{ $nc->{floating} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $self->_emit_comment_line($c, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 83 | ▶ | sub _is_table { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_table: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 83 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 83 | ▶ | return 0 if !defined $v; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # SPEC §"Unordered tables": DMS::UnorderedTable is a blessed hashref | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # marker. Treat it as a table for emission purposes; the full-mode | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # to_dms guard above prevents it from reaching here in round-trip. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 83 | ▶ | if (blessed($v)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 38 | return ref($v) eq 'DMS::UnorderedTable'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 45 | return ref($v) eq 'HASH'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 56 | ▶ | sub _is_list { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_list: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 56 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 56 | ▶ | return 0 if !defined $v; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 56 | ▶ | return 0 if blessed($v); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 18 | return ref($v) eq 'ARRAY'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 28 | ▶ | sub _table_keys { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_table_keys: called CC=3 SCAR=12.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 28 | my ($t) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # Fast path: when the table is a Tie::IxHash, bypass tie magic and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # read the keys AV directly. The tied object is a blessed arrayref | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # `[idx_hv_rv, keys_av_rv, vals_av_rv, iter]` per Tie::IxHash's | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # documented internal shape. `keys %$t` works too but goes through | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # every entry's mg_find — measurably slower on a 5000-pair tree. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 28 | my $tied = tied(%$t); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 28 | ▶ | if ($tied && ref($tied) eq 'Tie::IxHash') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$tied and ref $tied eq "Tie::IxHash"
MC/DC0%0/2
$tied and ref $tied eq "Tie::IxHash"
$tied
ref $tied eq "Tie::IxHash"
Truth table33%1/3
A and B
A= $tiedB= ref $tied eq "Tie::IxHash"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 28 | return @{ $tied->[1] }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # DMS::UnorderedTable (plain blessed hash) or plain HV: arbitrary | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # iteration order is the documented contract for lite mode. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | return keys %$t; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # Recursive walk: returns true if any nested table (or the value itself) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # is a DMS::UnorderedTable. Used by `to_dms` (full mode) to refuse | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # round-trip on unordered Documents per SPEC §"Unordered tables". | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 73 | ▶ | sub _contains_unordered { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_contains_unordered: called CC=11 SCAR=24.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 73 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 73 | ▶ | return 0 if !defined $v; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 73 | ▶ | if (blessed($v)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # DMS::UnorderedTable is itself the marker — we don't need to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # walk into it because finding the outer one is enough; any | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # nested UnorderedTable would still be detected via the body. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 38 | ▶ | return 1 if ref($v) eq 'DMS::UnorderedTable'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # Other blessed sentinels (DMS::Integer, DMS::Bool, dates, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # DMS::Float) are leaves. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 38 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 35 | ▶ | if (ref($v) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 25 | for my $k (keys %$v) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 45 | ▶ | next if $k eq "\0_keys"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 45 | ▶ | return 1 if _contains_unordered($v->{$k}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 25 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 10 | ▶ | if (ref($v) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | for my $item (@$v) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 6 | ▶ | return 1 if _contains_unordered($item); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 8 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 25 | ▶ | sub _emit_table_block { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_table_block: called CC=28 SCAR=51.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 25 | my ($self, $t, $path, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # Lite-mode hot path: no comments, no original_forms, so the per-kvpair | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # path/path-key construction and comment-map lookups are pure overhead. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # Skipping them saves ~35% of emit wall time on a 5000-kvpair Helm | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # chart values.yaml fixture (the path-building inner-array copy plus | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # _path_key string-join was the dominant cost). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 25 | ▶ | if ($self->{lite}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my $pad = $INDENT_STR x $indent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | for my $k (_table_keys($t)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | my $v = $t->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | my $r = ref($v); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # Inline the common scalar cases. The realistic fixture is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # >90% plain-string + a few bool/int values; dispatching to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # _emit_value_inline + _emit_string per kvpair was the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # dominant cost after the path-key skip. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if (!$r) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | my $key_fmt = ($k =~ /\A[A-Za-z_][A-Za-z0-9_-]*\z/) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | ? $k : _format_key($k); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | if ($v !~ /[\\"\x00-\x1F]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $self->{out} .= "${pad}${key_fmt}: \"${v}\"\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $self->{out} .= "${pad}${key_fmt}: \"" . _escape_basic($v) . "\"\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | if ($r eq 'DMS::Bool') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | my $key_fmt = ($k =~ /\A[A-Za-z_][A-Za-z0-9_-]*\z/) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | ? $k : _format_key($k); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | $self->{out} .= $pad . $key_fmt . ': ' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | . ($$v ? "true\n" : "false\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | if ($r eq 'DMS::Integer') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | my $key_fmt = ($k =~ /\A[A-Za-z_][A-Za-z0-9_-]*\z/) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | ? $k : _format_key($k); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | $self->{out} .= "${pad}${key_fmt}: ${$v}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | my $can_block = | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/7
_is_table($v) && scalar _table_keys($v) || _is_list($v) && scalar @$v
_is_table($v) and scalar _table_keys($v)
_is_list($v) and scalar @$v
MC/DC0%0/2
_is_table($v) && scalar _table_keys($v) || _is_list($v) && scalar @$v
_is_table($v)
_is_list($v)
Truth table0%0/3
A || B
A= _is_table($v)B= _is_list($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | (_is_table($v) && scalar(_table_keys($v))) || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | (_is_list($v) && scalar(@$v)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $self->{out} .= $pad; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | $self->{out} .= _format_key($k); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | $self->{out} .= ':'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | if ($can_block) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | if (_is_table($v)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | $self->_emit_table_block($v, undef, $indent + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | $self->_emit_list_block($v, undef, $indent + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | $self->{out} .= ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $self->_emit_value_inline($v, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 25 | for my $k (_table_keys($t)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 45 | my $v = $t->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 45 | my $child_path = [ @$path, $k ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 45 | my $child_pk = _path_key($child_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 45 | my $nc = $self->{comments_by_path}{$child_pk}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 45 | ▶ | if ($nc) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 9 | for my $c (@{ $nc->{leading} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 8 | $self->_emit_comment_line($c, $indent); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 45 | ▶ | my $has_trailing = $nc && @{ $nc->{trailing} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$nc && @{$nc->{'trailing'};}
MC/DC100%2/2
$nc && @{$nc->{'trailing'};}
$nc
@{$nc->{'trailing'};}
Truth table100%3/3
A && B
A= $ncB= @{$nc->{'trailing'};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 45 | my $has_inner = $self->_has_inner($child_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 45 | ▶ | my $can_block = | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%7/7
_is_table($v) && scalar _table_keys($v) || _is_list($v) && scalar @$v
_is_table($v) and scalar _table_keys($v)
_is_list($v) and scalar @$v
MC/DC100%2/2
_is_table($v) && scalar _table_keys($v) || _is_list($v) && scalar @$v
_is_table($v)
_is_list($v)
Truth table100%3/3
A || B
A= _is_table($v)B= _is_list($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | (_is_table($v) && scalar(_table_keys($v))) || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | (_is_list($v) && scalar(@$v)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 45 | ▶ | my $needs_block = $can_block && !($has_trailing && $self->_is_flow_safe($v, $child_path)); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$can_block && !($has_trailing && $self->_is_flow_safe($v, $child_path))
$has_trailing && $self->_is_flow_safe($v, $child_path)
MC/DC33%1/3
$can_block && !($has_trailing && $self->_is_flow_safe($v, $child_path))
$can_block
$has_trailing
$self->_is_flow_safe($v, $child_path)
Truth table50%2/4
A && not(B && C)
A= $can_blockB= $has_trailingC= $self->_is_flow_safe($v, $child_path)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 45 | $self->{out} .= $INDENT_STR x $indent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 45 | $self->{out} .= _format_key($k); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 45 | $self->{out} .= ':'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 45 | ▶ | if ($needs_block) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 5 | ▶ | if ($has_inner) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $self->{out} .= ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | $self->_emit_inner_for($child_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # Trim trailing space left by _emit_inner_for. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $self->{out} =~ s/ \z//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 5 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 5 | ▶ | if (_is_table($v)) { $self->_emit_table_block($v, $child_path, $indent + 1); } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 2 | else { $self->_emit_list_block($v, $child_path, $indent + 1); } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 40 | $self->{out} .= ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 40 | $self->_emit_inner_for($child_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 40 | $self->_emit_value_inline($v, $child_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 40 | $self->_emit_trailing_for($child_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 40 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 25 | $self->_emit_floating($path, $indent); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 2 | ▶ | sub _emit_list_block { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_list_block: called CC=16 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 2 | my ($self, $items, $path, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 2 | ▶ | if ($self->{lite}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | my $pad = $INDENT_STR x $indent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | for (my $i = 0; $i < @$items; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my $v = $items->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | $self->{out} .= $pad; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | $self->{out} .= '+'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | if (_is_table($v) && scalar(_table_keys($v))) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/2
_is_table($v) and scalar _table_keys($v)
MC/DC0%0/1
_is_table($v) and scalar _table_keys($v)
_is_table($v)
Truth table0%0/2
A
A= _is_table($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $self->_emit_table_block($v, undef, $indent + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | ▶ | } elsif (_is_list($v) && scalar(@$v)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
_is_list($v) and scalar @$v
MC/DC0%0/1
_is_list($v) and scalar @$v
_is_list($v)
Truth table0%0/2
A
A= _is_list($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $self->_emit_list_block($v, undef, $indent + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | $self->{out} .= ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $self->_emit_value_inline($v, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 2 | ▶ | for (my $i = 0; $i < @$items; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 6 | my $v = $items->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 6 | my $child_path = [ @$path, DMS::Index->new($i) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 6 | my $child_pk = _path_key($child_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 6 | my $nc = $self->{comments_by_path}{$child_pk}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 6 | ▶ | if ($nc) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | for my $c (@{ $nc->{leading} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | $self->_emit_comment_line($c, $indent); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 6 | $self->{out} .= $INDENT_STR x $indent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 6 | $self->{out} .= '+'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 6 | my $has_inner = $self->_has_inner($child_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 6 | ▶ | if (_is_table($v) && scalar(_table_keys($v))) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
_is_table($v) and scalar _table_keys($v)
MC/DC0%0/1
_is_table($v) and scalar _table_keys($v)
_is_table($v)
Truth table50%1/2
A
A= _is_table($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | if ($has_inner) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $self->{out} .= ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $self->_emit_inner_for($child_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $self->{out} =~ s/ \z//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $self->_emit_trailing_for($child_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | $self->_emit_table_block($v, $child_path, $indent + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | ▶ | } elsif (_is_list($v) && scalar(@$v)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
_is_list($v) and scalar @$v
MC/DC0%0/1
_is_list($v) and scalar @$v
_is_list($v)
Truth table50%1/2
A
A= _is_list($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | if ($has_inner) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | $self->{out} .= ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $self->_emit_inner_for($child_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $self->{out} =~ s/ \z//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | $self->_emit_trailing_for($child_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | $self->_emit_list_block($v, $child_path, $indent + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 6 | $self->{out} .= ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 6 | $self->_emit_inner_for($child_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 6 | $self->_emit_value_inline($v, $child_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 6 | $self->_emit_trailing_for($child_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 6 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 2 | $self->_emit_floating($path, $indent); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 46 | ▶ | sub _emit_value_inline { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_value_inline: called CC=21 SCAR=54.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 46 | my ($self, $v, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 46 | ▶ | if (blessed($v)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 38 | my $cls = ref($v); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | if ($cls eq 'DMS::Bool') { $self->{out} .= $v->value ? 'true' : 'false'; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 38 | elsif ($cls eq 'DMS::Integer') { $self->_emit_integer($v, $path); } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | elsif ($cls eq 'DMS::Float') { $self->_emit_float($v->value); } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | ▶ | elsif ($cls eq 'DMS::OffsetDateTime' | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
$cls eq "DMS::OffsetDateTime" or $cls eq "DMS::LocalDateTime" or $cls eq "DMS::LocalDate" or $cls eq "DMS::LocalTime"
$cls eq "DMS::OffsetDateTime" or $cls eq "DMS::LocalDateTime" or $cls eq "DMS::LocalDate"
$cls eq "DMS::OffsetDateTime" or $cls eq "DMS::LocalDateTime"
MC/DC0%0/4
$cls eq "DMS::OffsetDateTime" or $cls eq "DMS::LocalDateTime" or $cls eq "DMS::LocalDate" or $cls eq "DMS::LocalTime"
$cls eq "DMS::OffsetDateTime"
$cls eq "DMS::LocalDateTime"
$cls eq "DMS::LocalDate"
$cls eq "DMS::LocalTime"
Truth table0%0/5
A or B or C or D
A= $cls eq "DMS::OffsetDateTime"B= $cls eq "DMS::LocalDateTime"C= $cls eq "DMS::LocalDate"D= $cls eq "DMS::LocalTime"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | || $cls eq 'DMS::LocalDateTime' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | || $cls eq 'DMS::LocalDate' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | || $cls eq 'DMS::LocalTime') { $self->{out} .= $v->value; } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | else { die "to_dms: unknown blessed class $cls"; } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 38 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 8 | ▶ | if (_is_list($v)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | if (!@$v) { $self->{out} .= '[]'; return; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | $self->{out} .= '['; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | my $lite = $self->{lite}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | for (my $i = 0; $i < @$v; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | $self->{out} .= ', ' if $i > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | my $sub = $lite ? undef : [ @$path, DMS::Index->new($i) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | $self->_emit_value_inline($v->[$i], $sub); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | $self->{out} .= ']'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 8 | ▶ | if (_is_table($v)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | my @keys = _table_keys($v); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | if (!@keys) { $self->{out} .= '{}'; return; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | $self->{out} .= '{'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | my $first = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | my $lite = $self->{lite}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | for my $k (@keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | $self->{out} .= ', ' unless $first; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | $first = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | $self->{out} .= _format_key($k); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | $self->{out} .= ': '; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | my $sub = $lite ? undef : [ @$path, $k ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | $self->_emit_value_inline($v->{$k}, $sub); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | $self->{out} .= '}'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | # Plain scalar = string. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | if (!defined $v) { die "to_dms: got undef value"; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 8 | $self->_emit_string("$v", $path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 38 | ▶ | sub _emit_integer { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_integer: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 38 | my ($self, $iv, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 38 | ▶ | if ($self->{lite}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | # DMS::Integer is `bless \$v, 'DMS::Integer'` where $v is an IV. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | # Direct deref + string concat skips the bstr() method dispatch. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | $self->{out} .= "${$iv}"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 38 | my $lit_ref = $self->{forms_by_path}{ _path_key($path) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 38 | ▶ | if ($lit_ref && exists $lit_ref->{integer_lit}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$lit_ref and exists $lit_ref->{"integer_lit"}
MC/DC50%1/2
$lit_ref and exists $lit_ref->{"integer_lit"}
$lit_ref
exists $lit_ref->{"integer_lit"}
Truth table66%2/3
A and B
A= $lit_refB= exists $lit_ref->{"integer_lit"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 5 | $self->{out} .= $lit_ref->{integer_lit}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | # Default: canonical decimal. DMS::Integer's bstr stringifies the IV. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 33 | $self->{out} .= $iv->bstr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | sub _emit_float { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_float: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | my ($self, $f) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | if (isnan($f)) { $self->{out} .= 'nan'; return; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | if (isinf($f)) { $self->{out} .= ($f > 0 ? 'inf' : '-inf'); return; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | # ryu-shortest equivalent: try increasing %.Ng until round-trip works. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | for my $p (1..17) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | my $s = sprintf("%.${p}g", $f); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | if (0 + $s == $f) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | $s =~ s/e\+/e/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | $s =~ s/e-0+(\d)/e-$1/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | $s =~ s/e0+(\d)/e$1/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | ▶ | if ($s !~ /[.eE]/) { $s .= '.0'; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | $self->{out} .= $s; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | $self->{out} .= sprintf("%.17g", $f); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 8 | ▶ | sub _emit_string { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_string: called CC=13 SCAR=29.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 8 | my ($self, $s, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 8 | ▶ | if ($self->{lite}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | $self->{out} .= '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | $self->{out} .= _escape_basic($s); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | $self->{out} .= '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 8 | my $lit_ref = $self->{forms_by_path}{ _path_key($path) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 8 | my $form; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 8 | ▶ | if ($lit_ref && exists $lit_ref->{string_form}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$lit_ref and exists $lit_ref->{"string_form"}
MC/DC50%1/2
$lit_ref and exists $lit_ref->{"string_form"}
$lit_ref
exists $lit_ref->{"string_form"}
Truth table66%2/3
A and B
A= $lit_refB= exists $lit_ref->{"string_form"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 2 | $form = $lit_ref->{string_form}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 8 | ▶ | if (!$form || $form->{kind} eq 'basic') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $form or $form->{"kind"} eq "basic"
MC/DC50%1/2
not $form or $form->{"kind"} eq "basic"
not $form
$form->{"kind"} eq "basic"
Truth table66%2/3
not(A) or B
A= not $formB= $form->{"kind"} eq "basic"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 6 | $self->{out} .= '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 6 | $self->{out} .= _escape_basic($s); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 6 | $self->{out} .= '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 2 | ▶ | if ($form->{kind} eq 'literal') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 1 | $self->{out} .= "'"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 1 | $self->{out} .= $s; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 1 | $self->{out} .= "'"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 1 | ▶ | if ($form->{kind} eq 'heredoc') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | # The stored body is post-modifier. For idempotent modifiers this | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | # is fine, but `_fold_paragraphs` joins lines within a paragraph | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | # with spaces — so we pre-expand each `\n` to `\n\n` so the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | # re-applied modifier preserves line boundaries on round-trip. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 1 | my $body = $s; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 1 | my $has_fold = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 1 | ▶ | for my $m (@{ $form->{modifiers} || [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$form->{'modifiers'} || []
MC/DC0%0/1
$form->{'modifiers'} || []
$form->{'modifiers'}
Truth table50%1/2
A
A= $form->{'modifiers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | if ($m->{name} eq '_fold_paragraphs') { $has_fold = 1; last; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 1 | ▶ | if ($has_fold) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | $body =~ s/\n/\n\n/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 1 | ▶ | $self->_emit_heredoc($body, $form->{flavor}, $form->{label}, $form->{modifiers} || []); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$form->{'modifiers'} || []
MC/DC0%0/1
$form->{'modifiers'} || []
$form->{'modifiers'}
Truth table50%1/2
A
A= $form->{'modifiers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | die "to_dms: unknown string form: $form->{kind}"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 1 | ▶ | sub _emit_heredoc { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_heredoc: called CC=15 SCAR=37.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 1 | my ($self, $body, $flavor, $label, $modifiers) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | # Compute the kvpair's indent from the most recent newline in $self->{out}. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 1 | my $bytes = $self->{out}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 1 | my $last_nl = rindex($bytes, "\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 1 | ▶ | my $line_start = $last_nl < 0 ? 0 : $last_nl + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 1 | my $kv_indent_spaces = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 1 | ▶ | while ($line_start + $kv_indent_spaces < length($bytes) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$line_start + $kv_indent_spaces < length $bytes and substr($bytes, $line_start + $kv_indent_spaces, 1) eq " "
MC/DC0%0/2
$line_start + $kv_indent_spaces < length $bytes and substr($bytes, $line_start + $kv_indent_spaces, 1) eq " "
$line_start + $kv_indent_spaces < length $bytes
substr($bytes, $line_start + $kv_indent_spaces, 1) eq " "
Truth table33%1/3
A and B
A= $line_start + $kv_indent_spaces < length $bytesB= substr($bytes, $line_start + $kv_indent_spaces, 1) eq " "
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | && substr($bytes, $line_start + $kv_indent_spaces, 1) eq ' ') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | $kv_indent_spaces++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 1 | my $body_indent_str = ' ' x ($kv_indent_spaces + length($INDENT_STR)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 1 | my $term_indent_str = $body_indent_str; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 1 | ▶ | my $opener = ($flavor eq 'basic_triple') ? '"""' : "'''"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 1 | $self->{out} .= $opener; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 1 | ▶ | $self->{out} .= $label if defined $label; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 1 | for my $m (@$modifiers) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | $self->{out} .= ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | $self->{out} .= $m->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | $self->{out} .= '('; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | my $first = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | ▶ | for my $a (@{ $m->{args} || [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$m->{'args'} || []
MC/DC0%0/1
$m->{'args'} || []
$m->{'args'}
Truth table0%0/2
A
A= $m->{'args'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | ▶ | $self->{out} .= ', ' unless $first; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | $first = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | $self->_emit_modifier_arg($a); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | $self->{out} .= ')'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 1 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 1 | ▶ | if (length($body) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | # nothing — terminator on its own line follows | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 1 | for my $line (split /\n/, $body, -1) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 1 | ▶ | if (length($line) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 1 | $self->{out} .= $body_indent_str; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 1 | $self->{out} .= $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 1 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 1 | $self->{out} .= $term_indent_str; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 1 | ▶ | if (defined $label) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 1 | $self->{out} .= $label; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | $self->{out} .= ($flavor eq 'basic_triple') ? '"""' : "'''"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | ▶ | sub _emit_modifier_arg { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_modifier_arg: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | my ($self, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | ▶ | if (blessed($v)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | my $cls = ref($v); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | if ($cls eq 'DMS::Bool') { $self->{out} .= $v->value ? 'true' : 'false'; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | elsif ($cls eq 'DMS::Integer') { $self->{out} .= $v->bstr; } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | elsif ($cls eq 'DMS::Float') { $self->_emit_float($v->value); } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | ▶ | elsif ($cls eq 'DMS::OffsetDateTime' | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
$cls eq "DMS::OffsetDateTime" or $cls eq "DMS::LocalDateTime" or $cls eq "DMS::LocalDate" or $cls eq "DMS::LocalTime"
$cls eq "DMS::OffsetDateTime" or $cls eq "DMS::LocalDateTime" or $cls eq "DMS::LocalDate"
$cls eq "DMS::OffsetDateTime" or $cls eq "DMS::LocalDateTime"
MC/DC0%0/4
$cls eq "DMS::OffsetDateTime" or $cls eq "DMS::LocalDateTime" or $cls eq "DMS::LocalDate" or $cls eq "DMS::LocalTime"
$cls eq "DMS::OffsetDateTime"
$cls eq "DMS::LocalDateTime"
$cls eq "DMS::LocalDate"
$cls eq "DMS::LocalTime"
Truth table0%0/5
A or B or C or D
A= $cls eq "DMS::OffsetDateTime"B= $cls eq "DMS::LocalDateTime"C= $cls eq "DMS::LocalDate"D= $cls eq "DMS::LocalTime"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | || $cls eq 'DMS::LocalDateTime' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | || $cls eq 'DMS::LocalDate' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | || $cls eq 'DMS::LocalTime') { $self->{out} .= $v->value; } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | else { die "modifier arg: unknown blessed class $cls"; } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | ▶ | if (_is_list($v)) { $self->{out} .= '[]'; return; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | if (_is_table($v)) { $self->{out} .= '{}'; return; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | # Plain scalar = string. Modifier args use basic-quoted always. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | $self->{out} .= '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | $self->{out} .= _escape_basic("$v"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | $self->{out} .= '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 9 | ▶ | sub _emit_comment_line { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_comment_line: called CC=4 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 9 | my ($self, $c, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 9 | my $text = $c->{content}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 9 | my $prefix = $INDENT_STR x $indent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 9 | ▶ | if (index($text, "\n") < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 9 | $self->{out} .= $prefix; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 9 | $self->{out} .= $text; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 9 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 9 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | # Multi-line: only the first line gets re-indented; subsequent body | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | # lines keep their original whitespace verbatim. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | my @lines = split /\n/, $text, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | ▶ | for (my $i = 0; $i < @lines; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | ▶ | if ($i == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | $self->{out} .= $prefix; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | $self->{out} .= $lines[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | $self->{out} .= $lines[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | $self->{out} .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 46 | ▶ | sub _emit_trailing_for { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_trailing_for: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 46 | my ($self, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 46 | ▶ | return if $self->{lite}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 46 | my $nc = $self->{comments_by_path}{ _path_key($path) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 46 | ▶ | return if !$nc || !@{ $nc->{trailing} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$nc and @{$nc->{"trailing"};}
MC/DC50%1/2
$nc and @{$nc->{"trailing"};}
$nc
@{$nc->{"trailing"};}
Truth table66%2/3
A and B
A= $ncB= @{$nc->{"trailing"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 8 | my $first = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 8 | for my $c (@{ $nc->{trailing} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 8 | ▶ | $self->{out} .= ($first ? ' ' : ' '); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 8 | $first = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 8 | $self->{out} .= $c->{content}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 46 | ▶ | sub _emit_inner_for { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_inner_for: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 46 | my ($self, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 46 | ▶ | return if $self->{lite}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 46 | my $nc = $self->{comments_by_path}{ _path_key($path) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 46 | ▶ | return if !$nc; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 8 | for my $c (@{ $nc->{inner} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | $self->{out} .= $c->{content}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | $self->{out} .= ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 51 | ▶ | sub _has_inner { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_has_inner: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 51 | my ($self, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 51 | ▶ | return 0 if $self->{lite}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 51 | my $nc = $self->{comments_by_path}{ _path_key($path) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 51 | ▶ | return $nc && @{ $nc->{inner} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$nc && @{$nc->{'inner'};}
MC/DC0%0/2
$nc && @{$nc->{'inner'};}
$nc
@{$nc->{'inner'};}
Truth table66%2/3
A && B
A= $ncB= @{$nc->{'inner'};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 27 | ▶ | sub _emit_floating { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_floating: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 27 | my ($self, $path, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 27 | ▶ | return if $self->{lite}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 27 | my $nc = $self->{comments_by_path}{ _path_key($path) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 27 | ▶ | return if !$nc; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 1 | for my $c (@{ $nc->{floating} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 1 | $self->_emit_comment_line($c, $indent); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | # Returns true if $v rooted at $path is safe to emit as a flow form: no | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | # heredoc strings (heredocs need their own line) and no descendant has | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | # an attached comment (flow has nowhere to put it). Used to decide | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | # flow-vs-block when a trailing comment forces flow form. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | ▶ | sub _is_flow_safe { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_flow_safe: not called CC=20 SCAR=60.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | my ($self, $v, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | my $pk_prefix = _path_key($path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | # Any descendant comment ⇒ unsafe. Skipped in lite mode (no | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | # comments are emitted anyway). Mirrors Rust lib.rs::is_flow_safe. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | ▶ | if (!$self->{lite}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | ▶ | for my $ac (@{ $self->{doc}{comments} || [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'doc'}{'comments'} || []
MC/DC0%0/1
$self->{'doc'}{'comments'} || []
$self->{'doc'}{'comments'}
Truth table0%0/2
A
A= $self->{'doc'}{'comments'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | ▶ | next if scalar(@{ $ac->{path} }) <= scalar(@$path); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | my $apk = _path_key($ac->{path}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | ▶ | my $prefix = $pk_prefix eq '' ? '' : "$pk_prefix\0"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | ▶ | if ($pk_prefix eq '') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | # any non-empty path is descendant of root | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | } elsif (substr($apk, 0, length($prefix)) eq $prefix) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | ▶ | if (!ref($v) && !blessed($v)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $v or builtin::blessed($v)
MC/DC0%0/2
ref $v or builtin::blessed($v)
ref $v
builtin::blessed($v)
Truth table0%0/3
A or B
A= ref $vB= builtin::blessed($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | # plain string: check heredoc form | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | my $lit = $self->{forms_by_path}{ _path_key($path) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | ▶ | if ($lit && exists $lit->{string_form} && $lit->{string_form}{kind} eq 'heredoc') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$lit and exists $lit->{"string_form"} and $lit->{"string_form"}{"kind"} eq "heredoc"
$lit and exists $lit->{"string_form"}
MC/DC0%0/3
$lit and exists $lit->{"string_form"} and $lit->{"string_form"}{"kind"} eq "heredoc"
$lit
exists $lit->{"string_form"}
$lit->{"string_form"}{"kind"} eq "heredoc"
Truth table0%0/4
A and B and C
A= $litB= exists $lit->{"string_form"}C= $lit->{"string_form"}{"kind"} eq "heredoc"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | ▶ | if (blessed($v)) { return 1; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | ▶ | if (_is_list($v)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | ▶ | for (my $i = 0; $i < @$v; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | my $sub = [ @$path, DMS::Index->new($i) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | ▶ | return 0 if !$self->_is_flow_safe($v->[$i], $sub); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | ▶ | if (_is_table($v)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | for my $k (_table_keys($v)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | my $sub = [ @$path, $k ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | ▶ | return 0 if !$self->_is_flow_safe($v->{$k}, $sub); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 6 | ▶ | sub _escape_basic { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_escape_basic: called CC=11 SCAR=46.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 6 | my ($s) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | # Fast path: most strings need no escaping. Skip the per-char split | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | # if the string contains no `\`, no `"`, and no control chars. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 6 | ▶ | return $s if $s !~ /[\\"\x00-\x1F]/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | for my $ch (split //, $s) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | my $code = ord($ch); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | ▶ | if ($ch eq '\\') { $out .= '\\\\'; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | elsif ($ch eq '"') { $out .= '\\"'; } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | elsif ($ch eq "\n") { $out .= '\\n'; } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | elsif ($ch eq "\r") { $out .= '\\r'; } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | elsif ($ch eq "\t") { $out .= '\\t'; } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | elsif ($ch eq "\b") { $out .= '\\b'; } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | elsif ($ch eq "\f") { $out .= '\\f'; } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | elsif ($code < 0x20) { $out .= sprintf('\\u%04X', $code); } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 0 | else { $out .= $ch; } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | ▶ | sub _is_bare_key_char_emit { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_bare_key_char_emit: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | my ($c) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | ▶ | return 1 if $c eq '_' || $c eq '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$c eq "_" or $c eq "-"
MC/DC0%0/2
$c eq "_" or $c eq "-"
$c eq "_"
$c eq "-"
Truth table0%0/3
A or B
A= $c eq "_"B= $c eq "-"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | my $o = ord($c); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | ▶ | if ($o < 128) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | return $c =~ /[A-Za-z0-9]/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | # Match the parser's frozen Unicode 15.1 XID_Continue snapshot so that | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | # to_dms emits a key bare iff the parser would accept it bare. Avoids | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | # producing surface forms that drift with the host's Unicode tables. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | require DMS::Parser; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 0 | return DMS::Parser::_is_xid_continue($o); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 45 | ▶ | sub _format_key { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_format_key: called CC=9 SCAR=42.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 45 | my ($k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | # ASCII fast path. Real-world keys are >99% plain ASCII identifiers; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | # the regex bails out at the first non-bare char without splitting | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | # the string into single-char SVs. Saves per-key allocations. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 45 | ▶ | return $k if $k =~ /\A[A-Za-z_][A-Za-z0-9_-]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | ▶ | if (length($k) > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | my $bare = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | for my $ch (split //, $k) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | ▶ | if (!_is_bare_key_char_emit($ch)) { $bare = 0; last; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | ▶ | return $k if $bare; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | # Quoted: prefer literal if no single quote, no LF/CR. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | ▶ | if (index($k, "'") < 0 && index($k, "\n") < 0 && index($k, "\r") < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
index($k, "'") == -1 and index($k, "\n") == -1 and index($k, "\r") == -1
index($k, "'") == -1 and index($k, "\n") == -1
MC/DC0%0/3
index($k, "'") == -1 and index($k, "\n") == -1 and index($k, "\r") == -1
index($k, "'") == -1
index($k, "\n") == -1
index($k, "\r") == -1
Truth table0%0/4
A and B and C
A= index($k, "'") == -1B= index($k, "\n") == -1C= index($k, "\r") == -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | return "'$k'"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | return '"' . _escape_basic($k) . '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||