Skip to main content

Module serialize_normalize

Module serialize_normalize 

Source
Expand description

Free-function recursive flatten of stryke ClassInstance / StructInstance values into plain hashref / arrayref trees, for use by serializers (to_json, to_xml, to_yaml, to_toml, to_html, ddump) that take &[PerlValue] and don’t have a &VMHelper to consult.

Inheritance fields (parents declared via extends) are looked up through a thread-local CLASS_DEFS_REGISTRY that the VM populates on entry to execute and on each ClassDecl statement. When the registry is empty (e.g. a serializer is called outside a normal VM run), the helper falls back to the class’s own field definitions only — covers the no-inheritance case correctly.

Functions§

deep_normalize
Recursively convert any ClassInstance / StructInstance / EnumInstance reachable inside v into plain hashrefs (using the field name as the key). Hashrefs and arrayrefs are walked in place; every other value (numbers, strings, undef, code refs, blessed non-hash refs, …) round-trips unchanged.
normalize_args_head
Convenience: normalize the first arg in place and return a Vec the caller can hand to its existing serializer logic. Use when the serializer takes &[PerlValue] and only the first element is the data to serialize.