2 # See documentation after the __END__ mark.
7 $Headless $SortKeys $SingleQuote
8 $ImplicitBinary $ImplicitTyping $ImplicitUnicode
9 $UseCode $LoadCode $DumpCode
17 @EXPORT = qw( Dump Load DumpFile LoadFile );
18 @ISA = qw( Exporter );
25 XSLoader::load(__PACKAGE__, $VERSION);
29 push @ISA, 'DynaLoader';
30 __PACKAGE__->bootstrap($VERSION);
35 use constant QR_MAP => {
36 '' => sub { qr{$_[0]} },
37 x => sub { qr{$_[0]}x },
38 i => sub { qr{$_[0]}i },
39 s => sub { qr{$_[0]}s },
40 m => sub { qr{$_[0]}m },
41 ix => sub { qr{$_[0]}ix },
42 sx => sub { qr{$_[0]}sx },
43 mx => sub { qr{$_[0]}mx },
44 si => sub { qr{$_[0]}si },
45 mi => sub { qr{$_[0]}mi },
46 ms => sub { qr{$_[0]}sm },
47 six => sub { qr{$_[0]}six },
48 mix => sub { qr{$_[0]}mix },
49 msx => sub { qr{$_[0]}msx },
50 msi => sub { qr{$_[0]}msi },
51 msix => sub { qr{$_[0]}msix },
55 if ($_[0] =~ /\A \(\? ([ixsm]*) (?:- (?:[ixsm]*))? : (.*) \) \z/x) {
56 my $sub = QR_MAP()->{$1} || QR_MAP()->{''};
65 $#_ ? join('', map { YAML::Syck::DumpYAML($_) } @_)
66 : YAML::Syck::DumpYAML($_[0]);
71 my ($rv) = YAML::Syck::LoadYAML($_[0]);
75 YAML::Syck::LoadYAML($_[0]);
79 # NOTE. The code below (_is_openhandle) avoids to require/load
80 # Scalar::Util unless it is given a ref or glob
81 # as an argument. That is purposeful, so to avoid
82 # the need for this dependency unless strictly necessary.
83 # If that was not the case, Scalar::Util::openhandle could
88 if ( ref($h) || ref(\$h) eq 'GLOB' ) {
90 return Scalar::Util::openhandle($h);
98 if ( _is_openhandle($file) ) {
100 print {$file} YAML::Syck::DumpYAML($_) for @_;
103 print {$file} YAML::Syck::DumpYAML($_[0]);
108 open FH, "> $file" or die "Cannot write to $file: $!";
110 print FH YAML::Syck::DumpYAML($_) for @_;
113 print FH YAML::Syck::DumpYAML($_[0]);
121 if ( _is_openhandle($file) ) {
122 Load(do { local $/; <$file> });
126 open FH, "< $file" or die "Cannot read from $file: $!";
127 Load(do { local $/; <FH> });
138 YAML::Syck - Fast, lightweight YAML loader and dumper
144 # Set this for interoperability with other YAML/Syck bindings:
145 # e.g. Load('Yes') becomes 1 and Load('No') becomes ''.
146 $YAML::Syck::ImplicitTyping = 1;
151 # $file can be an IO object, or a filename
152 $data = LoadFile($file);
153 DumpFile($file, $data);
155 # A string with multiple YAML streams in it
161 This module has L<a lot of known
162 issues|https://rt.cpan.org/Public/Dist/Display.html?Name=YAML-Syck>
163 and hasn't been actively maintained since 2007. If you encounter an
164 issue with it probably won't be fixed unless you L<offer up a
165 patch|http://github.com/avar/YAML-Syck> in Git that's ready for
168 Consider using L<YAML::XS> instead, or not using YAML at all. YAML is
169 falling out of style in the Perl community in favor of simpler formats
170 like JSON, which don't suffer from the bugs and annoying
171 incompatibilities that plague the ambitious YAML format.
173 There are still some good reasons to use this module, such as better
174 interoperability with other syck wrappers (like Ruby's), or some edge
175 case of YAML's syntax that it handles better. Maybe it'll work
176 perfectly for you, but if it doesn't you may be in for some pain.
180 This module provides a Perl interface to the B<libsyck> data serialization
181 library. It exports the C<Dump> and C<Load> functions for converting
182 Perl data structures to YAML strings, and the other way around.
184 B<NOTE>: If you are working with other language's YAML/Syck bindings
185 (such as Ruby), please set C<$YAML::Syck::ImplicitTyping> to C<1> before
186 calling the C<Load>/C<Dump> functions. The default setting is for
187 preserving backward-compatibility with C<YAML.pm>.
191 =head2 $YAML::Syck::Headless
193 Defaults to false. Setting this to a true value will make C<Dump> omit the
194 leading C<---\n> marker.
196 =head2 $YAML::Syck::SortKeys
198 Defaults to false. Setting this to a true value will make C<Dump> sort
201 =head2 $YAML::Syck::SingleQuote
203 Defaults to false. Setting this to a true value will make C<Dump> always emit
204 single quotes instead of bare strings.
206 =head2 $YAML::Syck::ImplicitTyping
208 Defaults to false. Setting this to a true value will make C<Load> recognize
209 various implicit types in YAML, such as unquoted C<true>, C<false>, as well as
210 integers and floating-point numbers. Otherwise, only C<~> is recognized to
213 =head2 $YAML::Syck::ImplicitUnicode
215 Defaults to false. For Perl 5.8.0 or later, setting this to a true value will
216 make C<Load> set Unicode flag on for every string that contains valid UTF8
217 sequences, and make C<Dump> return a unicode string.
219 Regardless of this flag, Unicode strings are dumped verbatim without escaping;
220 byte strings with high-bit set will be dumped with backslash escaping.
222 However, because YAML does not distinguish between these two kinds of strings,
223 so this flag will affect loading of both variants of strings.
225 =head2 $YAML::Syck::ImplicitBinary
227 Defaults to false. For Perl 5.8.0 or later, setting this to a true value will
228 make C<Dump> generate Base64-encoded C<!!binary> data for all non-Unicode
229 scalars containing high-bit bytes.
231 =head2 $YAML::Syck::UseCode / $YAML::Syck::LoadCode / $YAML::Syck::DumpCode
233 These flags control whether or not to try and eval/deparse perl source code;
234 each of them defaults to false.
236 Setting C<$YAML::Syck::UseCode> to a true value is equivalent to setting
237 both C<$YAML::Syck::LoadCode> and C<$YAML::Syck::DumpCode> to true.
241 Dumping Glob/IO values does not work yet.
245 This module implements the YAML 1.0 spec. To deal with data in YAML 1.1,
246 please use the C<YAML::XS> module instead.
248 The current implementation bundles libsyck source code; if your system has a
249 site-wide shared libsyck, it will I<not> be used.
251 Tag names such as C<!!perl/hash:Foo> is blessed into the package C<Foo>, but
252 the C<!hs/foo> and C<!!hs/Foo> tags are blessed into C<hs::Foo>. Note that
253 this holds true even if the tag contains non-word characters; for example,
254 C<!haskell.org/Foo> is blessed into C<haskell.org::Foo>. Please use
255 L<Class::Rebless> to cast it into other user-defined packages.
259 L<YAML>, L<JSON::Syck>
261 L<http://www.yaml.org/>
265 Audrey Tang E<lt>cpan@audreyt.orgE<gt>
269 Copyright 2005-2009 by Audrey Tang E<lt>cpan@audreyt.orgE<gt>.
271 This software is released under the MIT license cited below.
273 The F<libsyck> code bundled with this library is released by
274 "why the lucky stiff", under a BSD-style license. See the F<COPYING>
277 =head2 The "MIT" License
279 Permission is hereby granted, free of charge, to any person obtaining a copy
280 of this software and associated documentation files (the "Software"), to deal
281 in the Software without restriction, including without limitation the rights
282 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
283 copies of the Software, and to permit persons to whom the Software is
284 furnished to do so, subject to the following conditions:
286 The above copyright notice and this permission notice shall be included in
287 all copies or substantial portions of the Software.
289 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
290 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
291 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
292 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
293 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
294 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
295 DEALINGS IN THE SOFTWARE.