{"id":15017767,"url":"https://github.com/sysread/toml-tiny","last_synced_at":"2025-04-09T19:42:38.503Z","repository":{"id":39726898,"uuid":"231615298","full_name":"sysread/TOML-Tiny","owner":"sysread","description":"A minimal TOML parser and serializer for perl 5","archived":false,"fork":false,"pushed_at":"2025-03-25T22:53:05.000Z","size":501,"stargazers_count":8,"open_issues_count":4,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-01T20:33:26.240Z","etag":null,"topics":["parser","perl","perl5","toml"],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sysread.png","metadata":{"files":{"readme":"README.pod","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-03T15:31:07.000Z","updated_at":"2025-03-25T22:53:09.000Z","dependencies_parsed_at":"2024-06-03T18:56:51.366Z","dependency_job_id":null,"html_url":"https://github.com/sysread/TOML-Tiny","commit_stats":{"total_commits":159,"total_committers":4,"mean_commits":39.75,"dds":0.03144654088050314,"last_synced_commit":"2cd349168a0d859e3162e82c8fce23b90966161d"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysread%2FTOML-Tiny","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysread%2FTOML-Tiny/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysread%2FTOML-Tiny/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysread%2FTOML-Tiny/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sysread","download_url":"https://codeload.github.com/sysread/TOML-Tiny/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248101186,"owners_count":21047920,"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":["parser","perl","perl5","toml"],"created_at":"2024-09-24T19:50:58.061Z","updated_at":"2025-04-09T19:42:38.491Z","avatar_url":"https://github.com/sysread.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"=pod\n\n=encoding UTF-8\n\n=head1 NAME\n\nTOML::Tiny - a minimal, pure perl TOML parser and serializer\n\n=head1 VERSION\n\nversion 0.20\n\n=head1 SYNOPSIS\n\n  use TOML::Tiny qw(from_toml to_toml);\n\n  binmode STDIN,  ':encoding(UTF-8)';\n  binmode STDOUT, ':encoding(UTF-8)';\n\n  # Decoding TOML\n  my $toml = do{ local $/; \u003cSTDIN\u003e };\n  my ($parsed, $error) = from_toml $toml;\n\n  # Encoding TOML\n  say to_toml({\n    stuff =\u003e {\n      about =\u003e ['other', 'stuff'],\n    },\n  });\n\n  # Object API\n  my $parser = TOML::Tiny-\u003enew;\n  my $data = $parser-\u003edecode($toml);\n  say $parser-\u003eencode($data);\n\n=head1 DESCRIPTION\n\n=for html \u003cp\u003e\n  \u003ca href=\"https://github.com/sysread/TOML-Tiny/actions?query=workflow%3Arun-tests\"\u003e\n    \u003cimg src=\"https://github.com/sysread/TOML-Tiny/workflows/run-tests/badge.svg\" alt=\"Build status\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\nC\u003cTOML::Tiny\u003e implements a pure-perl parser and generator for the\nL\u003cTOML|https://github.com/toml-lang/toml\u003e data format. It conforms to TOML v1.0\n(with a few caveats; see L\u003c/strict\u003e).\n\nC\u003cTOML::Tiny\u003e strives to maintain an interface compatible to the L\u003cTOML\u003e and\nL\u003cTOML::Parser\u003e modules, and could even be used to override C\u003c$TOML::Parser\u003e:\n\n  use TOML;\n  use TOML::Tiny;\n\n  local $TOML::Parser = TOML::Tiny-\u003enew(...);\n  say to_toml(...);\n\n=head1 EXPORTS\n\nC\u003cTOML::Tiny\u003e exports the following to functions for compatibility with the\nL\u003cTOML\u003e module. See L\u003cTOML/FUNCTIONS\u003e.\n\n=head2 from_toml\n\nParses a string of C\u003cTOML\u003e-formatted source and returns the resulting data\nstructure. Any arguments after the first are passed to L\u003cTOML::Tiny::Parser\u003e's\nconstructor.\n\nIf there is a syntax error in the C\u003cTOML\u003e source, C\u003cfrom_toml\u003e will die with\nan explanation which includes the line number of the error.\n\n  my $result = eval{ from_toml($toml_string) };\n\nAlternately, this routine may be called in list context, in which case syntax\nerrors will result in returning two values, C\u003cundef\u003e and an error message.\n\n  my ($result, $error) = from_toml($toml_string);\n\nAdditional arguments may be passed after the toml source string; see L\u003c/new\u003e.\n\n=head3 GOTCHAS\n\n=over\n\n=item Big integers and floats\n\nC\u003cTOML\u003e supports integers and floats larger than what many perls support. When\nC\u003cTOML::Tiny\u003e encounters a value it may not be able to represent as a number,\nit will instead return a L\u003cMath::BigInt\u003e or L\u003cMath::BigFloat\u003e. This behavior\ncan be overridden by providing inflation routines:\n\n  my $toml = TOML::Tiny-\u003enew(\n    inflate_float =\u003e sub{\n      return do_something_else_with_floats( $_[0] );\n    };\n  );\n\n=back\n\n=head2 to_toml\n\nEncodes a hash ref as a C\u003cTOML\u003e-formatted string.\n\n  my $toml = to_toml({foo =\u003e {'bar' =\u003e 'bat'}});\n\n  # [foo]\n  # bar=\"bat\"\n\n=head3 mapping perl to TOML types\n\n=head4 table\n\n=over\n\n=item C\u003cHASH\u003e ref\n\n=back\n\n=head4 array\n\n=over\n\n=item C\u003cARRAY\u003e ref\n\n=back\n\n=head4 boolean\n\n=over\n\n=item C\u003c\\0\u003e or C\u003c\\1\u003e\n\n=item L\u003cJSON::PP::Boolean\u003e\n\n=item L\u003cTypes::Serializer::Boolean\u003e\n\n=back\n\n=head4 numeric types\n\nThese are tricky in perl. When encountering a C\u003cMath::Big[Int|Float]\u003e,\nthat representation is used.\n\nIf the value is a defined (non-ref) scalar with the C\u003cSVf_IOK\u003e or C\u003cSVf_NOK\u003e\nflags set, the value will be emitted unchanged. This is in line with most\nother packages, so the normal hinting hacks for typed output apply:\n\n  number =\u003e 0 + $number,\n  string =\u003e \"\" . $string,\n\n=over\n\n=item L\u003cMath::BigInt\u003e\n\n=item L\u003cMath::BigFloat\u003e\n\n=item numerical scalars\n\n=back\n\n=head4 datetime\n\n=over\n\n=item RFC3339-formatted string\n\ne.g., C\u003c\"1985-04-12T23:20:50.52Z\"\u003e\n\n=item L\u003cDateTime\u003e\n\nL\u003cDateTime\u003es are formatted as C\u003cRFC3339\u003e, as expected by C\u003cTOML\u003e. However,\nC\u003cTOML\u003e supports the concept of a \"local\" time zone, which strays from\nC\u003cRFC3339\u003e by allowing a datetime without a time zone offset. This is\nrepresented in perl by a C\u003cDateTime\u003e with a B\u003cfloating time zone\u003e.\n\n=back\n\n=head4 string\n\nAll other non-ref scalars are treated as strings.\n\n=head1 OBJECT API\n\n=head2 new\n\n=over\n\n=item inflate_datetime\n\nBy default, C\u003cTOML::Tiny\u003e treats TOML datetimes as strings in the generated\ndata structure. The C\u003cinflate_datetime\u003e parameter allows the caller to provide\na routine to intercept those as they are generated:\n\n  use DateTime::Format::RFC3339;\n\n  my $parser = TOML::Tiny-\u003enew(\n    inflate_datetime =\u003e sub{\n      my ($dt_string) = @_;\n      # DateTime::Format::RFC3339 will set the resulting DateTime's formatter\n      # to itself. Fallback is the DateTime default, ISO8601, with a possibly\n      # floating time zone.\n      return eval{ DateTime::Format::RFC3339-\u003eparse_datetime($dt_string) }\n          || DateTime::Format::ISO8601-\u003eparse_datetime($dt_string);\n    },\n  );\n\n=item inflate_boolean\n\nBy default, boolean values in a C\u003cTOML\u003e document result in a C\u003c1\u003e or C\u003c0\u003e.\nIf L\u003cTypes::Serialiser\u003e is installed, they will instead be C\u003cTypes::Serialiser::true\u003e\nor C\u003cTypes::Serialiser::false\u003e.\n\nIf you wish to override this, you can provide your own routine to generate values:\n\n  my $parser = TOML::Tiny-\u003enew(\n    inflate_boolean =\u003e sub{\n      my $bool = shift;\n      if ($bool eq 'true') {\n        return 'The Truth';\n      } else {\n        return 'A Lie';\n      }\n    },\n  );\n\n=item inflate_integer\n\nTOML integers are 64 bit and may not match the size of the compiled perl's\ninternal integer type. By default, C\u003cTOML::Tiny\u003e coerces numbers that fit\nwithin a perl number by adding C\u003c0\u003e. For bignums, a L\u003cMath::BigInt\u003e is\nreturned. This may be overridden by providing an inflation routine:\n\n  my $parser = TOML::Tiny-\u003enew(\n    inflate_integer =\u003e sub{\n      my $parsed = shift;\n      return sprintf 'the number \"%d\"', $parsed;\n    };\n  );\n\n=item inflate_float\n\nTOML floats are 64 bit and may not match the size of the compiled perl's\ninternal float type. As with integers, floats are coerced to numbers and large\nfloats are upgraded to L\u003cMath::BigFloat\u003es. The special strings C\u003cNaN\u003e and\nC\u003cinf\u003e may also be returned. You can override this by specifying an inflation\nroutine.\n\n  my $parser = TOML::Tiny-\u003enew(\n    inflate_float =\u003e sub{\n      my $parsed = shift;\n      return sprintf '\"%0.8f\" is a float', $parsed;\n    };\n  );\n\n=item strict\n\nC\u003cstrict\u003e imposes some miscellaneous strictures on C\u003cTOML\u003e input, such as\ndisallowing trailing commas in inline tables and failing on invalid UTF8 input.\n\nB\u003cNote:\u003e C\u003cstrict\u003e was previously called C\u003cstrict_arrays\u003e. Both are accepted\nfor backward compatibility, although enforcement of homogenous arrays is no\nlonger supported as it has been dropped from the spec.\n\n=back\n\n=head2 decode\n\nDecodes C\u003cTOML\u003e and returns a hash ref. Dies on parse error.\n\n=head2 encode\n\nEncodes a perl hash ref as a C\u003cTOML\u003e-formatted string.\n\n=head2 parse\n\nAlias for C\u003cdecode\u003e to provide compatibility with C\u003cTOML::Parser\u003e when\noverriding the parser by setting C\u003c$TOML::Parser\u003e.\n\n=head1 DIFFERENCES FROM L\u003cTOML\u003e AND L\u003cTOML::Parser\u003e\n\nC\u003cTOML::Tiny\u003e differs in a few significant ways from the L\u003cTOML\u003e module,\nparticularly in adding support for newer C\u003cTOML\u003e features and strictness.\n\nL\u003cTOML\u003e defaults to lax parsing and provides C\u003cstrict_mode\u003e to (slightly)\ntighten things up. C\u003cTOML::Tiny\u003e defaults to (somewhat) stricter parsing,\nenabling some extra strictures with L\u003c/strict\u003e.\n\nC\u003cTOML::Tiny\u003e supports a number of options which do not exist in L\u003cTOML\u003e:\nL\u003c/inflate_integer\u003e, L\u003c/inflate_float\u003e, and L\u003c/strict\u003e.\n\nC\u003cTOML::Tiny\u003e ignores invalid surrogate pairs within basic and multiline\nstrings (L\u003cTOML\u003e may attempt to decode an invalid pair). Additionally, only\nthose character escapes officially supported by TOML are interpreted as such by\nC\u003cTOML::Tiny\u003e.\n\nC\u003cTOML::Tiny\u003e supports stripping initial whitespace and handles lines\nterminating with a backslash correctly in multilne strings:\n\n  # TOML input\n  x=\"\"\"\n  foo\"\"\"\n\n  y=\"\"\"\\\n     how now \\\n       brown \\\n  bureaucrat.\\\n  \"\"\"\n\n  # Perl output\n  {x =\u003e 'foo', y =\u003e 'how now brown bureaucrat.'}\n\nC\u003cTOML::Tiny\u003e includes support for integers specified in binary, octal or hex\nas well as the special float values C\u003cinf\u003e and C\u003cnan\u003e.\n\n=head1 SEE ALSO\n\n=over\n\n=item L\u003cTOML::Tiny::Grammar\u003e\n\nRegexp scraps used by C\u003cTOML::Tiny\u003e to parse TOML source.\n\n=back\n\n=head1 ACKNOWLEDGEMENTS\n\nThanks to L\u003cZipRecruiter|https://www.ziprecruiter.com\u003e for encouraging their\nemployees to contribute back to the open source ecosystem. Without their\ndedication to quality software development this distribution would not exist.\n\nA big thank you to those who have contributed code or bug reports:\n\n=over\n\n=item L\u003cijackson|https://github.com/ijackson\u003e\n\n=item L\u003cnoctux|https://github.com/noctux\u003e\n\n=item L\u003coschwald|https://github.com/oschwald\u003e\n\n=item L\u003cjjatria|https://metacpan.org/author/JJATRIA\u003e\n\n=back\n\n=head1 AUTHOR\n\nJeff Ober \u003csysread@fastmail.fm\u003e\n\n=head1 COPYRIGHT AND LICENSE\n\nThis software is copyright (c) 2025 by Jeff Ober.\n\nThis is free software; you can redistribute it and/or modify it under\nthe same terms as the Perl 5 programming language system itself.\n\n=cut\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsysread%2Ftoml-tiny","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsysread%2Ftoml-tiny","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsysread%2Ftoml-tiny/lists"}