.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "YAML::Tiny 3pm" .TH YAML::Tiny 3pm "2018-03-10" "perl v5.26.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" YAML::Tiny \- Read/Write YAML files with as little code as possible .SH "VERSION" .IX Header "VERSION" version 1.73 .SH "PREAMBLE" .IX Header "PREAMBLE" The \s-1YAML\s0 specification is huge. Really, \fBreally\fR huge. It contains all the functionality of \s-1XML,\s0 except with flexibility and choice, which makes it easier to read, but with a formal specification that is more complex than \&\s-1XML.\s0 .PP The original pure-Perl implementation \s-1YAML\s0 costs just over 4 megabytes of memory to load. Just like with Windows \fI.ini\fR files (3 meg to load) and \&\s-1CSS\s0 (3.5 meg to load) the situation is just asking for a \fBYAML::Tiny\fR module, an incomplete but correct and usable subset of the functionality, in as little code as possible. .PP Like the other \f(CW\*(C`::Tiny\*(C'\fR modules, YAML::Tiny has no non-core dependencies, does not require a compiler to install, is back-compatible to Perl v5.8.1, and can be inlined into other modules if needed. .PP In exchange for this adding this extreme flexibility, it provides support for only a limited subset of \s-1YAML.\s0 But the subset supported contains most of the features for the more common uses of \s-1YAML.\s0 .SH "SYNOPSIS" .IX Header "SYNOPSIS" Assuming \fIfile.yml\fR like this: .PP .Vb 7 \& \-\-\- \& rootproperty: blah \& section: \& one: two \& three: four \& Foo: Bar \& empty: ~ .Ve .PP Read and write \fIfile.yml\fR like this: .PP .Vb 1 \& use YAML::Tiny; \& \& # Open the config \& my $yaml = YAML::Tiny\->read( \*(Aqfile.yml\*(Aq ); \& \& # Get a reference to the first document \& my $config = $yaml\->[0]; \& \& # Or read properties directly \& my $root = $yaml\->[0]\->{rootproperty}; \& my $one = $yaml\->[0]\->{section}\->{one}; \& my $Foo = $yaml\->[0]\->{section}\->{Foo}; \& \& # Change data directly \& $yaml\->[0]\->{newsection} = { this => \*(Aqthat\*(Aq }; # Add a section \& $yaml\->[0]\->{section}\->{Foo} = \*(AqNot Bar!\*(Aq; # Change a value \& delete $yaml\->[0]\->{section}; # Delete a value \& \& # Save the document back to the file \& $yaml\->write( \*(Aqfile.yml\*(Aq ); .Ve .PP To create a new \s-1YAML\s0 file from scratch: .PP .Vb 2 \& # Create a new object with a single hashref document \& my $yaml = YAML::Tiny\->new( { wibble => "wobble" } ); \& \& # Add an arrayref document \& push @$yaml, [ \*(Aqfoo\*(Aq, \*(Aqbar\*(Aq, \*(Aqbaz\*(Aq ]; \& \& # Save both documents to a file \& $yaml\->write( \*(Aqdata.yml\*(Aq ); .Ve .PP Then \fIdata.yml\fR will contain: .PP .Vb 6 \& \-\-\- \& wibble: wobble \& \-\-\- \& \- foo \& \- bar \& \- baz .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\fBYAML::Tiny\fR is a perl class for reading and writing YAML-style files, written with as little code as possible, reducing load time and memory overhead. .PP Most of the time it is accepted that Perl applications use a lot of memory and modules. The \fB::Tiny\fR family of modules is specifically intended to provide an ultralight and zero-dependency alternative to many more-thorough standard modules. .PP This module is primarily for reading human-written files (like simple config files) and generating very simple human-readable files. Note that I said \fBhuman-readable\fR and not \fBgeek-readable\fR. The sort of files that your average manager or secretary should be able to look at and make sense of. .PP YAML::Tiny does not generate comments, it won't necessarily preserve the order of your hashes, and it will normalise if reading in and writing out again. .PP It only supports a very basic subset of the full \s-1YAML\s0 specification. .PP Usage is targeted at files like Perl's \s-1META\s0.yml, for which a small and easily-embeddable module is extremely attractive. .PP Features will only be added if they are human readable, and can be written in a few lines of code. Please don't be offended if your request is refused. Someone has to draw the line, and for YAML::Tiny that someone is me. .PP If you need something with more power move up to \s-1YAML\s0 (7 megabytes of memory overhead) or \s-1YAML::XS\s0 (6 megabytes memory overhead and requires a C compiler). .PP To restate, YAML::Tiny does \fBnot\fR preserve your comments, whitespace, or the order of your \s-1YAML\s0 data. But it should round-trip from Perl structure to file and back again just fine. .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" The constructor \f(CW\*(C`new\*(C'\fR creates a \f(CW\*(C`YAML::Tiny\*(C'\fR object as a blessed array reference. Any arguments provided are taken as separate documents to be serialized. .ie n .SS "read $filename" .el .SS "read \f(CW$filename\fP" .IX Subsection "read $filename" The \f(CW\*(C`read\*(C'\fR constructor reads a \s-1YAML\s0 file from a file name, and returns a new \f(CW\*(C`YAML::Tiny\*(C'\fR object containing the parsed content. .PP Returns the object on success or throws an error on failure. .ie n .SS "read_string $string;" .el .SS "read_string \f(CW$string\fP;" .IX Subsection "read_string $string;" The \f(CW\*(C`read_string\*(C'\fR constructor reads \s-1YAML\s0 data from a character string, and returns a new \f(CW\*(C`YAML::Tiny\*(C'\fR object containing the parsed content. If you have read the string from a file yourself, be sure that you have correctly decoded it into characters first. .PP Returns the object on success or throws an error on failure. .ie n .SS "write $filename" .el .SS "write \f(CW$filename\fP" .IX Subsection "write $filename" The \f(CW\*(C`write\*(C'\fR method generates the file content for the properties, and writes it to disk using \s-1UTF\-8\s0 encoding to the filename specified. .PP Returns true on success or throws an error on failure. .SS "write_string" .IX Subsection "write_string" Generates the file content for the object and returns it as a character string. This may contain non-ASCII characters and should be encoded before writing it to a file. .PP Returns true on success or throws an error on failure. .SS "errstr (\s-1DEPRECATED\s0)" .IX Subsection "errstr (DEPRECATED)" Prior to version 1.57, some errors were fatal and others were available only via the \f(CW$YAML::Tiny::errstr\fR variable, which could be accessed via the \&\f(CW\*(C`errstr()\*(C'\fR method. .PP Starting with version 1.57, all errors are fatal and throw exceptions. .PP The \f(CW$errstr\fR variable is still set when exceptions are thrown, but \&\f(CW$errstr\fR and the \f(CW\*(C`errstr()\*(C'\fR method are deprecated and may be removed in a future release. The first use of \f(CW\*(C`errstr()\*(C'\fR will issue a deprecation warning. .SH "FUNCTIONS" .IX Header "FUNCTIONS" YAML::Tiny implements a number of functions to add compatibility with the \s-1YAML\s0 \s-1API.\s0 These should be a drop-in replacement. .SS "Dump" .IX Subsection "Dump" .Vb 1 \& my $string = Dump(list\-of\-Perl\-data\-structures); .Ve .PP Turn Perl data into \s-1YAML.\s0 This function works very much like \&\fIData::Dumper::Dumper()\fR. .PP It takes a list of Perl data structures and dumps them into a serialized form. .PP It returns a character string containing the \s-1YAML\s0 stream. Be sure to encode it as \s-1UTF\-8\s0 before serializing to a file or socket. .PP The structures can be references or plain scalars. .PP Dies on any error. .SS "Load" .IX Subsection "Load" .Vb 1 \& my @data_structures = Load(string\-containing\-a\-YAML\-stream); .Ve .PP Turn \s-1YAML\s0 into Perl data. This is the opposite of Dump. .PP Just like Storable's \fIthaw()\fR function or the \fIeval()\fR function in relation to Data::Dumper. .PP It parses a character string containing a valid \s-1YAML\s0 stream into a list of Perl data structures representing the individual \s-1YAML\s0 documents. Be sure to decode the character string correctly if the string came from a file or socket. .PP .Vb 1 \& my $last_data_structure = Load(string\-containing\-a\-YAML\-stream); .Ve .PP For consistency with \s-1YAML\s0.pm, when Load is called in scalar context, it returns the data structure corresponding to the last of the \s-1YAML\s0 documents found in the input stream. .PP Dies on any error. .SS "\fIfreeze()\fP and \fIthaw()\fP" .IX Subsection "freeze() and thaw()" Aliases to \fIDump()\fR and \fILoad()\fR for Storable fans. This will also allow YAML::Tiny to be plugged directly into modules like \s-1POE\s0.pm, that use the freeze/thaw \s-1API\s0 for internal serialization. .SS "DumpFile(filepath, list)" .IX Subsection "DumpFile(filepath, list)" Writes the \s-1YAML\s0 stream to a file with \s-1UTF\-8\s0 encoding instead of just returning a string. .PP Dies on any error. .SS "LoadFile(filepath)" .IX Subsection "LoadFile(filepath)" Reads the \s-1YAML\s0 stream from a \s-1UTF\-8\s0 encoded file instead of a string. .PP Dies on any error. .SH "YAML TINY SPECIFICATION" .IX Header "YAML TINY SPECIFICATION" This section of the documentation provides a specification for \*(L"\s-1YAML\s0 Tiny\*(R", a subset of the \s-1YAML\s0 specification. .PP It is based on and described comparatively to the \s-1YAML 1.1\s0 Working Draft 2004\-12\-28 specification, located at . .PP Terminology and chapter numbers are based on that specification. .SS "1. Introduction and Goals" .IX Subsection "1. Introduction and Goals" The purpose of the \s-1YAML\s0 Tiny specification is to describe a useful subset of the \s-1YAML\s0 specification that can be used for typical document-oriented use cases such as configuration files and simple data structure dumps. .PP Many specification elements that add flexibility or extensibility are intentionally removed, as is support for complex data structures, class and object-orientation. .PP In general, the \s-1YAML\s0 Tiny language targets only those data structures available in \s-1JSON,\s0 with the additional limitation that only simple keys are supported. .PP As a result, all possible \s-1YAML\s0 Tiny documents should be able to be transformed into an equivalent \s-1JSON\s0 document, although the reverse is not necessarily true (but will be true in simple cases). .PP As a result of these simplifications the \s-1YAML\s0 Tiny specification should be implementable in a (relatively) small amount of code in any language that supports Perl Compatible Regular Expressions (\s-1PCRE\s0). .SS "2. Introduction" .IX Subsection "2. Introduction" \&\s-1YAML\s0 Tiny supports three data structures. These are scalars (in a variety of forms), block-form sequences and block-form mappings. Flow-style sequences and mappings are not supported, with some minor exceptions detailed later. .PP The use of three dashes \*(L"\-\-\-\*(R" to indicate the start of a new document is supported, and multiple documents per file/stream is allowed. .PP Both line and inline comments are supported. .PP Scalars are supported via the plain style, single quote and double quote, as well as literal-style and folded-style multi-line scalars. .PP The use of explicit tags is not supported. .PP The use of \*(L"null\*(R" type scalars is supported via the ~ character. .PP The use of \*(L"bool\*(R" type scalars is not supported. .PP However, serializer implementations should take care to explicitly escape strings that match a \*(L"bool\*(R" keyword in the following set to prevent other implementations that do support \*(L"bool\*(R" accidentally reading a string as a boolean .PP .Vb 3 \& y|Y|yes|Yes|YES|n|N|no|No|NO \& |true|True|TRUE|false|False|FALSE \& |on|On|ON|off|Off|OFF .Ve .PP The use of anchors and aliases is not supported. .PP The use of directives is supported only for the \f(CW%YAML\fR directive. .SS "3. Processing \s-1YAML\s0 Tiny Information" .IX Subsection "3. Processing YAML Tiny Information" \&\fBProcesses\fR .PP The \s-1YAML\s0 specification dictates three-phase serialization and three-phase deserialization. .PP The \s-1YAML\s0 Tiny specification does not mandate any particular methodology or mechanism for parsing. .PP Any compliant parser is only required to parse a single document at a time. The ability to support streaming documents is optional and most likely non-typical. .PP Because anchors and aliases are not supported, the resulting representation graph is thus directed but (unlike the main \s-1YAML\s0 specification) \fBacyclic\fR. .PP Circular references/pointers are not possible, and any \s-1YAML\s0 Tiny serializer detecting a circular reference should error with an appropriate message. .PP \&\fBPresentation Stream\fR .PP \&\s-1YAML\s0 Tiny reads and write \s-1UTF\-8\s0 encoded files. Operations on strings expect or produce Unicode characters not \s-1UTF\-8\s0 encoded bytes. .PP \&\fBLoading Failure Points\fR .PP \&\s-1YAML\s0 Tiny parsers and emitters are not expected to recover from, or adapt to, errors. The specific error modality of any implementation is not dictated (return codes, exceptions, etc.) but is expected to be consistent. .SS "4. Syntax" .IX Subsection "4. Syntax" \&\fBCharacter Set\fR .PP \&\s-1YAML\s0 Tiny streams are processed in memory as Unicode characters and read/written with \s-1UTF\-8\s0 encoding. .PP The escaping and unescaping of the 8\-bit \s-1YAML\s0 escapes is required. .PP The escaping and unescaping of 16\-bit and 32\-bit \s-1YAML\s0 escapes is not required. .PP \&\fBIndicator Characters\fR .PP Support for the \*(L"~\*(R" null/undefined indicator is required. .PP Implementations may represent this as appropriate for the underlying language. .PP Support for the \*(L"\-\*(R" block sequence indicator is required. .PP Support for the \*(L"?\*(R" mapping key indicator is \fBnot\fR required. .PP Support for the \*(L":\*(R" mapping value indicator is required. .PP Support for the \*(L",\*(R" flow collection indicator is \fBnot\fR required. .PP Support for the \*(L"[\*(R" flow sequence indicator is \fBnot\fR required, with one exception (detailed below). .PP Support for the \*(L"]\*(R" flow sequence indicator is \fBnot\fR required, with one exception (detailed below). .PP Support for the \*(L"{\*(R" flow mapping indicator is \fBnot\fR required, with one exception (detailed below). .PP Support for the \*(L"}\*(R" flow mapping indicator is \fBnot\fR required, with one exception (detailed below). .PP Support for the \*(L"#\*(R" comment indicator is required. .PP Support for the \*(L"&\*(R" anchor indicator is \fBnot\fR required. .PP Support for the \*(L"*\*(R" alias indicator is \fBnot\fR required. .PP Support for the \*(L"!\*(R" tag indicator is \fBnot\fR required. .PP Support for the \*(L"|\*(R" literal block indicator is required. .PP Support for the \*(L">\*(R" folded block indicator is required. .PP Support for the \*(L"'\*(R" single quote indicator is required. .PP Support for the """ double quote indicator is required. .PP Support for the \*(L"%\*(R" directive indicator is required, but only for the special case of a \f(CW%YAML\fR version directive before the \&\*(L"\-\-\-\*(R" document header, or on the same line as the document header. .PP For example: .PP .Vb 3 \& %YAML 1.1 \& \-\-\- \& \- A sequence with a single element .Ve .PP Special Exception: .PP To provide the ability to support empty sequences and mappings, support for the constructs [] (empty sequence) and {} (empty mapping) are required. .PP For example, .PP .Vb 9 \& %YAML 1.1 \& # A document consisting of only an empty mapping \& \-\-\- {} \& # A document consisting of only an empty sequence \& \-\-\- [] \& # A document consisting of an empty mapping within a sequence \& \- foo \& \- {} \& \- bar .Ve .PP \&\fBSyntax Primitives\fR .PP Other than the empty sequence and mapping cases described above, \s-1YAML\s0 Tiny supports only the indentation-based block-style group of contexts. .PP All five scalar contexts are supported. .PP Indentation spaces work as per the \s-1YAML\s0 specification in all cases. .PP Comments work as per the \s-1YAML\s0 specification in all simple cases. Support for indented multi-line comments is \fBnot\fR required. .PP Separation spaces work as per the \s-1YAML\s0 specification in all cases. .PP \&\fB\s-1YAML\s0 Tiny Character Stream\fR .PP The only directive supported by the \s-1YAML\s0 Tiny specification is the \&\f(CW%YAML\fR language/version identifier. Although detected, this directive will have no control over the parsing itself. .PP The parser must recognise both the \s-1YAML 1.0\s0 and \s-1YAML 1.1+\s0 formatting of this directive (as well as the commented form, although no explicit code should be needed to deal with this case, being a comment anyway) .PP That is, all of the following should be supported. .PP .Vb 2 \& \-\-\- #YAML:1.0 \& \- foo \& \& %YAML:1.0 \& \-\-\- \& \- foo \& \& % YAML 1.1 \& \-\-\- \& \- foo .Ve .PP Support for the \f(CW%TAG\fR directive is \fBnot\fR required. .PP Support for additional directives is \fBnot\fR required. .PP Support for the document boundary marker \*(L"\-\-\-\*(R" is required. .PP Support for the document boundary market \*(L"...\*(R" is \fBnot\fR required. .PP If necessary, a document boundary should simply by indicated with a \&\*(L"\-\-\-\*(R" marker, with not preceding \*(L"...\*(R" marker. .PP Support for empty streams (containing no documents) is required. .PP Support for implicit document starts is required. .PP That is, the following must be equivalent. .PP .Vb 4 \& # Full form \& %YAML 1.1 \& \-\-\- \& foo: bar \& \& # Implicit form \& foo: bar .Ve .PP \&\fBNodes\fR .PP Support for nodes optional anchor and tag properties is \fBnot\fR required. .PP Support for node anchors is \fBnot\fR required. .PP Support for node tags is \fBnot\fR required. .PP Support for alias nodes is \fBnot\fR required. .PP Support for flow nodes is \fBnot\fR required. .PP Support for block nodes is required. .PP \&\fBScalar Styles\fR .PP Support for all five scalar styles is required as per the \s-1YAML\s0 specification, although support for quoted scalars spanning more than one line is \fBnot\fR required. .PP Support for multi-line scalar documents starting on the header is not required. .PP Support for the chomping indicators on multi-line scalar styles is required. .PP \&\fBCollection Styles\fR .PP Support for block-style sequences is required. .PP Support for flow-style sequences is \fBnot\fR required. .PP Support for block-style mappings is required. .PP Support for flow-style mappings is \fBnot\fR required. .PP Both sequences and mappings should be able to be arbitrarily nested. .PP Support for plain-style mapping keys is required. .PP Support for quoted keys in mappings is \fBnot\fR required. .PP Support for \*(L"?\*(R"\-indicated explicit keys is \fBnot\fR required. .PP Here endeth the specification. .SS "Additional Perl-Specific Notes" .IX Subsection "Additional Perl-Specific Notes" For some Perl applications, it's important to know if you really have a number and not a string. .PP That is, in some contexts is important that 3 the number is distinctive from \*(L"3\*(R" the string. .PP Because even Perl itself is not trivially able to understand the difference (certainly without XS-based modules) Perl implementations of the \s-1YAML\s0 Tiny specification are not required to retain the distinctiveness of 3 vs \*(L"3\*(R". .SH "SUPPORT" .IX Header "SUPPORT" Bugs should be reported via the \s-1CPAN\s0 bug tracker at .PP .SH "AUTHOR" .IX Header "AUTHOR" Adam Kennedy .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 \&\s-1YAML\s0 .IP "\(bu" 4 YAML::Syck .IP "\(bu" 4 Config::Tiny .IP "\(bu" 4 CSS::Tiny .IP "\(bu" 4 .IP "\(bu" 4 .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2006 \- 2013 Adam Kennedy. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP The full text of the license can be found in the \&\s-1LICENSE\s0 file included with this module.