NAME

DMS::Parser::Emitter - Re-emit a parsed DMS Document as DMS source

SYNOPSIS

use DMS::Parser;
use DMS::Parser::Emitter;

my $doc = DMS::Parser::decode_document($src);

# Full round-trip: preserves comments and original literal forms
my $dms = DMS::Parser::Emitter::encode($doc);

# Lite mode: canonical DMS, no comments, decimal integers, basic-quoted strings
my $canonical = DMS::Parser::Emitter::encode_lite($doc);

DESCRIPTION

DMS::Parser::Emitter converts a parsed DMS Document hashref back into DMS source text. It is the shared emitter used by both DMS::Parser (pure-Perl backend) and DMS::Parser::XS (XS backend) — the Document shape is identical between the two, so the same walker handles both.

Round-trip contract (SPEC §encode)

Full mode (encode):

  • decode(encode(decode(source))) is data-equivalent to decode(source).

  • Comments are re-emitted at the same attached paths.

  • Original literal forms are preserved where recorded in $doc->{original_forms}: integer bases (hex, octal, binary), string forms (literal-quoted, heredocs with modifiers).

  • encode refuses a Document whose body contains a DMS::Parser::UnorderedTable; use encode_lite instead (no order guarantee).

Lite mode (encode_lite):

  • Emits canonical DMS: no comments, decimal integers, basic-quoted strings.

  • decode(encode_lite($doc)) is data-equivalent to $doc; comment and literal-form round-trip is not guaranteed.

  • Accepts DMS::Parser::UnorderedTable (arbitrary key order).

FUNCTIONS

encode($doc)

Re-emit the Document $doc (as returned by decode_document) as a DMS source string. Preserves comments attached to the tree and original literal forms recorded in $doc->{original_forms}. Dies if the body contains a DMS::Parser::UnorderedTable.

encode_lite($doc)

Emit canonical DMS source: no comments, no literal-form preservation. Safe to call on any Document including those with DMS::Parser::UnorderedTable.

to_dms($doc)

Deprecated alias for "encode". Emits a one-time Carp::carp warning and forwards. Will be removed in the next release.

to_dms_lite($doc)

Deprecated alias for "encode_lite". Emits a one-time Carp::carp warning and forwards. Will be removed in the next release.

SEE ALSO

DMS::Parser, DMS::Parser::XS, https://gitlab.com/flo-labs/pub/dms

AUTHOR

Filip Lopes

LICENSE

Dual-licensed under the Apache License 2.0 and the MIT license, at your option.