1YAML::Syck(3) User Contributed Perl Documentation YAML::Syck(3)
2
3
4
6 YAML::Syck - Fast, lightweight YAML loader and dumper
7
9 use YAML::Syck;
10
11 # Set this for interoperability with other YAML/Syck bindings:
12 # e.g. Load('Yes') becomes 1 and Load('No') becomes ''.
13 $YAML::Syck::ImplicitTyping = 1;
14
15 $data = Load($yaml);
16 $yaml = Dump($data);
17
18 # $file can be an IO object, or a filename
19 $data = LoadFile($file);
20 DumpFile($file, $data);
21
22 # A string with multiple YAML streams in it
23 $yaml = Dump(@data);
24 @data = Load($yaml);
25
26 # Dumping into a pre-existing output buffer
27 my $yaml;
28 DumpInto(\$yaml, @data);
29
31 This module provides a Perl interface to the libsyck data serialization
32 library. It exports the "Dump" and "Load" functions for converting
33 Perl data structures to YAML strings, and the other way around.
34
35 NOTE: If you are working with other language's YAML/Syck bindings (such
36 as Ruby), please set $YAML::Syck::ImplicitTyping to 1 before calling
37 the "Load"/"Dump" functions. The default setting is for preserving
38 backward-compatibility with "YAML.pm".
39
41 Error handling
42 Some calls are designed to die rather than returning YAML. You should
43 wrap your calls in eval to assure you do not get unexpected results.
44
46 $YAML::Syck::Headless
47 Defaults to false. Setting this to a true value will make "Dump" omit
48 the leading "---\n" marker.
49
50 $YAML::Syck::SortKeys
51 Defaults to false. Setting this to a true value will make "Dump" sort
52 hash keys.
53
54 $YAML::Syck::SingleQuote
55 Defaults to false. Setting this to a true value will make "Dump"
56 always emit single quotes instead of bare strings.
57
58 $YAML::Syck::ImplicitTyping
59 Defaults to false. Setting this to a true value will make "Load"
60 recognize various implicit types in YAML, such as unquoted "true",
61 "false", as well as integers and floating-point numbers. Otherwise,
62 only "~" is recognized to be "undef".
63
64 $YAML::Syck::ImplicitUnicode
65 Defaults to false. For Perl 5.8.0 or later, setting this to a true
66 value will make "Load" set Unicode flag on for every string that
67 contains valid UTF8 sequences, and make "Dump" return a unicode string.
68
69 Regardless of this flag, Unicode strings are dumped verbatim without
70 escaping; byte strings with high-bit set will be dumped with backslash
71 escaping.
72
73 However, because YAML does not distinguish between these two kinds of
74 strings, so this flag will affect loading of both variants of strings.
75
76 If you want to use LoadFile or DumpFile with unicode, you are required
77 to open your own file in order to assure it's UTF8 encoded:
78
79 open(my $fh, ">:encoding(UTF-8)", "out.yml");
80 DumpFile($fh, $hashref);
81
82 $YAML::Syck::ImplicitBinary
83 Defaults to false. For Perl 5.8.0 or later, setting this to a true
84 value will make "Dump" generate Base64-encoded "!!binary" data for all
85 non-Unicode scalars containing high-bit bytes.
86
87 $YAML::Syck::UseCode / $YAML::Syck::LoadCode / $YAML::Syck::DumpCode
88 These flags control whether or not to try and eval/deparse perl source
89 code; each of them defaults to false.
90
91 Setting $YAML::Syck::UseCode to a true value is equivalent to setting
92 both $YAML::Syck::LoadCode and $YAML::Syck::DumpCode to true.
93
94 $YAML::Syck::LoadBlessed
95 Defaults to false. Setting to true will allow YAML::Syck to bless
96 objects as it imports objects. This default changed in 1.32.
97
98 You can create any kind of object with YAML. The creation itself is not
99 the critical part. If the class has a DESTROY method, it will be called
100 once the object is deleted. An example with File::Temp removing files
101 can be found at
102 <https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=862373>
103
105 Dumping Glob/IO values do not work yet.
106
107 Dumping of Tied variables is unsupported.
108
109 Dumping into tied (or other magic variables) with "DumpInto" might not
110 work properly in all cases.
111
113 This module implements the YAML 1.0 spec. To deal with data in YAML
114 1.1, please use the "YAML::XS" module instead.
115
116 The current implementation bundles libsyck source code; if your system
117 has a site-wide shared libsyck, it will not be used.
118
119 Tag names such as "!!perl/hash:Foo" is blessed into the package "Foo",
120 but the "!hs/foo" and "!!hs/Foo" tags are blessed into "hs::Foo". Note
121 that this holds true even if the tag contains non-word characters; for
122 example, "!haskell.org/Foo" is blessed into "haskell.org::Foo". Please
123 use Class::Rebless to cast it into other user-defined packages. You can
124 also set the LoadBlessed flag false to disable all blessing.
125
126 This module has a lot of known issues
127 <https://rt.cpan.org/Public/Dist/Display.html?Name=YAML-Syck> and has
128 only been semi-actively maintained since 2007. If you encounter an
129 issue with it probably won't be fixed unless you offer up a patch
130 <http://github.com/toddr/YAML-Syck> in Git that's ready for release.
131
132 There are still good reasons to use this module, such as better
133 interoperability with other syck wrappers (like Ruby's), or some edge
134 case of YAML's syntax that it handles better. It'll probably work
135 perfectly for you, but if it doesn't you may want to look at YAML::XS,
136 or perhaps at looking another serialization format like JSON.
137
139 YAML, JSON::Syck
140
141 <http://www.yaml.org/>
142
144 Audrey Tang <cpan@audreyt.org>
145
147 Copyright 2005-2009 by Audrey Tang <cpan@audreyt.org>.
148
149 This software is released under the MIT license cited below.
150
151 The libsyck code bundled with this library is released by "why the
152 lucky stiff", under a BSD-style license. See the COPYING file for
153 details.
154
155 The "MIT" License
156 Permission is hereby granted, free of charge, to any person obtaining a
157 copy of this software and associated documentation files (the
158 "Software"), to deal in the Software without restriction, including
159 without limitation the rights to use, copy, modify, merge, publish,
160 distribute, sublicense, and/or sell copies of the Software, and to
161 permit persons to whom the Software is furnished to do so, subject to
162 the following conditions:
163
164 The above copyright notice and this permission notice shall be included
165 in all copies or substantial portions of the Software.
166
167 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
168 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
169 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
170 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
171 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
172 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
173 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
174
175
176
177perl v5.36.0 2023-01-20 YAML::Syck(3)