{"id":17799437,"url":"https://github.com/polettix/yaml-dump","last_synced_at":"2025-07-10T17:32:47.653Z","repository":{"id":56836209,"uuid":"124690470","full_name":"polettix/YAML-Dump","owner":"polettix","description":"Dump stuff, (simplified) YAML style","archived":false,"fork":false,"pushed_at":"2018-04-20T22:51:10.000Z","size":39,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T04:12:35.660Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polettix.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-10T19:14:17.000Z","updated_at":"2023-08-03T20:03:58.000Z","dependencies_parsed_at":"2022-09-07T07:10:34.370Z","dependency_job_id":null,"html_url":"https://github.com/polettix/YAML-Dump","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/polettix/YAML-Dump","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polettix%2FYAML-Dump","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polettix%2FYAML-Dump/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polettix%2FYAML-Dump/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polettix%2FYAML-Dump/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polettix","download_url":"https://codeload.github.com/polettix/YAML-Dump/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polettix%2FYAML-Dump/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264619480,"owners_count":23638460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-27T12:07:18.222Z","updated_at":"2025-07-10T17:32:47.633Z","avatar_url":"https://github.com/polettix.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nYAML::Dump - Dump stuff, (simplified) YAML style\n\n# VERSION\n\nThis document describes YAML::Dump version {{\\[ version \\]}}.\n\n\u003cdiv\u003e\n    \u003ca href=\"https://travis-ci.org/polettix/YAML-Dump\"\u003e\n    \u003cimg alt=\"Build Status\" src=\"https://travis-ci.org/polettix/YAML-Dump.svg?branch=master\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://www.perl.org/\"\u003e\n    \u003cimg alt=\"Perl Version\" src=\"https://img.shields.io/badge/perl-5.10+-brightgreen.svg\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://badge.fury.io/pl/YAML-Dump\"\u003e\n    \u003cimg alt=\"Current CPAN version\" src=\"https://badge.fury.io/pl/YAML-Dump.svg\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://cpants.cpanauthors.org/dist/YAML-Dump\"\u003e\n    \u003cimg alt=\"Kwalitee\" src=\"http://cpants.cpanauthors.org/dist/YAML-Dump.png\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://www.cpantesters.org/distro/B/YAML-Dump.html?distmat=1\"\u003e\n    \u003cimg alt=\"CPAN Testers\" src=\"https://img.shields.io/badge/cpan-testers-blue.svg\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://matrix.cpantesters.org/?dist=YAML-Dump\"\u003e\n    \u003cimg alt=\"CPAN Testers Matrix\" src=\"https://img.shields.io/badge/matrix-@testers-blue.svg\"\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\n# SYNOPSIS\n\n    use YAML::Dump qw\u003c Dump \u003e;\n\n    my $data = { ... };\n    say Dump $data\n\n# DESCRIPTION\n\nThis module allows you to generate a YAML representation of a data\nstructure, provided that:\n\n- there are no circular references\n- there are no objects or \"weird\" references, but see below\n\nIf you recognize most (not all) the constraints of [YAML::Tiny](https://metacpan.org/pod/YAML::Tiny) you are\ntotally right, because most of the code in this module is taken from\nthere. There are two notable differences:\n\n- booleans are supported, see [\"Booleans\"](#booleans)\n- you can provide your way of dumping objects by implementing\n[\"dumper\\_for\\_unknown\"](#dumper_for_unknown), see [\"Unsupported References\"](#unsupported-references).\n\n## Booleans\n\nBooleans are recognized and rendered as either `false` and `true`\n(unquoted), depending on their truthness. The following variants are\nrecognized:\n\n- a reference to a _purely integer_ scalar variable holding values `0` or\n`1`. Dual-lived variables or other values will not work.\n- [JSON::PP::Boolean](https://metacpan.org/pod/JSON::PP::Boolean)\n- [boolean](https://metacpan.org/pod/boolean)\n- [JSON::XS::Boolean](https://metacpan.org/pod/JSON::XS::Boolean)\n- [Types::Serialiaser::Boolean](https://metacpan.org/pod/Types::Serialiaser::Boolean) (although it should not be needed)\n- [Mojo::JSON::\\_Bool](https://metacpan.org/pod/Mojo::JSON::_Bool), for [Mojolicious](https://metacpan.org/pod/Mojolicious) up to version 6.21 (it later\nswitched to [JSON::PP::Boolean](https://metacpan.org/pod/JSON::PP::Boolean)).\n\n## Unsupported References\n\nWhen a reference that is neither a hash nor an array reference is found,\nmethod [\"dumper\\_for\\_objects\"](#dumper_for_objects) is called. This method first tries to figure\nout if the reference is one of the allowed [\"Booleans\"](#booleans) representations,\nthen hands over to a method [\"dumper\\_for\\_unknown\"](#dumper_for_unknown) (if the class has one),\nthen as a last resort it complains loudly `die`ing.\n\nIf you want to provide your own dumping functions, you can either override\n[\"dumper\\_for\\_objects\"](#dumper_for_objects) (losing support for [\"Booleans\"](#booleans)), or provide your\nmethod [\"dumper\\_for\\_unknown\"](#dumper_for_unknown). By default there is none, so you can either\nderive a subclass from YAML::Dump, or monkey-patch it by implementing the\nmethod directly:\n\n    sub YAML::Dump::dumper_for_unknown { \n       my ($self, $element, $line, $indent, $seen) = @_;\n    }\n\n# FUNCTIONS\n\n## **Dump**\n\n    my $string = Dump(@data_structures);\n\ngenerate a YAML representation of `@data_structures`.\n\n## **INDENT**\n\n    my $string = INDENT;\n\nthe indentation as space characters. This is useful if you have to\ngenerate indentation string with [\"dumper\\_for\\_unknown\"](#dumper_for_unknown).\n\n# METHODS\n\n## **dumper\\_for\\_objects**\n\n    my @lines = $obj-\u003edumper_for_objects($element, $line, $indent, $seen);\n\nThis method generates a representation for booleans or, as a fallback,\ncalls [\"dumper\\_for\\_unknown\"](#dumper_for_unknown). If you override this you lose the\npossibility of dumping booleans, you are probably looking for\n[\"dumper\\_for\\_unknown\"](#dumper_for_unknown).\n\n## **dumper\\_for\\_unknown**\n\n    my @stuff = $obj-\u003edumper_for_unknown($element, $line, $indent, $seen);\n\nThis method is not really present, but is invoked if you provide one\n(either in a subclass, or monkey-patching YAML::Dump, see\n[\"Unsupported References\"](#unsupported-references)). This allows you to provide your own\ngenerating functions for your classes, should you need to do this.\n\nThe method is provided the following positional parameters:\n\n- `$element`\n\n    the element to dump in YAML\n\n- `$line`\n\n    the line where the element will be put (starting). It can be one of the\n    following:\n\n    - an empty string, in case the object is at the root level\n    - a string starting with spaces and ending with a dash `-`: your element is\n    part of an array\n    - a string ending with a colon `:`: your element is the value of a hash\n\n    If your dump is just on a single line, it's sufficient to pre-pend the\n    string representation with a space; otherwise, decide what you want to do\n    also taking into consideration `$indent` (see below) and also taking into\n    consideration that it is your responsibility to output the `$line`\n    anyway.\n\n- `$indent`\n\n    The indentation level, should you need it (e.g. for multi-line dumps). To\n    generate the indentation string, use [\"INDENT\"](#indent):\n\n        my $indentation_string = INDENT x $indent;\n\n- `$seen`\n\n    used to track circular references. Use this if your object contains other\n    references with the potential for a cycle of references. This is how you\n    can use it:\n\n        sub dumper_for_unknown {\n           # ...\n\n           my $id = Scalar::Util::refaddr($some_reference);\n           die \\'circular references are unsupported' if $seen-\u003e{$id};\n\n           # ...\n        }\n\nThe return value from this method can be either a list of lines (with the\nproper indentation, and starting with the content of `$line` above) or\na single array or hash reference, which will be transformed automatically.\nThis allows you to basically ignore `$line`, `$indent` (but probably not\n`$seen`) and let YAML::Dump do the work for you.\n\n## **new**\n\n    my $obj = YAML::Dump-\u003enew(@data_for_dumping);\n\nGenerate an object. You should not need to use this, use [\"Dump\"](#dump) instead.\n\n# BUGS AND LIMITATIONS\n\nReport bugs through GitHub (patches welcome).\n\n# SEE ALSO\n\n[YAML::Tiny](https://metacpan.org/pod/YAML::Tiny), where most of the code was taken. But hey! There is also my\nstuff!\n\n# AUTHOR\n\nFlavio Poletti \u003cpolettix@cpan.org\u003e\n\n# COPYRIGHT AND LICENSE\n\nThis is tricky. A good part of the code comes from [YAML::Tiny](https://metacpan.org/pod/YAML::Tiny), whose\ncopyright statement at time of copy is:\n\n    Copyright 2006 - 2013 Adam Kennedy.\n\n    This program is free software; you can redistribute\n    it and/or modify it under the same terms as Perl itself.\n\n    The full text of the license can be found in the LICENSE file included\n    with this module.\n\nNow, _under the same terms as Perl itself_ is in itself a bit ambiguous,\neven though the original LICENSE has this:\n\n    This software is copyright (c) 2006 by Adam Kennedy.\n\n    This is free software; you can redistribute it and/or modify it under\n    the same terms as the Perl 5 programming language system itself.\n\n    Terms of the Perl programming language system itself\n\n    a) the GNU General Public License as published by the Free\n       Software Foundation; either version 1, or (at your option) any\n       later version, or b) the \"Artistic License\"\n\nAgain, it's my understanding that even _the same terms as Perl\n5 programming language system itself_ is a bit ambiguous. Also,\nthe _Artistic License_ is, in itself, ambiguous, which is why\nthe Perl Foundation eventually recommended the _Artistic License 2.0_.\n\nAnyway, a hopefully compatible license can be found in file LICENSE.\n\nAdditions are copyright (C) 2018 by Flavio Poletti \u003cpolettix@cpan.org\u003e\n\nThis program is distributed in the hope that it will be useful, but\nwithout any warranty; without even the implied warranty of\nmerchantability or fitness for a particular purpose.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolettix%2Fyaml-dump","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolettix%2Fyaml-dump","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolettix%2Fyaml-dump/lists"}