1YAML::XS(3)           User Contributed Perl Documentation          YAML::XS(3)
2
3
4

NAME

6       YAML::XS - Perl YAML Serialization using XS and libyaml
7

SYNOPSIS

9           use YAML::XS;
10
11           my $yaml = Dump [ 1..4 ];
12           my $array = Load $yaml;
13

DESCRIPTION

15       Kirill Simonov's "libyaml" is arguably the best YAML implementation.
16       The C library is written precisely to the YAML 1.1 specification. It
17       was originally bound to Python and was later bound to Ruby.
18
19       This module is a Perl XS binding to libyaml which offers Perl the best
20       YAML support to date.
21
22       This module exports the functions "Dump", "Load", "DumpFile" and
23       "LoadFile". These functions are intended to work exactly like
24       "YAML.pm"'s corresponding functions. Only "Load" and "Dump" are
25       exported by default.
26

CONFIGURATION

28       •   $YAML::XS::LoadBlessed (since v0.69)
29
30           Default: false.
31
32           The default was changed in version 0.81.
33
34           When set to false, it will not bless data into objects, which can
35           be a security problem, when loading YAML from an untrusted source.
36           It will silently ignore the tag and just load the data unblessed.
37
38           In PyYAML, this is called SafeLoad.
39
40           If set to true, it will load the following YAML as objects:
41
42               ---
43               local: !Foo::Bar [a]
44               perl: !!perl/hash:Foo::Bar { a: 1 }
45               regex: !!perl/regexp:Foo::Bar pattern
46
47           You can create any kind of object with YAML. The creation itself is
48           not the critical part. If the class has a "DESTROY" method, it will
49           be called once the object is deleted. An example with File::Temp
50           removing files can be found at
51           <https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=862373>.
52
53       •   $YAML::XS::ForbidDuplicateKeys (since 0.84)
54
55           Default: false
56
57           When set to true, "Load" will die when encountering a duplicate key
58           in a hash, e.g.
59
60               key: value
61               key: another value
62
63           This can be useful for bigger YAML documents where it is not that
64           obvious, and it is recommended to set it to true. That's also what
65           a YAML loader should do by default according to the YAML
66           specification.
67
68       •   $YAML::XS::UseCode
69
70       •   $YAML::XS::DumpCode
71
72       •   $YAML::XS::LoadCode
73
74           If enabled supports deparsing and evaling of code blocks.
75
76           Note that support for loading code was added in version 0.75,
77           although $LoadCode was documented already in earlier versions.
78
79       •   $YAML::XS::QuoteNumericStrings
80
81           When true (the default) strings that look like numbers but have not
82           been numified will be quoted when dumping.
83
84           This ensures leading that things like leading zeros and other
85           formatting are preserved.
86
87       •   $YAML::XS::Boolean (since v0.67)
88
89           Default is undef.
90
91           When set to "JSON::PP" or "boolean", the plain (unquoted) strings
92           "true" and "false" will be loaded as "JSON::PP::Boolean" or
93           "boolean.pm" objects. Those objects will be dumped again as plain
94           "true" or "false".
95
96           It will try to load [JSON::PP] or [boolean] and die if it can't be
97           loaded.
98
99           With that it's possible to add new "real" booleans to a data
100           structure:
101
102               local $YAML::XS::Boolean = "JSON::PP"; # or "boolean"
103               my $data = Load("booltrue: true");
104               $data->{boolfalse} = JSON::PP::false;
105               my $yaml = Dump($data);
106               # boolfalse: false
107               # booltrue: true
108
109           It also lets booleans survive when loading YAML via YAML::XS and
110           encode it in JSON via one of the various JSON encoders, which
111           mostly support JSON::PP booleans.
112
113           Please note that JSON::PP::Boolean and boolean.pm behave a bit
114           differently. Ideally you should only use them in boolean context.
115
116           If not set, booleans are loaded as special perl variables
117           "PL_sv_yes" and "PL_sv_no", which have the disadvantage that they
118           are readonly, and you can't add those to an existing data structure
119           with pure perl.
120
121           If you simply need to load "perl booleans" that are true or false
122           in boolean context, you will be fine with the default setting.
123
124       •   $YAML::XS::Indent (since v0.76)
125
126           Default is 2.
127
128           Sets the number of spaces for indentation for "Dump".
129

USING YAML::XS WITH UNICODE

131       Handling unicode properly in Perl can be a pain. YAML::XS only deals
132       with streams of utf8 octets. Just remember this:
133
134           $perl = Load($utf8_octets);
135           $utf8_octets = Dump($perl);
136
137       There are many, many places where things can go wrong with unicode. If
138       you are having problems, use Devel::Peek on all the possible data
139       points.
140

LIBYAML

142       You can find out (since v.079) which libyaml version this module was
143       built with:
144
145           my $libyaml_version = YAML::XS::LibYAML::libyaml_version();
146

SEE ALSO

148       •   YAML.pm
149
150       •   YAML::Syck
151
152       •   YAML::Tiny
153
154       •   YAML::PP
155
156       •   YAML::PP::LibYAML
157

AUTHOR

159       Ingy döt Net ingy@ingy.net <mailto:ingy@ingy.net>
160
162       Copyright 2007-2023 - Ingy döt Net
163
164       This program is free software; you can redistribute it and/or modify it
165       under the same terms as Perl itself.
166
167       See <http://www.perl.com/perl/misc/Artistic.html>
168
169
170
171perl v5.36.0                      2023-01-26                       YAML::XS(3)
Impressum