1YAML::XS(3) User Contributed Perl Documentation YAML::XS(3)
2
3
4
6 YAML::XS - Perl YAML Serialization using XS and libyaml
7
9 use YAML::XS;
10
11 my $yaml = Dump [ 1..4 ];
12 my $array = Load $yaml;
13
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
28 $YAML::XS::LoadBlessed (since v0.69)
29 Default: false.
30
31 The default was changed in version 0.81.
32
33 When set to false, it will not bless data into objects, which can
34 be a security problem, when loading YAML from an untrusted source.
35 It will silently ignore the tag and just load the data unblessed.
36
37 In PyYAML, this is called SafeLoad.
38
39 If set to true, it will load the following YAML as objects:
40
41 ---
42 local: !Foo::Bar [a]
43 perl: !!perl/hash:Foo::Bar { a: 1 }
44 regex: !!perl/regexp:Foo::Bar pattern
45
46 You can create any kind of object with YAML. The creation itself is
47 not the critical part. If the class has a "DESTROY" method, it will
48 be called once the object is deleted. An example with File::Temp
49 removing files can be found at
50 <https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=862373>
51
52 $YAML::XS::UseCode
53 $YAML::XS::DumpCode
54 $YAML::XS::LoadCode
55 If enabled supports deparsing and evaling of code blocks.
56
57 Note that support for loading code was added in version 0.75,
58 although $LoadCode was documented already in earlier versions.
59
60 $YAML::XS::QuoteNumericStrings
61 When true (the default) strings that look like numbers but have not
62 been numified will be quoted when dumping.
63
64 This ensures leading that things like leading zeros and other
65 formatting are preserved.
66
67 $YAML::XS::Boolean (since v0.67)
68 Default is undef.
69
70 When set to "JSON::PP" or "boolean", the plain (unquoted) strings
71 "true" and "false" will be loaded as "JSON::PP::Boolean" or
72 "boolean.pm" objects. Those objects will be dumped again as plain
73 "true" or "false".
74
75 It will try to load JSON::PP or boolean and die if it can't be
76 loaded.
77
78 With that it's possible to add new "real" booleans to a data
79 structure:
80
81 local $YAML::XS::Boolean = "JSON::PP"; # or "boolean"
82 my $data = Load("booltrue: true");
83 $data->{boolfalse} = JSON::PP::false;
84 my $yaml = Dump($data);
85 # boolfalse: false
86 # booltrue: true
87
88 It also lets booleans survive when loading YAML via YAML::XS and
89 encode it in JSON via one of the various JSON encoders, which
90 mostly support JSON::PP booleans.
91
92 Please note that JSON::PP::Boolean and boolean.pm behave a bit
93 differently. Ideally you should only use them in boolean context.
94
95 If not set, booleans are loaded as special perl variables
96 "PL_sv_yes" and "PL_sv_no", which have the disadvantage that they
97 are readonly, and you can't add those to an existing data structure
98 with pure perl.
99
100 If you simply need to load "perl booleans" that are true or false
101 in boolean context, you will be fine with the default setting.
102
103 $YAML::XS::Indent (since v0.76)
104 Default is 2.
105
106 Sets the number of spaces for indentation for "Dump".
107
109 Handling unicode properly in Perl can be a pain. YAML::XS only deals
110 with streams of utf8 octets. Just remember this:
111
112 $perl = Load($utf8_octets);
113 $utf8_octets = Dump($perl);
114
115 There are many, many places where things can go wrong with unicode. If
116 you are having problems, use Devel::Peek on all the possible data
117 points.
118
120 You can find out (since v.079) which libyaml version this module was
121 built with:
122
123 my $libyaml_version = YAML::XS::LibYAML::libyaml_version();
124
126 • YAML.pm
127
128 • YAML::Syck
129
130 • YAML::Tiny
131
132 • YAML::PP
133
134 • YAML::PP::LibYAML
135
137 Ingy döt Net <ingy@cpan.org>
138
140 Copyright 2007-2021. Ingy döt Net.
141
142 This program is free software; you can redistribute it and/or modify it
143 under the same terms as Perl itself.
144
145 See <http://www.perl.com/perl/misc/Artistic.html>
146
147
148
149perl v5.34.0 2022-01-21 YAML::XS(3)