YAML-1.31/0000755000175000017500000000000014543037225010703 5ustar ingyingyYAML-1.31/lib/0000755000175000017500000000000014543037225011451 5ustar ingyingyYAML-1.31/lib/YAML.pod0000644000175000017500000005570114543037225012727 0ustar ingyingy=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.48. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME YAML - YAML Ain't Markup Language™ =head1 VERSION This document describes L version B<1.31>. =head1 IMPORTANT - PLEASE READ THIS FIRST If you need to use YAML with Perl, it is likely that you will have a look at this module (C) first. There are several L in Perl and they all support the simple C and C API. Since this one has the obvious name "YAML", it may seem obvious to pick this one. As the author of this module, I humbly ask you to choose another. YAML.pm was the very first YAML implementation in the world, released in 2001. It was originally made as a prototype, over 2 years before the YAML 1.0 spec was published. Although it may work for your needs, it has numerous bugs and is barely maintained. Please consider using these first: =over =item * L - Pure Perl, Full Featured, Well Maintained =item * L - A C Perl binding like L but with the YAML::PP API. =back The rest of this documentation is left unchanged... =head1 SYNOPSIS use YAML; # Load a YAML stream of 3 YAML documents into Perl data structures. my ($hashref, $arrayref, $string) = Load(<<'...'); --- name: ingy # A Mapping age: old weight: heavy # I should comment that I also like pink, but don't tell anybody. favorite colors: - red - green - blue --- - Clark Evans # A Sequence - Oren Ben-Kiki - Ingy döt Net --- > # A Block Scalar You probably think YAML stands for "Yet Another Markup Language". It ain't! YAML is really a data serialization language. But if you want to think of it as a markup, that's OK with me. A lot of people try to use XML as a serialization format. "YAML" is catchy and fun to say. Try it. "YAML, YAML, YAML!!!" ... # Dump the Perl data structures back into YAML. print Dump($string, $arrayref, $hashref); # YAML::Dump is used the same way you'd use Data::Dumper::Dumper use Data::Dumper; print Dumper($string, $arrayref, $hashref); Since version 1.25 YAML.pm supports trailing comments. =head1 DESCRIPTION The YAML.pm module implements a YAML Loader and Dumper based on the YAML 1.0 specification. L YAML is a generic data serialization language that is optimized for human readability. It can be used to express the data structures of most modern programming languages. (Including Perl!!!) For information on the YAML syntax, please refer to the YAML specification. =head1 WHY YAML IS COOL =over =item YAML is readable for people. It makes clear sense out of complex data structures. You should find that YAML is an exceptional data dumping tool. Structure is shown through indentation, YAML supports recursive data, and hash keys are sorted by default. In addition, YAML supports several styles of scalar formatting for different types of data. =item YAML is editable. YAML was designed from the ground up to be an excellent syntax for configuration files. Almost all programs need configuration files, so why invent a new syntax for each one? And why subject users to the complexities of XML or native Perl code? =item YAML is multilingual. Yes, YAML supports Unicode. But I'm actually referring to programming languages. YAML was designed to meet the serialization needs of Perl, Python, Ruby, Tcl, PHP, Javascript and Java. It was also designed to be interoperable between those languages. That means YAML serializations produced by Perl can be processed by Python. =item YAML is taint safe. Using modules like Data::Dumper for serialization is fine as long as you can be sure that nobody can tamper with your data files or transmissions. That's because you need to use Perl's C built-in to deserialize the data. Somebody could add a snippet of Perl to erase your files. YAML's parser does not need to eval anything. =item YAML is full featured. YAML can accurately serialize all of the common Perl data structures and deserialize them again without losing data relationships. Although it is not 100% perfect (no serializer is or can be perfect), it fares as well as the popular current modules: Data::Dumper, Storable, XML::Dumper and Data::Denter. YAML.pm also has the ability to handle code (subroutine) references and typeglobs. (Still experimental) These features are not found in Perl's other serialization modules. =item YAML is extensible. The YAML language has been designed to be flexible enough to solve it's own problems. The markup itself has 3 basic construct which resemble Perl's hash, array and scalar. By default, these map to their Perl equivalents. But each YAML node also supports a tagging mechanism (type system) which can cause that node to be interpreted in a completely different manner. That's how YAML can support object serialization and oddball structures like Perl's typeglob. =back =head1 YAML IMPLEMENTATIONS IN PERL This module, YAML.pm, is really just the interface module for YAML modules written in Perl. The basic interface for YAML consists of two functions: C and C. The real work is done by the modules L and L. Different YAML module distributions can be created by subclassing YAML.pm and YAML::Loader and YAML::Dumper. For example, YAML-Simple consists of YAML::Simple YAML::Dumper::Simple and YAML::Loader::Simple. Why would there be more than one implementation of YAML? Well, despite YAML's offering of being a simple data format, YAML is actually very deep and complex. Implementing the entirety of the YAML specification is a daunting task. For this reason I am currently working on 3 different YAML implementations. =over =item YAML The main YAML distribution will keeping evolving to support the entire YAML specification in pure Perl. This may not be the fastest or most stable module though. Currently, YAML.pm has lots of known bugs. It is mostly a great tool for dumping Perl data structures to a readable form. =item YAML::Tiny The point of YAML::Tiny is to strip YAML down to the 90% that people use most and offer that in a small, fast, stable, pure Perl form. YAML::Tiny will simply die when it is asked to do something it can't. =item YAML::Syck C is the C based YAML processing library used by the Ruby programming language (and also Python, PHP and Pugs). YAML::Syck is the Perl binding to C. It should be very fast, but may have problems of its own. It will also require C compilation. NOTE: Audrey Tang has actually completed this module and it works great and is 10 times faster than YAML.pm. =back In the future, there will likely be even more YAML modules. Remember, people other than Ingy are allowed to write YAML modules! =head1 FUNCTIONAL USAGE YAML is completely OO under the hood. Still it exports a few useful top level functions so that it is dead simple to use. These functions just do the OO stuff for you. If you want direct access to the OO API see the documentation for YAML::Dumper and YAML::Loader. =head2 Exported Functions The following functions are exported by YAML.pm by default. The reason they are exported is so that YAML works much like Data::Dumper. If you don't want functions to be imported, just use YAML with an empty import list: use YAML (); =over =item Dump(list-of-Perl-data-structures) Turn Perl data into YAML. This function works very much like Data::Dumper::Dumper(). It takes a list of Perl data structures and dumps them into a serialized form. It returns a string containing the YAML stream. The structures can be references or plain scalars. =item Load(string-containing-a-YAML-stream) Turn YAML into Perl data. This is the opposite of Dump. Just like Storable's thaw() function or the eval() function in relation to Data::Dumper. It parses a string containing a valid YAML stream into a list of Perl data structures. =back =head2 Exportable Functions These functions are not exported by default but you can request them in an import list like this: use YAML qw'freeze thaw Bless'; =over =item freeze() and thaw() Aliases to Dump() and Load() for Storable fans. This will also allow YAML.pm to be plugged directly into modules like POE.pm, that use the freeze/thaw API for internal serialization. =item DumpFile(filepath, list) Writes the YAML stream to a file instead of just returning a string. =item LoadFile(filepath) Reads the YAML stream from a file instead of a string. =item Bless(perl-node, [yaml-node | class-name]) Associate a normal Perl node, with a yaml node. A yaml node is an object tied to the YAML::Node class. The second argument is either a yaml node that you've already created or a class (package) name that supports a C function. A C function should take a perl node and return a yaml node. If no second argument is provided, Bless will create a yaml node. This node is not returned, but can be retrieved with the Blessed() function. Here's an example of how to use Bless. Say you have a hash containing three keys, but you only want to dump two of them. Furthermore the keys must be dumped in a certain order. Here's how you do that: use YAML qw(Dump Bless); $hash = {apple => 'good', banana => 'bad', cauliflower => 'ugly'}; print Dump $hash; Bless($hash)->keys(['banana', 'apple']); print Dump $hash; produces: --- apple: good banana: bad cauliflower: ugly --- banana: bad apple: good Bless returns the tied part of a yaml-node, so that you can call the YAML::Node methods. This is the same thing that YAML::Node::ynode() returns. So another way to do the above example is: use YAML qw(Dump Bless); use YAML::Node; $hash = {apple => 'good', banana => 'bad', cauliflower => 'ugly'}; print Dump $hash; Bless($hash); $ynode = ynode(Blessed($hash)); $ynode->keys(['banana', 'apple']); print Dump $hash; Note that Blessing a Perl data structure does not change it anyway. The extra information is stored separately and looked up by the Blessed node's memory address. =item Blessed(perl-node) Returns the yaml node that a particular perl node is associated with (see above). Returns undef if the node is not (YAML) Blessed. =back =head1 GLOBAL OPTIONS YAML options are set using a group of global variables in the YAML namespace. This is similar to how Data::Dumper works. For example, to change the indentation width, do something like: local $YAML::Indent = 3; The current options are: =over =item DumperClass You can override which module/class YAML uses for Dumping data. =item LoadBlessed (since 1.25) Default is undef (false) The default was changed in version 1.30. When set to true, YAML nodes with special tags will be automatocally blessed into objects: - !perl/hash:Foo::Bar foo: 42 When loading untrusted YAML, you should disable this option by setting it to C<0>. This will also disable setting typeglobs when loading them. You can create any kind of object with YAML. The creation itself is not the critical part. If the class has a C method, it will be called once the object is deleted. An example with File::Temp removing files can be found at L =item LoaderClass You can override which module/class YAML uses for Loading data. =item Indent This is the number of space characters to use for each indentation level when doing a Dump(). The default is 2. By the way, YAML can use any number of characters for indentation at any level. So if you are editing YAML by hand feel free to do it anyway that looks pleasing to you; just be consistent for a given level. =item SortKeys Default is 1. (true) Tells YAML.pm whether or not to sort hash keys when storing a document. YAML::Node objects can have their own sort order, which is usually what you want. To override the YAML::Node order and sort the keys anyway, set SortKeys to 2. =item Stringify Default is 0. (false) Objects with string overloading should honor the overloading and dump the stringification of themselves, rather than the actual object's guts. =item Numify Default is 0. (false) Values that look like numbers (integers, floats) will be numified when loaded. =item UseHeader Default is 1. (true) This tells YAML.pm whether to use a separator string for a Dump operation. This only applies to the first document in a stream. Subsequent documents must have a YAML header by definition. =item UseVersion Default is 0. (false) Tells YAML.pm whether to include the YAML version on the separator/header. --- %YAML:1.0 =item AnchorPrefix Default is ''. Anchor names are normally numeric. YAML.pm simply starts with '1' and increases by one for each new anchor. This option allows you to specify a string to be prepended to each anchor number. =item UseCode Setting the UseCode option is a shortcut to set both the DumpCode and LoadCode options at once. Setting UseCode to '1' tells YAML.pm to dump Perl code references as Perl (using B::Deparse) and to load them back into memory using eval(). The reason this has to be an option is that using eval() to parse untrusted code is, well, untrustworthy. =item DumpCode Determines if and how YAML.pm should serialize Perl code references. By default YAML.pm will dump code references as dummy placeholders (much like Data::Dumper). If DumpCode is set to '1' or 'deparse', code references will be dumped as actual Perl code. =item LoadCode LoadCode is the opposite of DumpCode. It tells YAML if and how to deserialize code references. When set to '1' or 'deparse' it will use C. Since this is potentially risky, only use this option if you know where your YAML has been. LoadCode must be enabled also to use the feature of evaluating typeglobs (because with the typeglob feature you would be able to set the variable C<$YAML::LoadCode> from a YAML file). =item Preserve When set to true, this option tells the Loader to load hashes into YAML::Node objects. These are tied hashes. This has the effect of remembering the key order, thus it will be preserved when the hash is dumped again. See L for more information. =item UseBlock YAML.pm uses heuristics to guess which scalar style is best for a given node. Sometimes you'll want all multiline scalars to use the 'block' style. If so, set this option to 1. NOTE: YAML's block style is akin to Perl's here-document. =item UseFold (Not supported anymore since v0.60) If you want to force YAML to use the 'folded' style for all multiline scalars, then set $UseFold to 1. NOTE: YAML's folded style is akin to the way HTML folds text, except smarter. =item UseAliases YAML has an alias mechanism such that any given structure in memory gets serialized once. Any other references to that structure are serialized only as alias markers. This is how YAML can serialize duplicate and recursive structures. Sometimes, when you KNOW that your data is nonrecursive in nature, you may want to serialize such that every node is expressed in full. (ie as a copy of the original). Setting $YAML::UseAliases to 0 will allow you to do this. This also may result in faster processing because the lookup overhead is by bypassed. THIS OPTION CAN BE DANGEROUS. B your data is recursive, this option B cause Dump() to run in an endless loop, chewing up your computers memory. You have been warned. =item CompressSeries Default is 1. Compresses the formatting of arrays of hashes: - foo: bar - bar: foo becomes: - foo: bar - bar: foo Since this output is usually more desirable, this option is turned on by default. =item QuoteNumericStrings Default is 0. (false) Adds detection mechanisms to encode strings that resemble numbers with mandatory quoting. This ensures leading that things like leading/trailing zeros and other formatting are preserved. =back =head1 YAML TERMINOLOGY YAML is a full featured data serialization language, and thus has its own terminology. It is important to remember that although YAML is heavily influenced by Perl and Python, it is a language in its own right, not merely just a representation of Perl structures. YAML has three constructs that are conspicuously similar to Perl's hash, array, and scalar. They are called mapping, sequence, and string respectively. By default, they do what you would expect. But each instance may have an explicit or implicit tag (type) that makes it behave differently. In this manner, YAML can be extended to represent Perl's Glob or Python's tuple, or Ruby's Bigint. =over =item stream A YAML stream is the full sequence of Unicode characters that a YAML parser would read or a YAML emitter would write. A stream may contain one or more YAML documents separated by YAML headers. --- a: mapping foo: bar --- - a - sequence =item document A YAML document is an independent data structure representation within a stream. It is a top level node. Each document in a YAML stream must begin with a YAML header line. Actually the header is optional on the first document. --- This: top level mapping is: - a - YAML - document =item header A YAML header is a line that begins a YAML document. It consists of three dashes, possibly followed by more info. Another purpose of the header line is that it serves as a place to put top level tag and anchor information. --- !recursive-sequence &001 - * 001 - * 001 =item node A YAML node is the representation of a particular data structure. Nodes may contain other nodes. (In Perl terms, nodes are like scalars. Strings, arrayrefs and hashrefs. But this refers to the serialized format, not the in- memory structure.) =item tag This is similar to a type. It indicates how a particular YAML node serialization should be transferred into or out of memory. For instance a Foo::Bar object would use the tag 'perl/Foo::Bar': - !perl/Foo::Bar foo: 42 bar: stool =item collection A collection is the generic term for a YAML data grouping. YAML has two types of collections: mappings and sequences. (Similar to hashes and arrays) =item mapping A mapping is a YAML collection defined by unordered key/value pairs with unique keys. By default YAML mappings are loaded into Perl hashes. a mapping: foo: bar two: times two is 4 =item sequence A sequence is a YAML collection defined by an ordered list of elements. By default YAML sequences are loaded into Perl arrays. a sequence: - one bourbon - one scotch - one beer =item scalar A scalar is a YAML node that is a single value. By default YAML scalars are loaded into Perl scalars. a scalar key: a scalar value YAML has many styles for representing scalars. This is important because varying data will have varying formatting requirements to retain the optimum human readability. =item plain scalar A plain scalar is unquoted. All plain scalars are automatic candidates for "implicit tagging". This means that their tag may be determined automatically by examination. The typical uses for this are plain alpha strings, integers, real numbers, dates, times and currency. - a plain string - -42 - 3.1415 - 12:34 - 123 this is an error =item single quoted scalar This is similar to Perl's use of single quotes. It means no escaping except for single quotes which are escaped by using two adjacent single quotes. - 'When I say ''\n'' I mean "backslash en"' =item double quoted scalar This is similar to Perl's use of double quotes. Character escaping can be used. - "This scalar\nhas two lines, and a bell -->\a" =item folded scalar This is a multiline scalar which begins on the next line. It is indicated by a single right angle bracket. It is unescaped like the single quoted scalar. Line folding is also performed. - > This is a multiline scalar which begins on the next line. It is indicated by a single carat. It is unescaped like the single quoted scalar. Line folding is also performed. =item block scalar This final multiline form is akin to Perl's here-document except that (as in all YAML data) scope is indicated by indentation. Therefore, no ending marker is required. The data is verbatim. No line folding. - | QTY DESC PRICE TOTAL --- ---- ----- ----- 1 Foo Fighters $19.95 $19.95 2 Bar Belles $29.95 $59.90 =item parser A YAML processor has four stages: parse, load, dump, emit. A parser parses a YAML stream. YAML.pm's Load() function contains a parser. =item loader The other half of the Load() function is a loader. This takes the information from the parser and loads it into a Perl data structure. =item dumper The Dump() function consists of a dumper and an emitter. The dumper walks through each Perl data structure and gives info to the emitter. =item emitter The emitter takes info from the dumper and turns it into a YAML stream. NOTE: In YAML.pm the parserIemitter code are currently very closely tied together. In the future they may be broken into separate stages. =back For more information please refer to the immensely helpful YAML specification available at L. =head1 YSH - THE YAML SHELL The L distribution provides script called 'ysh', the YAML shell. ysh provides a simple, interactive way to play with YAML. If you type in Perl code, it displays the result in YAML. If you type in YAML it turns it into Perl code. To run ysh, (assuming you installed it along with YAML.pm) simply type: ysh [options] Please read the C documentation for the full details. There are lots of options. =head1 BUGS & DEFICIENCIES If you find a bug in YAML, please try to recreate it in the YAML Shell with logging turned on ('ysh -L'). When you have successfully reproduced the bug, please mail the LOG file to the author (ingy@cpan.org). WARNING: This is still B code. Well, most of this code has been around for years... BIGGER WARNING: YAML.pm has been slow in the making, but I am committed to having top notch YAML tools in the Perl world. The YAML team is close to finalizing the YAML 1.1 spec. This version of YAML.pm is based off of a very old pre 1.0 spec. In actuality there isn't a ton of difference, and this YAML.pm is still fairly useful. Things will get much better in the future. =head1 RESOURCES L is the official YAML website. L is the YAML 1.2 specification. =head1 SEE ALSO =over =item * L - This is almost certainly the YAML module you are looking for. It is full-featured and well maintained. =item * L - Same overall API as YAML::PP but uses the libyaml shared library for speed. =back =head1 AUTHOR Ingy döt Net =head1 COPYRIGHT AND LICENSE Copyright 2001-2023. Ingy döt Net. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut YAML-1.31/lib/YAML.pm0000644000175000017500000000617414543037225012561 0ustar ingyingypackage YAML; our $VERSION = '1.31'; use YAML::Mo; use Exporter; push @YAML::ISA, 'Exporter'; our @EXPORT = qw{ Dump Load }; our @EXPORT_OK = qw{ freeze thaw DumpFile LoadFile Bless Blessed }; our ( $UseCode, $DumpCode, $LoadCode, $SpecVersion, $UseHeader, $UseVersion, $UseBlock, $UseFold, $UseAliases, $Indent, $SortKeys, $Preserve, $AnchorPrefix, $CompressSeries, $InlineSeries, $Purity, $Stringify, $Numify, $LoadBlessed, $QuoteNumericStrings, $DumperClass, $LoaderClass ); use YAML::Node; # XXX This is a temp fix for Module::Build use Scalar::Util qw/ openhandle /; # XXX This VALUE nonsense needs to go. use constant VALUE => "\x07YAML\x07VALUE\x07"; # YAML Object Properties has dumper_class => default => sub {'YAML::Dumper'}; has loader_class => default => sub {'YAML::Loader'}; has dumper_object => default => sub {$_[0]->init_action_object("dumper")}; has loader_object => default => sub {$_[0]->init_action_object("loader")}; sub Dump { my $yaml = YAML->new; $yaml->dumper_class($YAML::DumperClass) if $YAML::DumperClass; return $yaml->dumper_object->dump(@_); } sub Load { my $yaml = YAML->new; $yaml->loader_class($YAML::LoaderClass) if $YAML::LoaderClass; return $yaml->loader_object->load(@_); } { no warnings 'once'; # freeze/thaw is the API for Storable string serialization. Some # modules make use of serializing packages on if they use freeze/thaw. *freeze = \ &Dump; *thaw = \ &Load; } sub DumpFile { my $OUT; my $filename = shift; if (openhandle $filename) { $OUT = $filename; } else { my $mode = '>'; if ($filename =~ /^\s*(>{1,2})\s*(.*)$/) { ($mode, $filename) = ($1, $2); } open $OUT, $mode, $filename or YAML::Mo::Object->die('YAML_DUMP_ERR_FILE_OUTPUT', $filename, "$!"); } binmode $OUT, ':utf8'; # if $Config{useperlio} eq 'define'; local $/ = "\n"; # reset special to "sane" print $OUT Dump(@_); unless (ref $filename eq 'GLOB') { close $OUT or do { my $errsav = $!; YAML::Mo::Object->die('YAML_DUMP_ERR_FILE_OUTPUT_CLOSE', $filename, $errsav); } } } sub LoadFile { my $IN; my $filename = shift; if (openhandle $filename) { $IN = $filename; } else { open $IN, '<', $filename or YAML::Mo::Object->die('YAML_LOAD_ERR_FILE_INPUT', $filename, "$!"); } binmode $IN, ':utf8'; # if $Config{useperlio} eq 'define'; return Load(do { local $/; <$IN> }); } sub init_action_object { my $self = shift; my $object_class = (shift) . '_class'; my $module_name = $self->$object_class; eval "require $module_name"; $self->die("Error in require $module_name - $@") if $@ and "$@" !~ /Can't locate/; my $object = $self->$object_class->new; $object->set_global_options; return $object; } my $global = {}; sub Bless { require YAML::Dumper::Base; YAML::Dumper::Base::bless($global, @_) } sub Blessed { require YAML::Dumper::Base; YAML::Dumper::Base::blessed($global, @_) } sub global_object { $global } 1; YAML-1.31/lib/YAML/0000755000175000017500000000000014543037225012213 5ustar ingyingyYAML-1.31/lib/YAML/Error.pod0000644000175000017500000000123214543037225014006 0ustar ingyingy=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.48. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME YAML::Error - Error formatting class for YAML modules =head1 SYNOPSIS $self->die('YAML_PARSE_ERR_NO_ANCHOR', $alias); $self->warn('YAML_LOAD_WARN_DUPLICATE_KEY'); =head1 DESCRIPTION This module provides a C and a C facility. =head1 AUTHOR Ingy döt Net =head1 COPYRIGHT Copyright 2001-2014. Ingy döt Net This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut YAML-1.31/lib/YAML/Dumper.pod0000644000175000017500000000141014543037225014147 0ustar ingyingy=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.48. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME YAML::Dumper - YAML class for dumping Perl objects to YAML =head1 SYNOPSIS use YAML::Dumper; my $dumper = YAML::Dumper->new; $dumper->indent_width(4); print $dumper->dump({foo => 'bar'}); =head1 DESCRIPTION YAML::Dumper is the module that YAML.pm used to serialize Perl objects to YAML. It is fully object oriented and usable on its own. =head1 AUTHOR Ingy döt Net =head1 COPYRIGHT Copyright 2001-2014. Ingy döt Net This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut YAML-1.31/lib/YAML/Marshall.pod0000644000175000017500000000122014543037225014455 0ustar ingyingy=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.48. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME YAML::Marshall - YAML marshalling class you can mixin to your classes =head1 SYNOPSIS package Bar; use Foo -base; use YAML::Marshall -mixin; =head1 DESCRIPTION For classes that want to handle their own YAML serialization. =head1 AUTHOR ingy döt Net =head1 COPYRIGHT Copyright 2001-2014. Ingy döt Net This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut YAML-1.31/lib/YAML/Loader.pod0000644000175000017500000000137714543037225014135 0ustar ingyingy=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.48. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME YAML::Loader - YAML class for loading Perl objects to YAML =head1 SYNOPSIS use YAML::Loader; my $loader = YAML::Loader->new; my $hash = $loader->load(<<'...'); foo: bar ... =head1 DESCRIPTION YAML::Loader is the module that YAML.pm used to deserialize YAML to Perl objects. It is fully object oriented and usable on its own. =head1 AUTHOR Ingy döt Net =head1 COPYRIGHT Copyright 2001-2014. Ingy döt Net This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut YAML-1.31/lib/YAML/Tag.pm0000644000175000017500000000033014543037225013260 0ustar ingyingyuse strict; use warnings; package YAML::Tag; use overload '""' => sub { ${$_[0]} }; sub new { my ($class, $self) = @_; bless \$self, $class } sub short { ${$_[0]} } sub canonical { ${$_[0]} } 1; YAML-1.31/lib/YAML/Mo.pm0000644000175000017500000000637014543037225013132 0ustar ingyingypackage YAML::Mo; # use Mo qw[builder default import]; # The following line of code was produced from the previous line by # Mo::Inline version 0.4 no warnings;my$M=__PACKAGE__.'::';*{$M.Object::new}=sub{my$c=shift;my$s=bless{@_},$c;my%n=%{$c.'::'.':E'};map{$s->{$_}=$n{$_}->()if!exists$s->{$_}}keys%n;$s};*{$M.import}=sub{import warnings;$^H|=1538;my($P,%e,%o)=caller.'::';shift;eval"no Mo::$_",&{$M.$_.::e}($P,\%e,\%o,\@_)for@_;return if$e{M};%e=(extends,sub{eval"no $_[0]()";@{$P.ISA}=$_[0]},has,sub{my$n=shift;my$m=sub{$#_?$_[0]{$n}=$_[1]:$_[0]{$n}};@_=(default,@_)if!($#_%2);$m=$o{$_}->($m,$n,@_)for sort keys%o;*{$P.$n}=$m},%e,);*{$P.$_}=$e{$_}for keys%e;@{$P.ISA}=$M.Object};*{$M.'builder::e'}=sub{my($P,$e,$o)=@_;$o->{builder}=sub{my($m,$n,%a)=@_;my$b=$a{builder}or return$m;my$i=exists$a{lazy}?$a{lazy}:!${$P.':N'};$i or ${$P.':E'}{$n}=\&{$P.$b}and return$m;sub{$#_?$m->(@_):!exists$_[0]{$n}?$_[0]{$n}=$_[0]->$b:$m->(@_)}}};*{$M.'default::e'}=sub{my($P,$e,$o)=@_;$o->{default}=sub{my($m,$n,%a)=@_;exists$a{default}or return$m;my($d,$r)=$a{default};my$g='HASH'eq($r=ref$d)?sub{+{%$d}}:'ARRAY'eq$r?sub{[@$d]}:'CODE'eq$r?$d:sub{$d};my$i=exists$a{lazy}?$a{lazy}:!${$P.':N'};$i or ${$P.':E'}{$n}=$g and return$m;sub{$#_?$m->(@_):!exists$_[0]{$n}?$_[0]{$n}=$g->(@_):$m->(@_)}}};my$i=\&import;*{$M.import}=sub{(@_==2 and not$_[1])?pop@_:@_==1?push@_,grep!/import/,@f:();goto&$i};@f=qw[builder default import];use strict;use warnings; our $DumperModule = 'Data::Dumper'; my ($_new_error, $_info, $_scalar_info); no strict 'refs'; *{$M.'Object::die'} = sub { my $self = shift; my $error = $self->$_new_error(@_); $error->type('Error'); Carp::croak($error->format_message); }; *{$M.'Object::warn'} = sub { my $self = shift; return unless $^W; my $error = $self->$_new_error(@_); $error->type('Warning'); Carp::cluck($error->format_message); }; # This code needs to be refactored to be simpler and more precise, and no, # Scalar::Util doesn't DWIM. # # Can't handle: # * blessed regexp *{$M.'Object::node_info'} = sub { my $self = shift; my $stringify = $_[1] || 0; my ($class, $type, $id) = ref($_[0]) ? $stringify ? &$_info("$_[0]") : do { require overload; my @info = &$_info(overload::StrVal($_[0])); if (ref($_[0]) eq 'Regexp') { @info[0, 1] = (undef, 'REGEXP'); } @info; } : &$_scalar_info($_[0]); ($class, $type, $id) = &$_scalar_info("$_[0]") unless $id; return wantarray ? ($class, $type, $id) : $id; }; #------------------------------------------------------------------------------- $_info = sub { return (($_[0]) =~ qr{^(?:(.*)\=)?([^=]*)\(([^\(]*)\)$}o); }; $_scalar_info = sub { my $id = 'undef'; if (defined $_[0]) { \$_[0] =~ /\((\w+)\)$/o or CORE::die(); $id = "$1-S"; } return (undef, undef, $id); }; $_new_error = sub { require Carp; my $self = shift; require YAML::Error; my $code = shift || 'unknown error'; my $error = YAML::Error->new(code => $code); $error->line($self->line) if $self->can('line'); $error->document($self->document) if $self->can('document'); $error->arguments([@_]); return $error; }; 1; YAML-1.31/lib/YAML/Loader.pm0000644000175000017500000006455714543037225014000 0ustar ingyingypackage YAML::Loader; use YAML::Mo; extends 'YAML::Loader::Base'; use YAML::Loader::Base; use YAML::Types; use YAML::Node; # Context constants use constant LEAF => 1; use constant COLLECTION => 2; use constant VALUE => "\x07YAML\x07VALUE\x07"; use constant COMMENT => "\x07YAML\x07COMMENT\x07"; # Common YAML character sets my $ESCAPE_CHAR = '[\\x00-\\x08\\x0b-\\x0d\\x0e-\\x1f]'; my $FOLD_CHAR = '>'; my $LIT_CHAR = '|'; my $LIT_CHAR_RX = "\\$LIT_CHAR"; sub load { my $self = shift; $self->stream($_[0] || ''); return $self->_parse(); } # Top level function for parsing. Parse each document in order and # handle processing for YAML headers. sub _parse { my $self = shift; my (%directives, $preface); $self->{stream} =~ s|\015\012|\012|g; $self->{stream} =~ s|\015|\012|g; $self->line(0); $self->die('YAML_PARSE_ERR_BAD_CHARS') if $self->stream =~ /$ESCAPE_CHAR/; $self->{stream} =~ s/(.)\n\Z/$1/s; $self->lines([split /\x0a/, $self->stream, -1]); $self->line(1); # Throw away any comments or blanks before the header (or start of # content for headerless streams) $self->_parse_throwaway_comments(); $self->document(0); $self->documents([]); $self->zero_indent([]); # Add an "assumed" header if there is no header and the stream is # not empty (after initial throwaways). if (not $self->eos) { if ($self->lines->[0] !~ /^---(\s|$)/) { unshift @{$self->lines}, '---'; $self->{line}--; } } # Main Loop. Parse out all the top level nodes and return them. while (not $self->eos) { $self->anchor2node({}); $self->{document}++; $self->done(0); $self->level(0); $self->offset->[0] = -1; if ($self->lines->[0] =~ /^---\s*(.*)$/) { my @words = split /\s/, $1; %directives = (); while (@words) { if ($words[0] =~ /^#(\w+):(\S.*)$/) { my ($key, $value) = ($1, $2); shift(@words); if (defined $directives{$key}) { $self->warn('YAML_PARSE_WARN_MULTIPLE_DIRECTIVES', $key, $self->document); next; } $directives{$key} = $value; } elsif ($words[0] eq '') { shift @words; } else { last; } } $self->preface(join ' ', @words); } else { $self->die('YAML_PARSE_ERR_NO_SEPARATOR'); } if (not $self->done) { $self->_parse_next_line(COLLECTION); } if ($self->done) { $self->{indent} = -1; $self->content(''); } $directives{YAML} ||= '1.0'; $directives{TAB} ||= 'NONE'; ($self->{major_version}, $self->{minor_version}) = split /\./, $directives{YAML}, 2; $self->die('YAML_PARSE_ERR_BAD_MAJOR_VERSION', $directives{YAML}) if $self->major_version ne '1'; $self->warn('YAML_PARSE_WARN_BAD_MINOR_VERSION', $directives{YAML}) if $self->minor_version ne '0'; $self->die('Unrecognized TAB policy') unless $directives{TAB} =~ /^(NONE|\d+)(:HARD)?$/; push @{$self->documents}, $self->_parse_node(); } return wantarray ? @{$self->documents} : $self->documents->[-1]; } # This function is the dispatcher for parsing each node. Every node # recurses back through here. (Inlines are an exception as they have # their own sub-parser.) sub _parse_node { my $self = shift; my $preface = $self->preface; $self->preface(''); my ($node, $type, $indicator, $chomp, $parsed_inline) = ('') x 5; my ($anchor, $alias, $explicit, $implicit) = ('') x 4; ($anchor, $alias, $explicit, $implicit, $preface) = $self->_parse_qualifiers($preface); if ($anchor) { $self->anchor2node->{$anchor} = CORE::bless [], 'YAML-anchor2node'; } $self->inline(''); while (length $preface) { if ($preface =~ s/^($FOLD_CHAR|$LIT_CHAR_RX)//) { $indicator = $1; if ($preface =~ s/^([+-])[0-9]*//) { $chomp = $1; } elsif ($preface =~ s/^[0-9]+([+-]?)//) { $chomp = $1; } if ($preface =~ s/^(?:\s+#.*$|\s*)$//) { } else { $self->die('YAML_PARSE_ERR_TEXT_AFTER_INDICATOR'); } } else { $self->inline($preface); $preface = ''; } } if ($alias) { $self->die('YAML_PARSE_ERR_NO_ANCHOR', $alias) unless defined $self->anchor2node->{$alias}; if (ref($self->anchor2node->{$alias}) ne 'YAML-anchor2node') { $node = $self->anchor2node->{$alias}; } else { $node = do {my $sv = "*$alias"}; push @{$self->anchor2node->{$alias}}, [\$node, $self->line]; } } elsif (length $self->inline) { $node = $self->_parse_inline(1, $implicit, $explicit); $parsed_inline = 1; if (length $self->inline) { $self->die('YAML_PARSE_ERR_SINGLE_LINE'); } } elsif ($indicator eq $LIT_CHAR) { $self->{level}++; $node = $self->_parse_block($chomp); $node = $self->_parse_implicit($node) if $implicit; $self->{level}--; } elsif ($indicator eq $FOLD_CHAR) { $self->{level}++; $node = $self->_parse_unfold($chomp); $node = $self->_parse_implicit($node) if $implicit; $self->{level}--; } else { $self->{level}++; $self->offset->[$self->level] ||= 0; if ($self->indent == $self->offset->[$self->level]) { if ($self->content =~ /^-( |$)/) { $node = $self->_parse_seq($anchor); } elsif ($self->content =~ /(^\?|\:( |$))/) { $node = $self->_parse_mapping($anchor); } elsif ($preface =~ /^\s*$/) { $node = $self->_parse_implicit(''); } else { $self->die('YAML_PARSE_ERR_BAD_NODE'); } } else { $node = undef; } $self->{level}--; } $#{$self->offset} = $self->level; if ($explicit) { $node = $self->_parse_explicit($node, $explicit) if !$parsed_inline; } if ($anchor) { if (ref($self->anchor2node->{$anchor}) eq 'YAML-anchor2node') { # XXX Can't remember what this code actually does for my $ref (@{$self->anchor2node->{$anchor}}) { ${$ref->[0]} = $node; $self->warn('YAML_LOAD_WARN_UNRESOLVED_ALIAS', $anchor, $ref->[1]); } } $self->anchor2node->{$anchor} = $node; } return $node; } # Preprocess the qualifiers that may be attached to any node. sub _parse_qualifiers { my $self = shift; my ($preface) = @_; my ($anchor, $alias, $explicit, $implicit, $token) = ('') x 5; $self->inline(''); while ($preface =~ /^[&*!]/) { if ($preface =~ s/^\!(\S+)\s*//) { $self->die('YAML_PARSE_ERR_MANY_EXPLICIT') if $explicit; $explicit = $1; } elsif ($preface =~ s/^\!\s*//) { $self->die('YAML_PARSE_ERR_MANY_IMPLICIT') if $implicit; $implicit = 1; } elsif ($preface =~ s/^\&([^ ,:]*)\s*//) { $token = $1; $self->die('YAML_PARSE_ERR_BAD_ANCHOR') unless $token =~ /^[a-zA-Z0-9_.\/-]+$/; $self->die('YAML_PARSE_ERR_MANY_ANCHOR') if $anchor; $self->die('YAML_PARSE_ERR_ANCHOR_ALIAS') if $alias; $anchor = $token; } elsif ($preface =~ s/^\*([^ ,:]*)\s*//) { $token = $1; $self->die('YAML_PARSE_ERR_BAD_ALIAS') unless $token =~ /^[a-zA-Z0-9_.\/-]+$/; $self->die('YAML_PARSE_ERR_MANY_ALIAS') if $alias; $self->die('YAML_PARSE_ERR_ANCHOR_ALIAS') if $anchor; $alias = $token; } } return ($anchor, $alias, $explicit, $implicit, $preface); } # Morph a node to it's explicit type sub _parse_explicit { my $self = shift; my ($node, $explicit) = @_; my ($type, $class); if ($explicit =~ /^\!?perl\/(hash|array|ref|scalar)(?:\:(\w(\w|\:\:)*)?)?$/) { ($type, $class) = (($1 || ''), ($2 || '')); # FIXME # die unless uc($type) eq ref($node) ? if ( $type eq "ref" ) { $self->die('YAML_LOAD_ERR_NO_DEFAULT_VALUE', 'XXX', $explicit) unless exists $node->{VALUE()} and scalar(keys %$node) == 1; my $value = $node->{VALUE()}; $node = \$value; } if ( $type eq "scalar" and length($class) and !ref($node) ) { my $value = $node; $node = \$value; } if ( length($class) and $YAML::LoadBlessed ) { CORE::bless($node, $class); } return $node; } if ($explicit =~ m{^!?perl/(glob|regexp|code)(?:\:(\w(\w|\:\:)*)?)?$}) { ($type, $class) = (($1 || ''), ($2 || '')); my $type_class = "YAML::Type::$type"; no strict 'refs'; if ($type_class->can('yaml_load')) { return $type_class->yaml_load($node, $class, $self); } else { $self->die('YAML_LOAD_ERR_NO_CONVERT', 'XXX', $explicit); } } # This !perl/@Foo and !perl/$Foo are deprecated but still parsed elsif ($YAML::TagClass->{$explicit} || $explicit =~ m{^perl/(\@|\$)?([a-zA-Z](\w|::)+)$} ) { $class = $YAML::TagClass->{$explicit} || $2; if ($class->can('yaml_load')) { require YAML::Node; return $class->yaml_load(YAML::Node->new($node, $explicit)); } elsif ($YAML::LoadBlessed) { if (ref $node) { return CORE::bless $node, $class; } else { return CORE::bless \$node, $class; } } else { return $node; } } elsif (ref $node) { require YAML::Node; return YAML::Node->new($node, $explicit); } else { # XXX This is likely wrong. Failing test: # --- !unknown 'scalar value' return $node; } } # Parse a YAML mapping into a Perl hash sub _parse_mapping { my $self = shift; my ($anchor) = @_; my $mapping = $self->preserve ? YAML::Node->new({}) : {}; $self->anchor2node->{$anchor} = $mapping; my $key; while (not $self->done and $self->indent == $self->offset->[$self->level]) { # If structured key: if ($self->{content} =~ s/^\?\s*//) { $self->preface($self->content); $self->_parse_next_line(COLLECTION); $key = $self->_parse_node(); $key = "$key"; } # If "default" key (equals sign) elsif ($self->{content} =~ s/^\=\s*(?=:)//) { $key = VALUE; } # If "comment" key (slash slash) elsif ($self->{content} =~ s/^\=\s*(?=:)//) { $key = COMMENT; } # Regular scalar key: else { $self->inline($self->content); $key = $self->_parse_inline(); $key = "$key"; $self->content($self->inline); $self->inline(''); } unless ($self->{content} =~ s/^:(?:\s+#.*$|\s*)//) { $self->die('YAML_LOAD_ERR_BAD_MAP_ELEMENT'); } $self->preface($self->content); my $level = $self->level; # we can get a zero indented sequence, possibly my $zero_indent = $self->zero_indent; $zero_indent->[ $level ] = 0; $self->_parse_next_line(COLLECTION); my $value = $self->_parse_node(); $#$zero_indent = $level; if (exists $mapping->{$key}) { $self->warn('YAML_LOAD_WARN_DUPLICATE_KEY', $key); } else { $mapping->{$key} = $value; } } return $mapping; } # Parse a YAML sequence into a Perl array sub _parse_seq { my $self = shift; my ($anchor) = @_; my $seq = []; $self->anchor2node->{$anchor} = $seq; while (not $self->done and $self->indent == $self->offset->[$self->level]) { if ($self->content =~ /^-(?: (.*))?$/) { $self->preface(defined($1) ? $1 : ''); } else { if ($self->zero_indent->[ $self->level ]) { last; } $self->die('YAML_LOAD_ERR_BAD_SEQ_ELEMENT'); } # Check whether the preface looks like a YAML mapping ("key: value"). # This is complicated because it has to account for the possibility # that a key is a quoted string, which itself may contain escaped # quotes. my $preface = $self->preface; if ($preface =~ m/^ (\s*) ( - (?: \ .* | $ ) ) /x) { $self->indent($self->offset->[$self->level] + 2 + length($1)); $self->content($2); $self->level($self->level + 1); $self->offset->[$self->level] = $self->indent; $self->preface(''); push @$seq, $self->_parse_seq(''); $self->{level}--; $#{$self->offset} = $self->level; } elsif ( $preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) ((") (?:\\\\|[^"])*? " \s* \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) (\?.*$)/x or $preface =~ /^ (\s*) ([^'"\s:#&!\[\]\{\},*|>].*\:(\ .*|$))/x ) { $self->indent($self->offset->[$self->level] + 2 + length($1)); $self->content($2); $self->level($self->level + 1); $self->offset->[$self->level] = $self->indent; $self->preface(''); push @$seq, $self->_parse_mapping(''); $self->{level}--; $#{$self->offset} = $self->level; } else { $self->_parse_next_line(COLLECTION); push @$seq, $self->_parse_node(); } } return $seq; } # Parse an inline value. Since YAML supports inline collections, this is # the top level of a sub parsing. sub _parse_inline { my $self = shift; my ($top, $top_implicit, $top_explicit) = (@_, '', '', ''); $self->{inline} =~ s/^\s*(.*)\s*$/$1/; # OUCH - mugwump my ($node, $anchor, $alias, $explicit, $implicit) = ('') x 5; ($anchor, $alias, $explicit, $implicit, $self->{inline}) = $self->_parse_qualifiers($self->inline); if ($anchor) { $self->anchor2node->{$anchor} = CORE::bless [], 'YAML-anchor2node'; } $implicit ||= $top_implicit; $explicit ||= $top_explicit; ($top_implicit, $top_explicit) = ('', ''); if ($alias) { $self->die('YAML_PARSE_ERR_NO_ANCHOR', $alias) unless defined $self->anchor2node->{$alias}; if (ref($self->anchor2node->{$alias}) ne 'YAML-anchor2node') { $node = $self->anchor2node->{$alias}; } else { $node = do {my $sv = "*$alias"}; push @{$self->anchor2node->{$alias}}, [\$node, $self->line]; } } elsif ($self->inline =~ /^\{/) { $node = $self->_parse_inline_mapping($anchor); } elsif ($self->inline =~ /^\[/) { $node = $self->_parse_inline_seq($anchor); } elsif ($self->inline =~ /^"/) { $node = $self->_parse_inline_double_quoted(); $node = $self->_unescape($node); $node = $self->_parse_implicit($node) if $implicit; } elsif ($self->inline =~ /^'/) { $node = $self->_parse_inline_single_quoted(); $node = $self->_parse_implicit($node) if $implicit; } else { if ($top) { $node = $self->inline; $self->inline(''); } else { $node = $self->_parse_inline_simple(); } $node = $self->_parse_implicit($node) unless $explicit; if ($self->numify and defined $node and not ref $node and length $node and $node =~ m/\A-?(?:0|[1-9][0-9]*)?(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?\z/) { $node += 0; } } if ($explicit) { $node = $self->_parse_explicit($node, $explicit); } if ($anchor) { if (ref($self->anchor2node->{$anchor}) eq 'YAML-anchor2node') { for my $ref (@{$self->anchor2node->{$anchor}}) { ${$ref->[0]} = $node; $self->warn('YAML_LOAD_WARN_UNRESOLVED_ALIAS', $anchor, $ref->[1]); } } $self->anchor2node->{$anchor} = $node; } return $node; } # Parse the inline YAML mapping into a Perl hash sub _parse_inline_mapping { my $self = shift; my ($anchor) = @_; my $node = {}; $self->anchor2node->{$anchor} = $node; $self->die('YAML_PARSE_ERR_INLINE_MAP') unless $self->{inline} =~ s/^\{\s*//; while (not $self->{inline} =~ s/^\s*\}(\s+#.*$|\s*)//) { my $key = $self->_parse_inline(); $self->die('YAML_PARSE_ERR_INLINE_MAP') unless $self->{inline} =~ s/^\: \s*//; my $value = $self->_parse_inline(); if (exists $node->{$key}) { $self->warn('YAML_LOAD_WARN_DUPLICATE_KEY', $key); } else { $node->{$key} = $value; } next if $self->inline =~ /^\s*\}/; $self->die('YAML_PARSE_ERR_INLINE_MAP') unless $self->{inline} =~ s/^\,\s*//; } return $node; } # Parse the inline YAML sequence into a Perl array sub _parse_inline_seq { my $self = shift; my ($anchor) = @_; my $node = []; $self->anchor2node->{$anchor} = $node; $self->die('YAML_PARSE_ERR_INLINE_SEQUENCE') unless $self->{inline} =~ s/^\[\s*//; while (not $self->{inline} =~ s/^\s*\](\s+#.*$|\s*)//) { my $value = $self->_parse_inline(); push @$node, $value; next if $self->inline =~ /^\s*\]/; $self->die('YAML_PARSE_ERR_INLINE_SEQUENCE') unless $self->{inline} =~ s/^\,\s*//; } return $node; } # Parse the inline double quoted string. sub _parse_inline_double_quoted { my $self = shift; my $inline = $self->inline; if ($inline =~ s/^"//) { my $node = ''; while ($inline =~ s/^(\\.|[^"\\]+)//) { my $capture = $1; $capture =~ s/^\\"/"/; $node .= $capture; last unless length $inline; } if ($inline =~ s/^"(?:\s+#.*|\s*)//) { $self->inline($inline); return $node; } } $self->die('YAML_PARSE_ERR_BAD_DOUBLE'); } # Parse the inline single quoted string. sub _parse_inline_single_quoted { my $self = shift; my $inline = $self->inline; if ($inline =~ s/^'//) { my $node = ''; while ($inline =~ s/^(''|[^']+)//) { my $capture = $1; $capture =~ s/^''/'/; $node .= $capture; last unless length $inline; } if ($inline =~ s/^'(?:\s+#.*|\s*)//) { $self->inline($inline); return $node; } } $self->die('YAML_PARSE_ERR_BAD_SINGLE'); } # Parse the inline unquoted string and do implicit typing. sub _parse_inline_simple { my $self = shift; my $value; if ($self->inline =~ /^(|[^!@#%^&*].*?)(?=[\[\]\{\},]|, |: |- |:\s*$|$)/) { $value = $1; substr($self->{inline}, 0, length($1)) = ''; } else { $self->die('YAML_PARSE_ERR_BAD_INLINE_IMPLICIT', $value); } return $value; } sub _parse_implicit { my $self = shift; my ($value) = @_; # remove trailing comments and whitespace $value =~ s/^#.*$//; $value =~ s/\s+#.*$//; $value =~ s/\s*$//; return $value if $value eq ''; return undef if $value =~ /^~$/; return $value unless $value =~ /^[\@\`]/ or $value =~ /^[\-\?]\s/; $self->die('YAML_PARSE_ERR_BAD_IMPLICIT', $value); } # Unfold a YAML multiline scalar into a single string. sub _parse_unfold { my $self = shift; my ($chomp) = @_; my $node = ''; my $space = 0; while (not $self->done and $self->indent == $self->offset->[$self->level]) { $node .= $self->content. "\n"; $self->_parse_next_line(LEAF); } $node =~ s/^(\S.*)\n(?=\S)/$1 /gm; $node =~ s/^(\S.*)\n(\n+\S)/$1$2/gm; $node =~ s/\n*\Z// unless $chomp eq '+'; $node .= "\n" unless $chomp; return $node; } # Parse a YAML block style scalar. This is like a Perl here-document. sub _parse_block { my $self = shift; my ($chomp) = @_; my $node = ''; while (not $self->done and $self->indent == $self->offset->[$self->level]) { $node .= $self->content . "\n"; $self->_parse_next_line(LEAF); } return $node if '+' eq $chomp; $node =~ s/\n*\Z/\n/; $node =~ s/\n\Z// if $chomp eq '-'; return $node; } # Handle Perl style '#' comments. Comments must be at the same indentation # level as the collection line following them. sub _parse_throwaway_comments { my $self = shift; while (@{$self->lines} and $self->lines->[0] =~ m{^\s*(\#|$)} ) { shift @{$self->lines}; $self->{line}++; } $self->eos($self->{done} = not @{$self->lines}); } # This is the routine that controls what line is being parsed. It gets called # once for each line in the YAML stream. # # This routine must: # 1) Skip past the current line # 2) Determine the indentation offset for a new level # 3) Find the next _content_ line # A) Skip over any throwaways (Comments/blanks) # B) Set $self->indent, $self->content, $self->line # 4) Expand tabs appropriately sub _parse_next_line { my $self = shift; my ($type) = @_; my $level = $self->level; my $offset = $self->offset->[$level]; $self->die('YAML_EMIT_ERR_BAD_LEVEL') unless defined $offset; shift @{$self->lines}; $self->eos($self->{done} = not @{$self->lines}); if ($self->eos) { $self->offset->[$level + 1] = $offset + 1; return; } $self->{line}++; # Determine the offset for a new leaf node # TODO if ($self->preface =~ qr/(?:^|\s)(?:$FOLD_CHAR|$LIT_CHAR_RX)(?:[+-]([0-9]*)|([0-9]*)[+-]?)(?:\s+#.*|\s*)$/ ) { my $explicit_indent = defined $1 ? $1 : defined $2 ? $2 : ''; $self->die('YAML_PARSE_ERR_ZERO_INDENT') if length($explicit_indent) and $explicit_indent == 0; $type = LEAF; if (length($explicit_indent)) { $self->offset->[$level + 1] = $offset + $explicit_indent; } else { # First get rid of any comments. while (@{$self->lines} && ($self->lines->[0] =~ /^\s*#/)) { $self->lines->[0] =~ /^( *)/; last unless length($1) <= $offset; shift @{$self->lines}; $self->{line}++; } $self->eos($self->{done} = not @{$self->lines}); return if $self->eos; if ($self->lines->[0] =~ /^( *)\S/ and length($1) > $offset) { $self->offset->[$level+1] = length($1); } else { $self->offset->[$level+1] = $offset + 1; } } $offset = $self->offset->[++$level]; } # Determine the offset for a new collection level elsif ($type == COLLECTION and $self->preface =~ /^(\s*(\!\S*|\&\S+))*\s*$/) { $self->_parse_throwaway_comments(); my $zero_indent = $self->zero_indent; if ($self->eos) { $self->offset->[$level+1] = $offset + 1; return; } elsif ( defined $zero_indent->[ $level ] and not $zero_indent->[ $level ] and $self->lines->[0] =~ /^( {$offset,})-(?: |$)/ ) { my $new_offset = length($1); $self->offset->[$level+1] = $new_offset; if ($new_offset == $offset) { $zero_indent->[ $level+1 ] = 1; } } else { $self->lines->[0] =~ /^( *)\S/ or $self->die('YAML_PARSE_ERR_NONSPACE_INDENTATION'); if (length($1) > $offset) { $self->offset->[$level+1] = length($1); } else { $self->offset->[$level+1] = $offset + 1; } } $offset = $self->offset->[++$level]; } if ($type == LEAF) { if (@{$self->lines} and $self->lines->[0] =~ m{^( *)(\#)} and length($1) < $offset ) { if ( length($1) < $offset) { shift @{$self->lines}; $self->{line}++; # every comment after that is also thrown away regardless # of identation while (@{$self->lines} and $self->lines->[0] =~ m{^( *)(\#)} ) { shift @{$self->lines}; $self->{line}++; } } } $self->eos($self->{done} = not @{$self->lines}); } else { $self->_parse_throwaway_comments(); } return if $self->eos; if ($self->lines->[0] =~ /^---(\s|$)/) { $self->done(1); return; } if ($type == LEAF and $self->lines->[0] =~ /^ {$offset}(.*)$/ ) { $self->indent($offset); $self->content($1); } elsif ($self->lines->[0] =~ /^\s*$/) { $self->indent($offset); $self->content(''); } else { $self->lines->[0] =~ /^( *)(\S.*)$/; while ($self->offset->[$level] > length($1)) { $level--; } $self->die('YAML_PARSE_ERR_INCONSISTENT_INDENTATION') if $self->offset->[$level] != length($1); $self->indent(length($1)); $self->content($2); } $self->die('YAML_PARSE_ERR_INDENTATION') if $self->indent - $offset > 1; } #============================================================================== # Utility subroutines. #============================================================================== # Printable characters for escapes my %unescapes = ( 0 => "\x00", a => "\x07", t => "\x09", n => "\x0a", 'v' => "\x0b", # Potential v-string error on 5.6.2 if not quoted f => "\x0c", r => "\x0d", e => "\x1b", '\\' => '\\', ); # Transform all the backslash style escape characters to their literal meaning sub _unescape { my $self = shift; my ($node) = @_; $node =~ s/\\([never\\fart0]|x([0-9a-fA-F]{2}))/ (length($1)>1)?pack("H2",$2):$unescapes{$1}/gex; return $node; } 1; YAML-1.31/lib/YAML/Error.pm0000644000175000017500000001320414543037225013642 0ustar ingyingypackage YAML::Error; use YAML::Mo; has 'code'; has 'type' => default => sub {'Error'}; has 'line'; has 'document'; has 'arguments' => default => sub {[]}; my ($error_messages, %line_adjust); sub format_message { my $self = shift; my $output = 'YAML ' . $self->type . ': '; my $code = $self->code; if ($error_messages->{$code}) { $code = sprintf($error_messages->{$code}, @{$self->arguments}); } $output .= $code . "\n"; $output .= ' Code: ' . $self->code . "\n" if defined $self->code; $output .= ' Line: ' . $self->line . "\n" if defined $self->line; $output .= ' Document: ' . $self->document . "\n" if defined $self->document; return $output; } sub error_messages { $error_messages; } %$error_messages = map {s/^\s+//;s/\\n/\n/;$_} split "\n", <<'...'; YAML_PARSE_ERR_BAD_CHARS Invalid characters in stream. This parser only supports printable ASCII YAML_PARSE_ERR_BAD_MAJOR_VERSION Can't parse a %s document with a 1.0 parser YAML_PARSE_WARN_BAD_MINOR_VERSION Parsing a %s document with a 1.0 parser YAML_PARSE_WARN_MULTIPLE_DIRECTIVES '%s directive used more than once' YAML_PARSE_ERR_TEXT_AFTER_INDICATOR No text allowed after indicator YAML_PARSE_ERR_NO_ANCHOR No anchor for alias '*%s' YAML_PARSE_ERR_NO_SEPARATOR Expected separator '---' YAML_PARSE_ERR_SINGLE_LINE Couldn't parse single line value YAML_PARSE_ERR_BAD_ANCHOR Invalid anchor YAML_DUMP_ERR_INVALID_INDENT Invalid Indent width specified: '%s' YAML_LOAD_USAGE usage: YAML::Load($yaml_stream_scalar) YAML_PARSE_ERR_BAD_NODE Can't parse node YAML_PARSE_ERR_BAD_EXPLICIT Unsupported explicit transfer: '%s' YAML_DUMP_USAGE_DUMPCODE Invalid value for DumpCode: '%s' YAML_LOAD_ERR_FILE_INPUT Couldn't open %s for input:\n%s YAML_DUMP_ERR_FILE_CONCATENATE Can't concatenate to YAML file %s YAML_DUMP_ERR_FILE_OUTPUT Couldn't open %s for output:\n%s YAML_DUMP_ERR_FILE_OUTPUT_CLOSE Error closing %s:\n%s YAML_DUMP_ERR_NO_HEADER With UseHeader=0, the node must be a plain hash or array YAML_DUMP_WARN_BAD_NODE_TYPE Can't perform serialization for node type: '%s' YAML_EMIT_WARN_KEYS Encountered a problem with 'keys':\n%s YAML_DUMP_WARN_DEPARSE_FAILED Deparse failed for CODE reference YAML_DUMP_WARN_CODE_DUMMY Emitting dummy subroutine for CODE reference YAML_PARSE_ERR_MANY_EXPLICIT More than one explicit transfer YAML_PARSE_ERR_MANY_IMPLICIT More than one implicit request YAML_PARSE_ERR_MANY_ANCHOR More than one anchor YAML_PARSE_ERR_ANCHOR_ALIAS Can't define both an anchor and an alias YAML_PARSE_ERR_BAD_ALIAS Invalid alias YAML_PARSE_ERR_MANY_ALIAS More than one alias YAML_LOAD_ERR_NO_CONVERT Can't convert implicit '%s' node to explicit '%s' node YAML_LOAD_ERR_NO_DEFAULT_VALUE No default value for '%s' explicit transfer YAML_LOAD_ERR_NON_EMPTY_STRING Only the empty string can be converted to a '%s' YAML_LOAD_ERR_BAD_MAP_TO_SEQ Can't transfer map as sequence. Non numeric key '%s' encountered. YAML_DUMP_ERR_BAD_GLOB '%s' is an invalid value for Perl glob YAML_DUMP_ERR_BAD_REGEXP '%s' is an invalid value for Perl Regexp YAML_LOAD_ERR_BAD_MAP_ELEMENT Invalid element in map YAML_LOAD_WARN_DUPLICATE_KEY Duplicate map key '%s' found. Ignoring. YAML_LOAD_ERR_BAD_SEQ_ELEMENT Invalid element in sequence YAML_PARSE_ERR_INLINE_MAP Can't parse inline map YAML_PARSE_ERR_INLINE_SEQUENCE Can't parse inline sequence YAML_PARSE_ERR_BAD_DOUBLE Can't parse double quoted string YAML_PARSE_ERR_BAD_SINGLE Can't parse single quoted string YAML_PARSE_ERR_BAD_INLINE_IMPLICIT Can't parse inline implicit value '%s' YAML_PARSE_ERR_BAD_IMPLICIT Unrecognized implicit value '%s' YAML_PARSE_ERR_INDENTATION Error. Invalid indentation level YAML_PARSE_ERR_INCONSISTENT_INDENTATION Inconsistent indentation level YAML_LOAD_WARN_UNRESOLVED_ALIAS Can't resolve alias *%s YAML_LOAD_WARN_NO_REGEXP_IN_REGEXP No 'REGEXP' element for Perl regexp YAML_LOAD_WARN_BAD_REGEXP_ELEM Unknown element '%s' in Perl regexp YAML_LOAD_WARN_GLOB_NAME No 'NAME' element for Perl glob YAML_LOAD_WARN_PARSE_CODE Couldn't parse Perl code scalar: %s YAML_LOAD_WARN_CODE_DEPARSE Won't parse Perl code unless $YAML::LoadCode is set YAML_EMIT_ERR_BAD_LEVEL Internal Error: Bad level detected YAML_PARSE_WARN_AMBIGUOUS_TAB Amibiguous tab converted to spaces YAML_LOAD_WARN_BAD_GLOB_ELEM Unknown element '%s' in Perl glob YAML_PARSE_ERR_ZERO_INDENT Can't use zero as an indentation width YAML_LOAD_WARN_GLOB_IO Can't load an IO filehandle. Yet!!! ... %line_adjust = map {($_, 1)} qw(YAML_PARSE_ERR_BAD_MAJOR_VERSION YAML_PARSE_WARN_BAD_MINOR_VERSION YAML_PARSE_ERR_TEXT_AFTER_INDICATOR YAML_PARSE_ERR_NO_ANCHOR YAML_PARSE_ERR_MANY_EXPLICIT YAML_PARSE_ERR_MANY_IMPLICIT YAML_PARSE_ERR_MANY_ANCHOR YAML_PARSE_ERR_ANCHOR_ALIAS YAML_PARSE_ERR_BAD_ALIAS YAML_PARSE_ERR_MANY_ALIAS YAML_LOAD_ERR_NO_CONVERT YAML_LOAD_ERR_NO_DEFAULT_VALUE YAML_LOAD_ERR_NON_EMPTY_STRING YAML_LOAD_ERR_BAD_MAP_TO_SEQ YAML_LOAD_ERR_BAD_STR_TO_INT YAML_LOAD_ERR_BAD_STR_TO_DATE YAML_LOAD_ERR_BAD_STR_TO_TIME YAML_LOAD_WARN_DUPLICATE_KEY YAML_PARSE_ERR_INLINE_MAP YAML_PARSE_ERR_INLINE_SEQUENCE YAML_PARSE_ERR_BAD_DOUBLE YAML_PARSE_ERR_BAD_SINGLE YAML_PARSE_ERR_BAD_INLINE_IMPLICIT YAML_PARSE_ERR_BAD_IMPLICIT YAML_LOAD_WARN_NO_REGEXP_IN_REGEXP YAML_LOAD_WARN_BAD_REGEXP_ELEM YAML_LOAD_WARN_REGEXP_CREATE YAML_LOAD_WARN_GLOB_NAME YAML_LOAD_WARN_PARSE_CODE YAML_LOAD_WARN_CODE_DEPARSE YAML_LOAD_WARN_BAD_GLOB_ELEM YAML_PARSE_ERR_ZERO_INDENT ); package YAML::Warning; our @ISA = 'YAML::Error'; 1; YAML-1.31/lib/YAML/Loader/0000755000175000017500000000000014543037225013421 5ustar ingyingyYAML-1.31/lib/YAML/Loader/Base.pod0000644000175000017500000000121514543037225014776 0ustar ingyingy=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.48. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME YAML::Loader::Base - Base class for YAML Loader classes =head1 SYNOPSIS package YAML::Loader::Something; use YAML::Loader::Base -base; =head1 DESCRIPTION YAML::Loader::Base is a base class for creating YAML loader classes. =head1 AUTHOR Ingy döt Net =head1 COPYRIGHT Copyright 2001-2014. Ingy döt Net This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut YAML-1.31/lib/YAML/Loader/Base.pm0000644000175000017500000000231614543037225014633 0ustar ingyingypackage YAML::Loader::Base; use YAML::Mo; has load_code => default => sub {0}; has preserve => default => sub {0}; has stream => default => sub {''}; has document => default => sub {0}; has line => default => sub {0}; has documents => default => sub {[]}; has lines => default => sub {[]}; has eos => default => sub {0}; has done => default => sub {0}; has anchor2node => default => sub {{}}; has level => default => sub {0}; has offset => default => sub {[]}; has preface => default => sub {''}; has content => default => sub {''}; has indent => default => sub {0}; has major_version => default => sub {0}; has minor_version => default => sub {0}; has inline => default => sub {''}; has numify => default => sub {0}; has zero_indent => default => sub {[]}; sub set_global_options { my $self = shift; $self->load_code($YAML::LoadCode || $YAML::UseCode) if defined $YAML::LoadCode or defined $YAML::UseCode; $self->preserve($YAML::Preserve) if defined $YAML::Preserve; $self->numify($YAML::Numify) if defined $YAML::Numify; } sub load { die 'load() not implemented in this class.'; } 1; YAML-1.31/lib/YAML/Dumper.pm0000644000175000017500000004130014543037225014003 0ustar ingyingypackage YAML::Dumper; use YAML::Mo; extends 'YAML::Dumper::Base'; use YAML::Dumper::Base; use YAML::Node; use YAML::Types; use Scalar::Util qw(); use B (); use Carp (); # Context constants use constant KEY => 3; use constant BLESSED => 4; use constant FROMARRAY => 5; use constant VALUE => "\x07YAML\x07VALUE\x07"; # Common YAML character sets my $ESCAPE_CHAR = '[\\x00-\\x08\\x0b-\\x0d\\x0e-\\x1f]'; my $LIT_CHAR = '|'; #============================================================================== # OO version of Dump. YAML->new->dump($foo); sub dump { my $self = shift; $self->stream(''); $self->document(0); for my $document (@_) { $self->{document}++; $self->transferred({}); $self->id_refcnt({}); $self->id_anchor({}); $self->anchor(1); $self->level(0); $self->offset->[0] = 0 - $self->indent_width; $self->_prewalk($document); $self->_emit_header($document); $self->_emit_node($document); } return $self->stream; } # Every YAML document in the stream must begin with a YAML header, unless # there is only a single document and the user requests "no header". sub _emit_header { my $self = shift; my ($node) = @_; if (not $self->use_header and $self->document == 1 ) { $self->die('YAML_DUMP_ERR_NO_HEADER') unless ref($node) =~ /^(HASH|ARRAY)$/; $self->die('YAML_DUMP_ERR_NO_HEADER') if ref($node) eq 'HASH' and keys(%$node) == 0; $self->die('YAML_DUMP_ERR_NO_HEADER') if ref($node) eq 'ARRAY' and @$node == 0; # XXX Also croak if aliased, blessed, or ynode $self->headless(1); return; } $self->{stream} .= '---'; # XXX Consider switching to 1.1 style if ($self->use_version) { # $self->{stream} .= " #YAML:1.0"; } } # Walk the tree to be dumped and keep track of its reference counts. # This function is where the Dumper does all its work. All type # transfers happen here. sub _prewalk { my $self = shift; my $stringify = $self->stringify; my ($class, $type, $node_id) = $self->node_info(\$_[0], $stringify); # Handle typeglobs if ($type eq 'GLOB') { $self->transferred->{$node_id} = YAML::Type::glob->yaml_dump($_[0]); $self->_prewalk($self->transferred->{$node_id}); return; } # Handle regexps if (ref($_[0]) eq 'Regexp') { return; } # Handle Purity for scalars. # XXX can't find a use case yet. Might be YAGNI. if (not ref $_[0]) { $self->{id_refcnt}{$node_id}++ if $self->purity; return; } # Make a copy of original my $value = $_[0]; ($class, $type, $node_id) = $self->node_info($value, $stringify); # Must be a stringified object. return if (ref($value) and not $type); # Look for things already transferred. if ($self->transferred->{$node_id}) { (undef, undef, $node_id) = (ref $self->transferred->{$node_id}) ? $self->node_info($self->transferred->{$node_id}, $stringify) : $self->node_info(\ $self->transferred->{$node_id}, $stringify); $self->{id_refcnt}{$node_id}++; return; } # Handle code refs if ($type eq 'CODE') { $self->transferred->{$node_id} = 'placeholder'; YAML::Type::code->yaml_dump( $self->dump_code, $_[0], $self->transferred->{$node_id} ); ($class, $type, $node_id) = $self->node_info(\ $self->transferred->{$node_id}, $stringify); $self->{id_refcnt}{$node_id}++; return; } # Handle blessed things if (defined $class) { if ($value->can('yaml_dump')) { $value = $value->yaml_dump; } elsif ($type eq 'SCALAR') { $self->transferred->{$node_id} = 'placeholder'; YAML::Type::blessed->yaml_dump ($_[0], $self->transferred->{$node_id}); ($class, $type, $node_id) = $self->node_info(\ $self->transferred->{$node_id}, $stringify); $self->{id_refcnt}{$node_id}++; return; } else { $value = YAML::Type::blessed->yaml_dump($value); } $self->transferred->{$node_id} = $value; (undef, $type, $node_id) = $self->node_info($value, $stringify); } # Handle YAML Blessed things require YAML; if (defined YAML->global_object()->{blessed_map}{$node_id}) { $value = YAML->global_object()->{blessed_map}{$node_id}; $self->transferred->{$node_id} = $value; ($class, $type, $node_id) = $self->node_info($value, $stringify); $self->_prewalk($value); return; } # Handle hard refs if ($type eq 'REF' or $type eq 'SCALAR') { $value = YAML::Type::ref->yaml_dump($value); $self->transferred->{$node_id} = $value; (undef, $type, $node_id) = $self->node_info($value, $stringify); } # Handle ref-to-glob's elsif ($type eq 'GLOB') { my $ref_ynode = $self->transferred->{$node_id} = YAML::Type::ref->yaml_dump($value); my $glob_ynode = $ref_ynode->{&VALUE} = YAML::Type::glob->yaml_dump($$value); (undef, undef, $node_id) = $self->node_info($glob_ynode, $stringify); $self->transferred->{$node_id} = $glob_ynode; $self->_prewalk($glob_ynode); return; } # Increment ref count for node return if ++($self->{id_refcnt}{$node_id}) > 1; # Keep on walking if ($type eq 'HASH') { $self->_prewalk($value->{$_}) for keys %{$value}; return; } elsif ($type eq 'ARRAY') { $self->_prewalk($_) for @{$value}; return; } # Unknown type. Need to know about it. $self->warn(<<"..."); YAML::Dumper can't handle dumping this type of data. Please report this to the author. id: $node_id type: $type class: $class value: $value ... return; } # Every data element and sub data element is a node. # Everything emitted goes through this function. sub _emit_node { my $self = shift; my ($type, $node_id); my $ref = ref($_[0]); if ($ref) { if ($ref eq 'Regexp') { $self->_emit(' !!perl/regexp'); $self->_emit_str("$_[0]"); return; } (undef, $type, $node_id) = $self->node_info($_[0], $self->stringify); } else { $type = $ref || 'SCALAR'; (undef, undef, $node_id) = $self->node_info(\$_[0], $self->stringify); } my ($ynode, $tag) = ('') x 2; my ($value, $context) = (@_, 0); if (defined $self->transferred->{$node_id}) { $value = $self->transferred->{$node_id}; $ynode = ynode($value); if (ref $value) { $tag = defined $ynode ? $ynode->tag->short : ''; (undef, $type, $node_id) = $self->node_info($value, $self->stringify); } else { $ynode = ynode($self->transferred->{$node_id}); $tag = defined $ynode ? $ynode->tag->short : ''; $type = 'SCALAR'; (undef, undef, $node_id) = $self->node_info( \ $self->transferred->{$node_id}, $self->stringify ); } } elsif ($ynode = ynode($value)) { $tag = $ynode->tag->short; } if ($self->use_aliases) { $self->{id_refcnt}{$node_id} ||= 0; if ($self->{id_refcnt}{$node_id} > 1) { if (defined $self->{id_anchor}{$node_id}) { $self->{stream} .= ' *' . $self->{id_anchor}{$node_id} . "\n"; return; } my $anchor = $self->anchor_prefix . $self->{anchor}++; $self->{stream} .= ' &' . $anchor; $self->{id_anchor}{$node_id} = $anchor; } } return $self->_emit_str("$value") # Stringified object if ref($value) and not $type; return $self->_emit_scalar($value, $tag) if $type eq 'SCALAR' and $tag; return $self->_emit_str($value) if $type eq 'SCALAR'; return $self->_emit_mapping($value, $tag, $node_id, $context) if $type eq 'HASH'; return $self->_emit_sequence($value, $tag) if $type eq 'ARRAY'; $self->warn('YAML_DUMP_WARN_BAD_NODE_TYPE', $type); return $self->_emit_str("$value"); } # A YAML mapping is akin to a Perl hash. sub _emit_mapping { my $self = shift; my ($value, $tag, $node_id, $context) = @_; $self->{stream} .= " !$tag" if $tag; # Sometimes 'keys' fails. Like on a bad tie implementation. my $empty_hash = not(eval {keys %$value}); $self->warn('YAML_EMIT_WARN_KEYS', $@) if $@; return ($self->{stream} .= " {}\n") if $empty_hash; # If CompressSeries is on (default) and legal is this context, then # use it and make the indent level be 2 for this node. if ($context == FROMARRAY and $self->compress_series and not (defined $self->{id_anchor}{$node_id} or $tag or $empty_hash) ) { $self->{stream} .= ' '; $self->offset->[$self->level+1] = $self->offset->[$self->level] + 2; } else { $context = 0; $self->{stream} .= "\n" unless $self->headless && not($self->headless(0)); $self->offset->[$self->level+1] = $self->offset->[$self->level] + $self->indent_width; } $self->{level}++; my @keys; if ($self->sort_keys == 1) { if (ynode($value)) { @keys = keys %$value; } else { @keys = sort keys %$value; } } elsif ($self->sort_keys == 2) { @keys = sort keys %$value; } # XXX This is hackish but sometimes handy. Not sure whether to leave it in. elsif (ref($self->sort_keys) eq 'ARRAY') { my $i = 1; my %order = map { ($_, $i++) } @{$self->sort_keys}; @keys = sort { (defined $order{$a} and defined $order{$b}) ? ($order{$a} <=> $order{$b}) : ($a cmp $b); } keys %$value; } else { @keys = keys %$value; } # Force the YAML::VALUE ('=') key to sort last. if (exists $value->{&VALUE}) { for (my $i = 0; $i < @keys; $i++) { if ($keys[$i] eq &VALUE) { splice(@keys, $i, 1); push @keys, &VALUE; last; } } } for my $key (@keys) { $self->_emit_key($key, $context); $context = 0; $self->{stream} .= ':'; $self->_emit_node($value->{$key}); } $self->{level}--; } # A YAML series is akin to a Perl array. sub _emit_sequence { my $self = shift; my ($value, $tag) = @_; $self->{stream} .= " !$tag" if $tag; return ($self->{stream} .= " []\n") if @$value == 0; $self->{stream} .= "\n" unless $self->headless && not($self->headless(0)); # XXX Really crufty feature. Better implemented by ynodes. if ($self->inline_series and @$value <= $self->inline_series and not (scalar grep {ref or /\n/} @$value) ) { $self->{stream} =~ s/\n\Z/ /; $self->{stream} .= '['; for (my $i = 0; $i < @$value; $i++) { $self->_emit_str($value->[$i], KEY); last if $i == $#{$value}; $self->{stream} .= ', '; } $self->{stream} .= "]\n"; return; } $self->offset->[$self->level + 1] = $self->offset->[$self->level] + $self->indent_width; $self->{level}++; for my $val (@$value) { $self->{stream} .= ' ' x $self->offset->[$self->level]; $self->{stream} .= '-'; $self->_emit_node($val, FROMARRAY); } $self->{level}--; } # Emit a mapping key sub _emit_key { my $self = shift; my ($value, $context) = @_; $self->{stream} .= ' ' x $self->offset->[$self->level] unless $context == FROMARRAY; $self->_emit_str($value, KEY); } # Emit a blessed SCALAR sub _emit_scalar { my $self = shift; my ($value, $tag) = @_; $self->{stream} .= " !$tag"; $self->_emit_str($value, BLESSED); } sub _emit { my $self = shift; $self->{stream} .= join '', @_; } # Emit a string value. YAML has many scalar styles. This routine attempts to # guess the best style for the text. sub _emit_str { my $self = shift; my $type = $_[1] || 0; # Use heuristics to find the best scalar emission style. $self->offset->[$self->level + 1] = $self->offset->[$self->level] + $self->indent_width; $self->{level}++; my $sf = $type == KEY ? '' : ' '; my $sb = $type == KEY ? '? ' : ' '; my $ef = $type == KEY ? '' : "\n"; my $eb = "\n"; while (1) { $self->_emit($sf), $self->_emit_plain($_[0]), $self->_emit($ef), last if not defined $_[0]; $self->_emit($sf, '=', $ef), last if $_[0] eq VALUE; $self->_emit($sf), $self->_emit_double($_[0]), $self->_emit($ef), last if $_[0] =~ /$ESCAPE_CHAR/; if ($_[0] =~ /\n/) { $self->_emit($sb), $self->_emit_block($LIT_CHAR, $_[0]), $self->_emit($eb), last if $self->use_block; Carp::cluck "[YAML] \$UseFold is no longer supported" if $self->use_fold; $self->_emit($sf), $self->_emit_double($_[0]), $self->_emit($ef), last if length $_[0] <= 30; $self->_emit($sf), $self->_emit_double($_[0]), $self->_emit($ef), last if $_[0] !~ /\n\s*\S/; $self->_emit($sb), $self->_emit_block($LIT_CHAR, $_[0]), $self->_emit($eb), last; } $self->_emit($sf), $self->_emit_number($_[0]), $self->_emit($ef), last if $self->is_literal_number($_[0]); $self->_emit($sf), $self->_emit_plain($_[0]), $self->_emit($ef), last if $self->is_valid_plain($_[0]); $self->_emit($sf), $self->_emit_double($_[0]), $self->_emit($ef), last if $_[0] =~ /'/; $self->_emit($sf), $self->_emit_single($_[0]), $self->_emit($ef); last; } $self->{level}--; return; } sub is_literal_number { my $self = shift; # Stolen from JSON::Tiny return B::svref_2object(\$_[0])->FLAGS & (B::SVp_IOK | B::SVp_NOK) && 0 + $_[0] eq $_[0]; } sub _emit_number { my $self = shift; return $self->_emit_plain($_[0]); } # Check whether or not a scalar should be emitted as an plain scalar. sub is_valid_plain { my $self = shift; return 0 unless length $_[0]; return 0 if $self->quote_numeric_strings and Scalar::Util::looks_like_number($_[0]); # refer to YAML::Loader::parse_inline_simple() return 0 if $_[0] =~ /^[\s\{\[\~\`\'\"\!\@\#\>\|\%\&\?\*\^]/; return 0 if $_[0] =~ /[\{\[\]\},]/; return 0 if $_[0] =~ /[:\-\?]\s/; return 0 if $_[0] =~ /\s#/; return 0 if $_[0] =~ /\:(\s|$)/; return 0 if $_[0] =~ /[\s\|\>]$/; return 0 if $_[0] eq '-'; return 0 if $_[0] eq '='; return 1; } sub _emit_block { my $self = shift; my ($indicator, $value) = @_; $self->{stream} .= $indicator; $value =~ /(\n*)\Z/; my $chomp = length $1 ? (length $1 > 1) ? '+' : '' : '-'; $value = '~' if not defined $value; $self->{stream} .= $chomp; $self->{stream} .= $self->indent_width if $value =~ /^\s/; $self->{stream} .= $self->indent($value); } # Plain means that the scalar is unquoted. sub _emit_plain { my $self = shift; $self->{stream} .= defined $_[0] ? $_[0] : '~'; } # Double quoting is for single lined escaped strings. sub _emit_double { my $self = shift; (my $escaped = $self->escape($_[0])) =~ s/"/\\"/g; $self->{stream} .= qq{"$escaped"}; } # Single quoting is for single lined unescaped strings. sub _emit_single { my $self = shift; my $item = shift; $item =~ s{'}{''}g; $self->{stream} .= "'$item'"; } #============================================================================== # Utility subroutines. #============================================================================== # Indent a scalar to the current indentation level. sub indent { my $self = shift; my ($text) = @_; return $text unless length $text; $text =~ s/\n\Z//; my $indent = ' ' x $self->offset->[$self->level]; $text =~ s/^/$indent/gm; $text = "\n$text"; return $text; } # Escapes for unprintable characters my @escapes = qw(\0 \x01 \x02 \x03 \x04 \x05 \x06 \a \x08 \t \n \v \f \r \x0e \x0f \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1a \e \x1c \x1d \x1e \x1f ); # Escape the unprintable characters sub escape { my $self = shift; my ($text) = @_; $text =~ s/\\/\\\\/g; $text =~ s/([\x00-\x1f])/$escapes[ord($1)]/ge; return $text; } 1; YAML-1.31/lib/YAML/Node.pod0000644000175000017500000000475714543037225013621 0ustar ingyingy=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.48. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME YAML::Node - A generic data node that encapsulates YAML information =head1 SYNOPSIS use YAML; use YAML::Node; my $ynode = YAML::Node->new({}, 'ingerson.com/fruit'); %$ynode = qw(orange orange apple red grape green); print Dump $ynode; yields: --- !ingerson.com/fruit orange: orange apple: red grape: green =head1 DESCRIPTION A generic node in YAML is similar to a plain hash, array, or scalar node in Perl except that it must also keep track of its type. The type is a URI called the YAML type tag. YAML::Node is a class for generating and manipulating these containers. A YAML node (or ynode) is a tied hash, array or scalar. In most ways it behaves just like the plain thing. But you can assign and retrieve and YAML type tag URI to it. For the hash flavor, you can also assign the order that the keys will be retrieved in. By default a ynode will offer its keys in the same order that they were assigned. YAML::Node has a class method call new() that will return a ynode. You pass it a regular node and an optional type tag. After that you can use it like a normal Perl node, but when you YAML::Dump it, the magical properties will be honored. This is how you can control the sort order of hash keys during a YAML serialization. By default, YAML sorts keys alphabetically. But notice in the above example that the keys were Dumped in the same order they were assigned. YAML::Node exports a function called ynode(). This function returns the tied object so that you can call special methods on it like ->keys(). keys() works like this: use YAML; use YAML::Node; %$node = qw(orange orange apple red grape green); $ynode = YAML::Node->new($node); ynode($ynode)->keys(['grape', 'apple']); print Dump $ynode; produces: --- grape: green apple: red It tells the ynode which keys and what order to use. ynodes will play a very important role in how programs use YAML. They are the foundation of how a Perl class can marshall the Loading and Dumping of its objects. The upcoming versions of YAML.pm will have much more information on this. =head1 AUTHOR Ingy döt Net =head1 COPYRIGHT Copyright 2001-2014. Ingy döt Net This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut YAML-1.31/lib/YAML/Types.pm0000644000175000017500000001470014543037225013657 0ustar ingyingypackage YAML::Types; use YAML::Mo; use YAML::Node; # XXX These classes and their APIs could still use some refactoring, # but at least they work for now. #------------------------------------------------------------------------------- package YAML::Type::blessed; use YAML::Mo; # XXX sub yaml_dump { my $self = shift; my ($value) = @_; my ($class, $type) = YAML::Mo::Object->node_info($value); no strict 'refs'; my $kind = lc($type) . ':'; my $tag = ${$class . '::ClassTag'} || "!perl/$kind$class"; if ($type eq 'REF') { YAML::Node->new( {(&YAML::VALUE, ${$_[0]})}, $tag ); } elsif ($type eq 'SCALAR') { $_[1] = $$value; YAML::Node->new($_[1], $tag); } elsif ($type eq 'GLOB') { # blessed glob support is minimal, and will not round-trip # initial aim: to not cause an error return YAML::Type::glob->yaml_dump($value, $tag); } else { YAML::Node->new($value, $tag); } } #------------------------------------------------------------------------------- package YAML::Type::undef; sub yaml_dump { my $self = shift; } sub yaml_load { my $self = shift; } #------------------------------------------------------------------------------- package YAML::Type::glob; sub yaml_dump { my $self = shift; # $_[0] remains as the glob my $tag = pop @_ if 2==@_; $tag = '!perl/glob:' unless defined $tag; my $ynode = YAML::Node->new({}, $tag); for my $type (qw(PACKAGE NAME SCALAR ARRAY HASH CODE IO)) { my $value = *{$_[0]}{$type}; $value = $$value if $type eq 'SCALAR'; if (defined $value) { if ($type eq 'IO') { my @stats = qw(device inode mode links uid gid rdev size atime mtime ctime blksize blocks); undef $value; $value->{stat} = YAML::Node->new({}); if ($value->{fileno} = fileno(*{$_[0]})) { local $^W; map {$value->{stat}{shift @stats} = $_} stat(*{$_[0]}); $value->{tell} = tell(*{$_[0]}); } } $ynode->{$type} = $value; } } return $ynode; } sub yaml_load { my $self = shift; my ($node, $class, $loader) = @_; my ($name, $package); if (defined $node->{NAME}) { $name = $node->{NAME}; delete $node->{NAME}; } else { $loader->warn('YAML_LOAD_WARN_GLOB_NAME'); return undef; } if (defined $node->{PACKAGE}) { $package = $node->{PACKAGE}; delete $node->{PACKAGE}; } else { $package = 'main'; } no strict 'refs'; if (exists $node->{SCALAR}) { if ($YAML::LoadBlessed and $loader->load_code) { *{"${package}::$name"} = \$node->{SCALAR}; } delete $node->{SCALAR}; } for my $elem (qw(ARRAY HASH CODE IO)) { if (exists $node->{$elem}) { if ($elem eq 'IO') { $loader->warn('YAML_LOAD_WARN_GLOB_IO'); delete $node->{IO}; next; } if ($YAML::LoadBlessed and $loader->load_code) { *{"${package}::$name"} = $node->{$elem}; } delete $node->{$elem}; } } for my $elem (sort keys %$node) { $loader->warn('YAML_LOAD_WARN_BAD_GLOB_ELEM', $elem); } return *{"${package}::$name"}; } #------------------------------------------------------------------------------- package YAML::Type::code; my $dummy_warned = 0; my $default = '{ "DUMMY" }'; sub yaml_dump { my $self = shift; my $code; my ($dumpflag, $value) = @_; my ($class, $type) = YAML::Mo::Object->node_info($value); my $tag = "!perl/code"; $tag .= ":$class" if defined $class; if (not $dumpflag) { $code = $default; } else { bless $value, "CODE" if $class; eval { require B::Deparse }; return if $@; my $deparse = B::Deparse->new(); eval { local $^W = 0; $code = $deparse->coderef2text($value); }; if ($@) { warn YAML::YAML_DUMP_WARN_DEPARSE_FAILED() if $^W; $code = $default; } bless $value, $class if $class; chomp $code; $code .= "\n"; } $_[2] = $code; YAML::Node->new($_[2], $tag); } sub yaml_load { my $self = shift; my ($node, $class, $loader) = @_; if ($loader->load_code) { my $code = eval "package main; sub $node"; if ($@) { $loader->warn('YAML_LOAD_WARN_PARSE_CODE', $@); return sub {}; } else { CORE::bless $code, $class if ($class and $YAML::LoadBlessed); return $code; } } else { return CORE::bless sub {}, $class if ($class and $YAML::LoadBlessed); return sub {}; } } #------------------------------------------------------------------------------- package YAML::Type::ref; sub yaml_dump { my $self = shift; YAML::Node->new({(&YAML::VALUE, ${$_[0]})}, '!perl/ref') } sub yaml_load { my $self = shift; my ($node, $class, $loader) = @_; $loader->die('YAML_LOAD_ERR_NO_DEFAULT_VALUE', 'ptr') unless exists $node->{&YAML::VALUE}; return \$node->{&YAML::VALUE}; } #------------------------------------------------------------------------------- package YAML::Type::regexp; # XXX Be sure to handle blessed regexps (if possible) sub yaml_dump { die "YAML::Type::regexp::yaml_dump not currently implemented"; } use constant _QR_TYPES => { '' => sub { qr{$_[0]} }, x => sub { qr{$_[0]}x }, i => sub { qr{$_[0]}i }, s => sub { qr{$_[0]}s }, m => sub { qr{$_[0]}m }, ix => sub { qr{$_[0]}ix }, sx => sub { qr{$_[0]}sx }, mx => sub { qr{$_[0]}mx }, si => sub { qr{$_[0]}si }, mi => sub { qr{$_[0]}mi }, ms => sub { qr{$_[0]}sm }, six => sub { qr{$_[0]}six }, mix => sub { qr{$_[0]}mix }, msx => sub { qr{$_[0]}msx }, msi => sub { qr{$_[0]}msi }, msix => sub { qr{$_[0]}msix }, }; sub yaml_load { my $self = shift; my ($node, $class) = @_; return qr{$node} unless $node =~ /^\(\?([\^\-uxism]*):(.*)\)\z/s; my ($flags, $re) = ($1, $2); $flags =~ s/-.*//; $flags =~ s/^\^//; $flags =~ tr/u//d; my $sub = _QR_TYPES->{$flags} || sub { qr{$_[0]} }; my $qr = &$sub($re); bless $qr, $class if (length $class and $YAML::LoadBlessed); return $qr; } 1; YAML-1.31/lib/YAML/Types.pod0000644000175000017500000000134214543037225014023 0ustar ingyingy=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.48. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME YAML::Types - Marshall Perl internal data types to/from YAML =head1 SYNOPSIS $::foo = 42; print YAML::Dump(*::foo); print YAML::Dump(qr{match me}); =head1 DESCRIPTION This module has the helper classes for transferring objects, subroutines, references, globs, regexps and file handles to and from YAML. =head1 AUTHOR ingy döt Net =head1 COPYRIGHT Copyright 2001-2014. Ingy döt Net This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut YAML-1.31/lib/YAML/Node.pm0000644000175000017500000001051014543037225013433 0ustar ingyingyuse strict; use warnings; package YAML::Node; use YAML::Tag; require YAML::Mo; use Exporter; our @ISA = qw(Exporter YAML::Mo::Object); our @EXPORT = qw(ynode); sub ynode { my $self; if (ref($_[0]) eq 'HASH') { $self = tied(%{$_[0]}); } elsif (ref($_[0]) eq 'ARRAY') { $self = tied(@{$_[0]}); } elsif (ref(\$_[0]) eq 'GLOB') { $self = tied(*{$_[0]}); } else { $self = tied($_[0]); } return (ref($self) =~ /^yaml_/) ? $self : undef; } sub new { my ($class, $node, $tag) = @_; my $self; $self->{NODE} = $node; my (undef, $type) = YAML::Mo::Object->node_info($node); $self->{KIND} = (not defined $type) ? 'scalar' : ($type eq 'ARRAY') ? 'sequence' : ($type eq 'HASH') ? 'mapping' : $class->die("Can't create YAML::Node from '$type'"); tag($self, ($tag || '')); if ($self->{KIND} eq 'scalar') { yaml_scalar->new($self, $_[1]); return \ $_[1]; } my $package = "yaml_" . $self->{KIND}; $package->new($self) } sub node { $_->{NODE} } sub kind { $_->{KIND} } sub tag { my ($self, $value) = @_; if (defined $value) { $self->{TAG} = YAML::Tag->new($value); return $self; } else { return $self->{TAG}; } } sub keys { my ($self, $value) = @_; if (defined $value) { $self->{KEYS} = $value; return $self; } else { return $self->{KEYS}; } } #============================================================================== package yaml_scalar; @yaml_scalar::ISA = qw(YAML::Node); sub new { my ($class, $self) = @_; tie $_[2], $class, $self; } sub TIESCALAR { my ($class, $self) = @_; bless $self, $class; $self } sub FETCH { my ($self) = @_; $self->{NODE} } sub STORE { my ($self, $value) = @_; $self->{NODE} = $value } #============================================================================== package yaml_sequence; @yaml_sequence::ISA = qw(YAML::Node); sub new { my ($class, $self) = @_; my $new; tie @$new, $class, $self; $new } sub TIEARRAY { my ($class, $self) = @_; bless $self, $class } sub FETCHSIZE { my ($self) = @_; scalar @{$self->{NODE}}; } sub FETCH { my ($self, $index) = @_; $self->{NODE}[$index] } sub STORE { my ($self, $index, $value) = @_; $self->{NODE}[$index] = $value } sub undone { die "Not implemented yet"; # XXX } *STORESIZE = *POP = *PUSH = *SHIFT = *UNSHIFT = *SPLICE = *DELETE = *EXISTS = *STORESIZE = *POP = *PUSH = *SHIFT = *UNSHIFT = *SPLICE = *DELETE = *EXISTS = *undone; # XXX Must implement before release #============================================================================== package yaml_mapping; @yaml_mapping::ISA = qw(YAML::Node); sub new { my ($class, $self) = @_; @{$self->{KEYS}} = sort keys %{$self->{NODE}}; my $new; tie %$new, $class, $self; $new } sub TIEHASH { my ($class, $self) = @_; bless $self, $class } sub FETCH { my ($self, $key) = @_; if (exists $self->{NODE}{$key}) { return (grep {$_ eq $key} @{$self->{KEYS}}) ? $self->{NODE}{$key} : undef; } return $self->{HASH}{$key}; } sub STORE { my ($self, $key, $value) = @_; if (exists $self->{NODE}{$key}) { $self->{NODE}{$key} = $value; } elsif (exists $self->{HASH}{$key}) { $self->{HASH}{$key} = $value; } else { if (not grep {$_ eq $key} @{$self->{KEYS}}) { push(@{$self->{KEYS}}, $key); } $self->{HASH}{$key} = $value; } $value } sub DELETE { my ($self, $key) = @_; my $return; if (exists $self->{NODE}{$key}) { $return = $self->{NODE}{$key}; } elsif (exists $self->{HASH}{$key}) { $return = delete $self->{NODE}{$key}; } for (my $i = 0; $i < @{$self->{KEYS}}; $i++) { if ($self->{KEYS}[$i] eq $key) { splice(@{$self->{KEYS}}, $i, 1); } } return $return; } sub CLEAR { my ($self) = @_; @{$self->{KEYS}} = (); %{$self->{HASH}} = (); } sub FIRSTKEY { my ($self) = @_; $self->{ITER} = 0; $self->{KEYS}[0] } sub NEXTKEY { my ($self) = @_; $self->{KEYS}[++$self->{ITER}] } sub EXISTS { my ($self, $key) = @_; exists $self->{NODE}{$key} } 1; YAML-1.31/lib/YAML/Marshall.pm0000644000175000017500000000154314543037225014317 0ustar ingyingyuse strict; use warnings; package YAML::Marshall; use YAML::Node (); sub import { my $class = shift; no strict 'refs'; my $package = caller; unless (grep { $_ eq $class} @{$package . '::ISA'}) { push @{$package . '::ISA'}, $class; } my $tag = shift; if ( $tag ) { no warnings 'once'; $YAML::TagClass->{$tag} = $package; ${$package . "::YamlTag"} = $tag; } } sub yaml_dump { my $self = shift; no strict 'refs'; my $tag = ${ref($self) . "::YamlTag"} || 'perl/' . ref($self); $self->yaml_node($self, $tag); } sub yaml_load { my ($class, $node) = @_; if (my $ynode = $class->yaml_ynode($node)) { $node = $ynode->{NODE}; } bless $node, $class; } sub yaml_node { shift; YAML::Node->new(@_); } sub yaml_ynode { shift; YAML::Node::ynode(@_); } 1; YAML-1.31/lib/YAML/Dumper/0000755000175000017500000000000014543037225013447 5ustar ingyingyYAML-1.31/lib/YAML/Dumper/Base.pod0000644000175000017500000000121514543037225015024 0ustar ingyingy=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.48. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME YAML::Dumper::Base - Base class for YAML Dumper classes =head1 SYNOPSIS package YAML::Dumper::Something; use YAML::Dumper::Base -base; =head1 DESCRIPTION YAML::Dumper::Base is a base class for creating YAML dumper classes. =head1 AUTHOR Ingy döt Net =head1 COPYRIGHT Copyright 2001-2014. Ingy döt Net This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut YAML-1.31/lib/YAML/Dumper/Base.pm0000644000175000017500000000701214543037225014657 0ustar ingyingypackage YAML::Dumper::Base; use YAML::Mo; use YAML::Node; # YAML Dumping options has spec_version => default => sub {'1.0'}; has indent_width => default => sub {2}; has use_header => default => sub {1}; has use_version => default => sub {0}; has sort_keys => default => sub {1}; has anchor_prefix => default => sub {''}; has dump_code => default => sub {0}; has use_block => default => sub {0}; has use_fold => default => sub {0}; has compress_series => default => sub {1}; has inline_series => default => sub {0}; has use_aliases => default => sub {1}; has purity => default => sub {0}; has stringify => default => sub {0}; has quote_numeric_strings => default => sub {0}; # Properties has stream => default => sub {''}; has document => default => sub {0}; has transferred => default => sub {{}}; has id_refcnt => default => sub {{}}; has id_anchor => default => sub {{}}; has anchor => default => sub {1}; has level => default => sub {0}; has offset => default => sub {[]}; has headless => default => sub {0}; has blessed_map => default => sub {{}}; # Global Options are an idea taken from Data::Dumper. Really they are just # sugar on top of real OO properties. They make the simple Dump/Load API # easy to configure. sub set_global_options { my $self = shift; $self->spec_version($YAML::SpecVersion) if defined $YAML::SpecVersion; $self->indent_width($YAML::Indent) if defined $YAML::Indent; $self->use_header($YAML::UseHeader) if defined $YAML::UseHeader; $self->use_version($YAML::UseVersion) if defined $YAML::UseVersion; $self->sort_keys($YAML::SortKeys) if defined $YAML::SortKeys; $self->anchor_prefix($YAML::AnchorPrefix) if defined $YAML::AnchorPrefix; $self->dump_code($YAML::DumpCode || $YAML::UseCode) if defined $YAML::DumpCode or defined $YAML::UseCode; $self->use_block($YAML::UseBlock) if defined $YAML::UseBlock; $self->use_fold($YAML::UseFold) if defined $YAML::UseFold; $self->compress_series($YAML::CompressSeries) if defined $YAML::CompressSeries; $self->inline_series($YAML::InlineSeries) if defined $YAML::InlineSeries; $self->use_aliases($YAML::UseAliases) if defined $YAML::UseAliases; $self->purity($YAML::Purity) if defined $YAML::Purity; $self->stringify($YAML::Stringify) if defined $YAML::Stringify; $self->quote_numeric_strings($YAML::QuoteNumericStrings) if defined $YAML::QuoteNumericStrings; } sub dump { my $self = shift; $self->die('dump() not implemented in this class.'); } sub blessed { my $self = shift; my ($ref) = @_; $ref = \$_[0] unless ref $ref; my (undef, undef, $node_id) = YAML::Mo::Object->node_info($ref); $self->{blessed_map}->{$node_id}; } sub bless { my $self = shift; my ($ref, $blessing) = @_; my $ynode; $ref = \$_[0] unless ref $ref; my (undef, undef, $node_id) = YAML::Mo::Object->node_info($ref); if (not defined $blessing) { $ynode = YAML::Node->new($ref); } elsif (ref $blessing) { $self->die() unless ynode($blessing); $ynode = $blessing; } else { no strict 'refs'; my $transfer = $blessing . "::yaml_dump"; $self->die() unless defined &{$transfer}; $ynode = &{$transfer}($ref); $self->die() unless ynode($ynode); } $self->{blessed_map}->{$node_id} = $ynode; my $object = ynode($ynode) or $self->die(); return $object; } 1; YAML-1.31/lib/YAML/Any.pod0000644000175000017500000000550714543037225013455 0ustar ingyingy=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.48. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME YAML::Any - Pick a YAML implementation and use it. =head1 STATUS WARNING: This module will soon be deprecated. The plan is that YAML.pm itself will act like an I module. =head1 SYNOPSIS use YAML::Any; $YAML::Indent = 3; my $yaml = Dump(@objects); =head1 DESCRIPTION There are several YAML implementations that support the Dump/Load API. This module selects the best one available and uses it. =head1 ORDER Currently, YAML::Any will choose the first one of these YAML implementations that is installed on your system: =over =item * YAML::XS =item * YAML::Syck =item * YAML::Old =item * YAML =item * YAML::Tiny =back =head1 OPTIONS If you specify an option like: $YAML::Indent = 4; And YAML::Any is using YAML::XS, it will use the proper variable: $YAML::XS::Indent. =head1 SUBROUTINES Like all the YAML modules that YAML::Any uses, the following subroutines are exported by default: =over =item * Dump =item * Load =back and the following subroutines are exportable by request: =over =item * DumpFile =item * LoadFile =back =head1 METHODS YAML::Any provides the following class methods. =over =item C<< YAML::Any->order >> This method returns a list of the current possible implementations that YAML::Any will search for. =item C<< YAML::Any->implementation >> This method returns the implementation the YAML::Any will use. This result is obtained by finding the first member of YAML::Any->order that is either already loaded in C<%INC> or that can be loaded using C. If no implementation is found, an error will be thrown. =back =head1 EXAMPLES =head2 DumpFile and LoadFile Here is an example for C: #!/usr/bin/perl use strict; use warnings; use YAML::Any qw(DumpFile); my $ds = { array => [5,6,100], string => "Hello", }; DumpFile("hello.yml", $ds); When run, this creates a file called C in the current working directory, with the following contents. --- array: - 5 - 6 - 100 string: Hello In turn, the following C example, loads the contents from there and accesses them: #!/usr/bin/perl use strict; use warnings; use YAML::Any qw(LoadFile); my ($ds) = LoadFile("hello.yml"); print "String == '", $ds->{string}, "'\n"; Assuming C exists, and is as created by the C example, it prints: $ perl load.pl String == 'Hello' $ =head1 AUTHOR Ingy döt Net =head1 COPYRIGHT Copyright 2001-2014. Ingy döt Net This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut YAML-1.31/lib/YAML/Any.pm0000644000175000017500000000514714543037225013307 0ustar ingyingyuse strict; use warnings; package YAML::Any; our $VERSION = '1.31'; use Exporter (); @YAML::Any::ISA = 'Exporter'; @YAML::Any::EXPORT = qw(Dump Load); @YAML::Any::EXPORT_OK = qw(DumpFile LoadFile); my @dump_options = qw( UseCode DumpCode SpecVersion Indent UseHeader UseVersion SortKeys AnchorPrefix UseBlock UseFold CompressSeries InlineSeries UseAliases Purity Stringify ); my @load_options = qw( UseCode LoadCode Preserve ); my @implementations = qw( YAML::XS YAML::Syck YAML::Old YAML YAML::Tiny ); sub import { __PACKAGE__->implementation; goto &Exporter::import; } sub Dump { no strict 'refs'; no warnings 'once'; my $implementation = __PACKAGE__->implementation; for my $option (@dump_options) { my $var = "$implementation\::$option"; my $value = $$var; local $$var; $$var = defined $value ? $value : ${"YAML::$option"}; } return &{"$implementation\::Dump"}(@_); } sub DumpFile { no strict 'refs'; no warnings 'once'; my $implementation = __PACKAGE__->implementation; for my $option (@dump_options) { my $var = "$implementation\::$option"; my $value = $$var; local $$var; $$var = defined $value ? $value : ${"YAML::$option"}; } return &{"$implementation\::DumpFile"}(@_); } sub Load { no strict 'refs'; no warnings 'once'; my $implementation = __PACKAGE__->implementation; for my $option (@load_options) { my $var = "$implementation\::$option"; my $value = $$var; local $$var; $$var = defined $value ? $value : ${"YAML::$option"}; } return &{"$implementation\::Load"}(@_); } sub LoadFile { no strict 'refs'; no warnings 'once'; my $implementation = __PACKAGE__->implementation; for my $option (@load_options) { my $var = "$implementation\::$option"; my $value = $$var; local $$var; $$var = defined $value ? $value : ${"YAML::$option"}; } return &{"$implementation\::LoadFile"}(@_); } sub order { return @YAML::Any::_TEST_ORDER if @YAML::Any::_TEST_ORDER; return @implementations; } sub implementation { my @order = __PACKAGE__->order; for my $module (@order) { my $path = $module; $path =~ s/::/\//g; $path .= '.pm'; return $module if exists $INC{$path}; eval "require $module; 1" and return $module; } croak("YAML::Any couldn't find any of these YAML implementations: @order"); } sub croak { require Carp; Carp::croak(@_); } 1; YAML-1.31/lib/YAML/Tag.pod0000644000175000017500000000103214543037225013426 0ustar ingyingy=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.48. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME YAML::Tag - Tag URI object class for YAML =head1 SYNOPSIS use YAML::Tag; =head1 DESCRIPTION Used by YAML::Node. =head1 AUTHOR ingy döt Net =head1 COPYRIGHT Copyright 2001-2014. Ingy döt Net This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut YAML-1.31/Makefile.PL0000644000175000017500000000214314543037225012655 0ustar ingyingy# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.030. use strict; use warnings; use 5.008001; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "YAML Ain't Markup Language\x{2122}", "AUTHOR" => "Ingy d\x{f6}t Net ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "YAML", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.008001", "NAME" => "YAML", "PREREQ_PM" => {}, "TEST_REQUIRES" => { "Encode" => 0, "Test::Deep" => 0, "Test::More" => "0.88", "Test::YAML" => "1.05" }, "VERSION" => "1.31", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Encode" => 0, "Test::Deep" => 0, "Test::More" => "0.88", "Test::YAML" => "1.05" ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); YAML-1.31/CONTRIBUTING0000644000175000017500000000232614543037225012540 0ustar ingyingyContributing ============ The "YAML" Project needs your help! Please consider being a contributor. This file contains instructions that will help you be an effective contributor to the Project. GitHub ------ The code for this Project is hosted at GitHub. The URL is: https://github.com/ingydotnet/yaml-pm You can get the code with this command: git clone https://github.com/ingydotnet/yaml-pm If you've found a bug or a missing feature that you would like the author to know about, report it here: https://github.com/ingydotnet/yaml-pm/issues or fix it and submit a pull request here: https://github.com/ingydotnet/yaml-pm/pulls See these links for help on interacting with GitHub: * https://help.github.com/ * https://help.github.com/articles/creating-a-pull-request Zilla::Dist ----------- This Project uses Zilla::Dist to prepare it for publishing to CPAN. Read: https://metacpan.org/pod/Zilla::Dist::Contributing for up-to-date instructions on what contributors like yourself need to know to use it. IRC --- YAML has an IRC channel where you can find real people to help you: irc.perl.org#yaml Join the channel. Join the team! Thanks in advance, # This file generated by Zilla-Dist-0.1.22 YAML-1.31/META.yml0000644000175000017500000000153714543037225012162 0ustar ingyingy--- abstract: "YAML Ain't Markup Language™" author: - 'Ingy döt Net ' build_requires: Encode: '0' Test::Deep: '0' Test::More: '0.88' Test::YAML: '1.05' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.030, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: YAML no_index: directory: - example - inc - t - xt requires: perl: v5.8.1 resources: bugtracker: https://github.com/ingydotnet/yaml-pm/issues homepage: https://github.com/ingydotnet/yaml-pm repository: https://github.com/ingydotnet/yaml-pm.git version: '1.31' x_generated_by_perl: v5.28.0 x_serialization_backend: 'YAML::Tiny version 1.73' x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' YAML-1.31/Changes0000644000175000017500000003263214543037225012204 0ustar ingyingy1.31 Wed Dec 27 07:10:56 AM PST 2023 - Update docs to recommend YAML::PP 1.3 Mon 27 Jan 2020 11:09:46 PM CET - Breaking Change: Set $YAML::LoadBlessed default to false to make it more secure 1.29 Sat 11 May 2019 10:26:54 AM CEST - Fix regex for alias to match the one for anchors (PR#214 TINITA) 1.28 Sun 28 Apr 2019 11:46:21 AM CEST - Security fix: only enable loading globs when $LoadCode is set (PR#213 TINITA) 1.27 Sat Nov 3 14:01:26 CET 2018 - Remove a warning about uninitialized value for perl <= 5.10 1.26 Fri May 18 21:57:20 CEST 2018 - Fix bug introduced in 1.25 - loading of quoted string with colon as sequence element (tinita, fixes issue#208) - Support zero indented block sequences (PR#207 tinita) 1.25 Fri May 11 19:58:58 CEST 2018 - Applied several pull requests by tinita - Support trailing comments (PR#189, PR#190, PR#191) - Remove unused code (PR#192) - Use Test::Deep to actually test correctly for class names (PR#193) - Fix loading of mapping key which starts with `= ` (PR#194) - Fix loading strings with multiple spaces (PR#172) - Allow more characters in anchor name (PR#196) - Add $YAML::LoadBlessed for disabling loading objects (PR#197) - Disable test with long string under certain conditions (PR#201) - Quote scalar if it equals '=' (PR#202) - Multiple regexp roundtrip does not grow (PR#203) - Add support for compact nested block sequences (PR#204) - Support reverse order of block scalar indicators (PR#205) - Support nested mappings in sequences (PR#206) - Fix parsing of quoted strings (PR#188) 1.24 Mon Oct 30 20:31:53 CET 2017 - Fix $LoadCode (PR#180, PR#181, PR#182 by @mohawk2++) 1.23 Sun Feb 19 22:07:57 CET 2017 - Fix $YAML::Numify (empty values were converted to 0) 1.22 Tue Feb 14 23:23:08 CET 2017 - Add $YAML::Numify @perlpunk++ 1.21 Fri Dec 23 21:19:15 CET 2016 - No more "used only once" warnings for $YAML::Indent etc. PR#171, Issue#109 @perlpunk++ - Empty mapping value at the end resolves to null (was becoming empty string) PR#170, Issue#131 hiratara@cpan.org++ - Output key in warning when duplicate key was found PR#169, PR#119 patrick.allen.higgins@gmail.com++ - Allow reading and writing to IO::Handle PR#157, PR#168 @lameventanas++ @perlpunk++ 1.2 Fri Dec 2 13:20:33 PST 2016 - Apply and amend PR#146 (quoted map keys) @preaction++ - B::Deparse is loaded at runtime now - New Feature $YAML::Preserve (Apply PR#9 @fmenabe++) 1.19 Fri Nov 18 19:46:44 CET 2016 - Apply PR#164 pod (link to YAML::Shell) - Apply PR#151 Fix infinite loop for aliases without a name @bubaflub++ - Apply PR#142 Improve error messages @werekraken++ - Apply PR#162 Improve error messages - Apply PR#163 Trailing spaces after inline seq/map work now - Apply PR#154 Add test case for trailing comments @Varadinsky++ 1.18 Fri Jul 8 14:52:26 UTC 2016 - List Test::More as a prereq PR#161 @perlpunk++ 1.17 Tue Jul 5 20:20:55 UTC 2016 - Use Mo 0.40 1.16 Sun Jul 3 10:53:06 PDT 2016 - Fix VERSION issue. PR#158 by @bgruening++ 1.15 Sat Apr 18 17:03:09 CEST 2015 - Don't require newlines at end of YAML. Issue#149 1.14 Sat Jan 17 15:32:18 PST 2015 - Support for QuoteNumericStrings Global Setting. PR#145 @kentnl++ 1.13 Sat Oct 11 18:05:45 CEST 2014 - Disable some warnings in YAML::Any. PR#140 @nfg++ 1.12 Mon Sep 22 08:24:43 PDT 2014 - Fix https://rt.cpan.org/Ticket/Display.html?id=97870 1.11 Fri Aug 29 20:08:20 PDT 2014 - Remove unreachable code. PR#139. @ehuelsmann++ 1.1 Thu Aug 28 22:53:26 PDT 2014 - Improve error message about indendation. PR#138. @ehuelsmann++ 1.09 Tue Aug 19 16:41:13 PDT 2014 - Replace tabs with spaces 1.08 Mon Aug 18 10:21:48 PDT 2014 - Dep on Test::YAML 1.05 1.07 Mon Aug 18 08:40:01 PDT 2014 - Add doc examples for YAML::Any. PR#8 from shlomif++ 1.06 Sat Aug 16 16:51:08 PDT 2014 - Change testdir to t 1.05 Sat Aug 16 13:03:28 PDT 2014 - Meta 0.0.2 1.04 Sat Aug 16 04:28:10 PDT 2014 - Eliminate spurious trailing whitespace 1.03 Sat Aug 16 03:32:35 PDT 2014 - Eliminate File::Basename from test/ 1.02 Fri Aug 15 21:09:54 PDT 2014 - Add t/000-compile-modules.t 1.01 Thu Aug 7 14:48:24 PDT 2014 - Dep on patched Test::YAML 1 Thu Aug 7 00:35:21 PDT 2014 - Fix bad encoding in Pod 0.99 Wed Aug 6 17:55:42 PDT 2014 - Switch to external Test::Base 0.98 Wed Jul 30 12:32:25 PDT 2014 - Fix indexing of YAML::Any - Change IRC to irc.perl.org#yaml 0.97 Wed Jul 16 23:37:04 PDT 2014 - Move remaining docs to Swim 0.96 Sun Jul 13 22:54:08 PDT 2014 - Fix Metadata and add Contributing file - Change Kwim to Swim 0.95 Sat Jun 14 10:32:08 PDT 2014 - Fix dumping blessed globs. Issue 26. mcast++ 0.94 Sat Jun 14 10:32:08 PDT 2014 - Skip a failing test on 5.8 introduced in 0.93 0.93 Fri Jun 13 22:32:18 PDT 2014 - Switch to Zilla::Dist - Add badges to doc - @thorsteneckel++ fixed #18 - @karenetheridge++ fixed #19 0.92 Wed May 28 23:04:26 EDT 2014 - https://github.com/ingydotnet/yaml-pm/pull/23 0.91 Tue May 27 17:14:12 EDT 2014 - https://github.com/ingydotnet/yaml-pm/pull/22 0.9 Mon Feb 10 08:42:31 PST 2014 - Revert Mo from 0.38 to 0.31 - zefram++ reported it breaking cpan client 0.89 Sat Nov 8 12:51:48 PST 2014 - Fixed tests to work under parallel testing -- kentnl - Switched to dzil release process 0.88 Tue Dec 3 05:29:34 UTC 2013 - Fixed YAML loading on perl 5.8 (broken in YAML 0.85) by removing 5.10-specific regex construct. -- hobbs++ 0.87 Sat Nov 30 21:51:48 PST 2013 - Using latest Test::Builder tp fix https://rt.cpan.org/Public/Bug/Display.html?id=90847 0.86 Tue Nov 26 16:43:27 UTC 2013 - Revert YAML::Mo for https://rt.cpan.org/Public/Bug/Display.html?id=90817 0.85 Sun Nov 24 07:43:13 PST 2013 - Fix for https://rt.cpan.org/Ticket/Display.html?id=19838 where synopsis in YAML::Dumper doesn't work as exptected. - Thorsten++ https://rt.cpan.org/Public/Bug/Display.html?id=90593 - Upgrade to latest Mo 0.84 Fri Jul 13 18:17:27 GMT 2012 - Resolve distribution error that caused .git to be shipped in the .tar.gz 0.83 Fri Jul 13 15:44:03 GMT 2012 - Only call stat() and tell() on a filehandle if fileno existed - Explicit tied() call on globs to avoid a 5.16 deprecation warning 0.82 Thu Jul 12 18:49:45 GMT 2012 - Test scalar @array rather than deprecated defined @array (Sebastian Stumpf) 0.81 Thu Apr 19 11:03:38 PDT 2012 - Patch from https://rt.cpan.org/Public/Bug/Display.html?id=74826 - YAML::Mo uses Safe Mo https://rt.cpan.org/Public/Bug/Display.html?id=76664 0.8 Fri Feb 10 12:56:08 PST 2012 - Patch from https://rt.cpan.org/Ticket/Display.html?id=73702 - Make YAML::Node subclass YAML::Mo::Object as well as Exporter (MSTROUT) 0.79 Wed Feb 8 17:25:55 PST 2012 - Peter Scott and others noticed Mo::xxx causing problems on newer perls. Removed xxx for now. 0.78 Sun Jan 1 23:53:57 PST 2012 - Apply patch from ANDK++ to deal with B::Deparse changes. 0.77 Thu Sep 29 18:28:25 CEST 2011 - Add $VERSION back to all modules. - Released from Liz++ and Wendy++ garage attic! 0.76 Wed Sep 28 12:05:08 CEST 2011 - Removed YAML::import per mst. 0.75 Tue Sep 27 00:46:19 CEST 2011 - Switch to Mo for OO (YAML::Mo) - use_test_base in Makefile.PL. 0.74 Sun Sep 25 22:05:05 CEST 2011 - Switch to Module::Package - Removed extra $VERSION lines from submodules - Released from Liz++ and Wendy++'s Tool Basement! 0.73 Tue Apr 19 20:14:59 EST 2011 - Apply ANDK's patch for 5.14.0 0.72 Wed Sep 1 11:54:00 AEST 2010 - Upgrade to Module::Install 1.00 - Upgraded author tests via new ADAMK release automation - Normalise Ingy's name to ASCII in Makefile.PL so that we don't have Unicode in our own META.yml 0.71 Sun Jan 3 12:25:00 AEST 2010 - Set file encoding to UTF-8 in LoadFile/DumpFile (RT#25434) by Olivier Mengue - We shouldn't have to care about 5.8.0. Since it's causing CPAN Testers failures, bump the minimum Perl to 5.8.1 0.7 Tue Aug 11 02:52:10 AEST 2009 - Updated Module::Install dependency to 0.91 - Bumping dependency to 5.8.0 but I think it's only in the test suite. However, I can't prove it. So if anyone wants 5.6 compatibility back you need to fix or rewrite the test suite. 0.69_02 Mon Aug 10 22:37:37 AEST 2009 - Developer $VERSION now has eval correction 0.69_01 Sun Jul 9 02:01:12 AEST 2009 - Added $VERSION to all modules - Removed the use of use base - Imported into the svn.ali.as repo 0.68 Thu Dec 4 01:00:44 PST 2008 - Used update Test::Base to ensure Filter::Util::Call 0.67 Mon Dec 1 02:34:21 PST 2008 - Add YAML::Any - Move ysh to YAML::Shell - Add doc section explaining YAML::Old 0.66 Thu Sep 27 01:37:16 PDT 2007 - Blessed code refs with LoadCode=0 still get blessed. rafl++ 0.65 Thu Jun 21 17:37:32 PDT 2007 - \z is really \0 - Speed up regexp loading. audreyt++ 0.64 Thu Jun 21 14:31:20 PDT 2007 - Better support for loading regexps. audreyt++ 0.63 Wed Jun 20 16:03:22 PDT 2007 - Don't emit nodes blessed into '' in the new tag scheme, and improve semantics of loading such nodes. - New support for dumping/loading regexps. 0.62 Mon Jul 3 15:41:20 PDT 2006 - Patch from rgs for Catalyst users 0.61 Sun Jul 2 15:25:08 CDT 2006 - New CGI.pm made test fail. 0.6 Fri Jun 30 21:55:55 CDT 2006 - Changed object tag format in non backwards compatible way - Removed support for folded scalar emission - Added new tests - Sync with YAML::Syck 0.58 Tue Feb 14 12:42:34 PST 2006 - Fixed bug reported by Slaven Rezic on 5.8.0 - Fixed a ysh bug reported on rt. 17589 0.57 Wed Feb 1 23:06:25 PST 2006 - Add obligatory '1;' to end of each module. 0.56 Mon Jan 30 10:26:33 PST 2006 - Add Module::Install::TestBase support 0.55 Sun Jan 29 19:03:35 PST 2006 - Load YAML::Node because Module::Build expects it to be loaded. We can undo this when Module::Build starts loading it for itself. 0.54 Sun Jan 29 17:28:46 PST 2006 - Remove dependency on Class::Spiffy (and/or Spiffy). 0.53 Thu Jan 19 06:03:17 PST 2006 - Depend on Class::Spiffy instead of Spiffy. No source filtering. 0.52 Wed Jan 18 14:25:24 PST 2006 - Error in Spiffy-0.26 causing problems. Require 0.27 0.51 Sat Jan 14 17:09:09 GMT 2006 - Tests pass on win32 and cygwin - Don't gpg sign the distribution tarball 0.5 Sun Dec 25 11:09:18 PST 2005 - Major refactoring of YAML.pm - Completely OO with same old functional UI - Support the $YAML::Stringify option which most be on for objects to get stringified. Otherwise dump the object. - Can dump overloaded objects now. - Completely refactor test suite using Test::Base - Create Test::YAML - Make test framework compatible with YAML::Syck - Test-Base-0.45 - Reviewed all rt bugs. fixed many - Reviewed all emailed bugs. Fixed many. - Helped audrey complete YAML::Syck and worked on interoperability issues - Test well known yaml docs like svk and META.yml - Eliminate unsafe string evals - Can use with autouse. Spiffy-0.25 - Support YAML::Marshall to help classes that want to do their own marshalling - Make objects tags configurable - -M option for ysh to test other implementations like YAML::Syck 0.39 Tue Apr 12 15:28:40 PDT 2005 - Need newer Test::More or tests hang. 0.38 Thu Mar 31 01:43:21 PST 2005 - Deleted Spiffy -XXX artifact :( 0.37 Thu Mar 31 01:56:24 CST 2005 - All the edge cases with hash key dumping (commas, [], {}, etc) should now be covered 0.36 Sun Jan 30 21:00:28 PST 2005 - Slight changes to the way things are dumped. - Fixed bugs dumping "foo\nbar" for svk acceptance 0.32 Sat May 11 19:54:52 EDT 2002 - Moved error handling into YAML::Error - Enabled UseAliases=0 to mean skip Dump checking of alias nodes. - Changed Defaults. Indent=2. CompressSeries=1. - Deprecated Store() in favor of Dump() - Refactored test suite - Added key list to SortKeys - Added ForceBlock option - CONTROL-D can be used to terminate ysh. Ryan King will be happy. - Added the ability to direct STDIN to the ysh. 0.27 Tue Jan 15 01:46:18 PST 2002 - Make '-' chomp all trailing newlines - Change folded indicator from '^' to ']'. - YAC-010 Allow a map as a sequence entry to be collapsed to one line. - Changed the nextline scalar indicators. '^' means folded, and escaping ('\') can be applied to folded or blocks. Chomping is now '-'. - YAC-013. Generic indentation. This change was big, ugly, hard and it really made my brain hurt. But look. It works! :) - YAC-012. Added ability to put comments anywhere, at any indentation level. - Added $YAML::UseBlock and $YAML::UseFold - Changed $YAML::PerlCode to $YAML::UseCode - Added $YAML::Indent config option - YAC-012. Handled all Throwaway Issues. Blank lines and comments can be used anywhere, and they will work appropriately. - Converted Changes file (this file) to use YAML - AC-016. Support "assumed header" (--- #YAML:1.0) if no header. - Added $YAML::UseBlock option - YAC-015. Support Top Level Inline nodes - Added testing for Store to test suite. (Now there's no excuse not to create lot's of new tests. :) 0.26 Wed Jan 9 21:13:45 PST 2002 - Detect implicit scalars more correctly - Refactor test suite - Proofed documentation - Fix ysh doc. Document flags in the pod. - Move test code out of YAML.pm and into testlib - Change directives to use # - Parse regexes - YAC-017. Change !perl/ syntax - Emit regexes - support 'ysh -v' and 'ysh -V' and 'ysh -h' - Support blessed globs - Make ysh installable - Parse CODE leaves - Support blessed scalars - Test warnings as well as errors - Use B::Deparse to serialize code - Change 'implicit' to 'simple' 0.25 Wed Dec 19 02:34:38 PST 2001 - Initial module shipped to CPAN 0.01 Mon Oct 15 19:18:49 2001 - original version; created by h2xs 1.19 YAML-1.31/LICENSE0000644000175000017500000004365314543037225011723 0ustar ingyingyThis software is copyright (c) 2023 by Ingy döt Net. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2023 by Ingy döt Net. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2023 by Ingy döt Net. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End YAML-1.31/META.json0000644000175000017500000000311014543037225012317 0ustar ingyingy{ "abstract" : "YAML Ain't Markup Language\u2122", "author" : [ "Ingy d\u00f6t Net " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.030, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "YAML", "no_index" : { "directory" : [ "example", "inc", "t", "xt" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "perl" : "v5.8.1" } }, "test" : { "requires" : { "Encode" : "0", "Test::Deep" : "0", "Test::More" : "0.88", "Test::YAML" : "1.05" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/ingydotnet/yaml-pm/issues" }, "homepage" : "https://github.com/ingydotnet/yaml-pm", "repository" : { "type" : "git", "url" : "https://github.com/ingydotnet/yaml-pm.git", "web" : "https://github.com/ingydotnet/yaml-pm" } }, "version" : "1.31", "x_generated_by_perl" : "v5.28.0", "x_serialization_backend" : "Cpanel::JSON::XS version 4.06", "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later" } YAML-1.31/xt/0000755000175000017500000000000014543037225011336 5ustar ingyingyYAML-1.31/xt/pmv.t0000644000175000017500000000132414543037225012325 0ustar ingyingy#!/usr/bin/perl # Test that our declared minimum Perl version matches our syntax use strict; BEGIN { $| = 1; $^W = 1; } my @MODULES = ( 'Perl::MinimumVersion 1.25', 'Test::MinimumVersion 0.101080', ); # Don't run tests for installs use Test::More; unless ( $ENV{AUTOMATED_TESTING} or $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } # Load the testing modules foreach my $MODULE ( @MODULES ) { eval "use $MODULE"; if ( $@ ) { $ENV{RELEASE_TESTING} ? die( "Failed to load required release-testing module $MODULE" ) : plan( skip_all => "$MODULE not available for testing" ); } } all_minimum_version_from_metayml_ok(); YAML-1.31/xt/meta.t0000644000175000017500000000111514543037225012447 0ustar ingyingy#!/usr/bin/perl # Test that our META.yml file matches the current specification. use strict; BEGIN { $| = 1; $^W = 1; } my $MODULE = 'Test::CPAN::Meta 0.17'; # Don't run tests for installs use Test::More; unless ( $ENV{AUTOMATED_TESTING} or $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } # Load the testing module eval "use $MODULE"; if ( $@ ) { $ENV{RELEASE_TESTING} ? die( "Failed to load required release-testing module $MODULE" ) : plan( skip_all => "$MODULE not available for testing" ); } meta_yaml_ok(); YAML-1.31/xt/pod.t0000644000175000017500000000124114543037225012303 0ustar ingyingy#!/usr/bin/perl # Test that the syntax of our POD documentation is valid use strict; BEGIN { $| = 1; $^W = 1; } my @MODULES = ( 'Pod::Simple 3.14', 'Test::Pod 1.44', ); # Don't run tests for installs use Test::More; unless ( $ENV{AUTOMATED_TESTING} or $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } # Load the testing modules foreach my $MODULE ( @MODULES ) { eval "use $MODULE"; if ( $@ ) { $ENV{RELEASE_TESTING} ? die( "Failed to load required release-testing module $MODULE" ) : plan( skip_all => "$MODULE not available for testing" ); } } all_pod_files_ok(); YAML-1.31/t/0000755000175000017500000000000014543037225011146 5ustar ingyingyYAML-1.31/t/errors.t0000644000175000017500000001545714543037225012663 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 39; $^W = 1; use YAML::Error; filters { error => 'regexp', yaml => [mutate_yaml => 'yaml_load_error_or_warning' => 'check_yaml'], perl => 'perl_eval_error_or_warning', }; run_like('yaml' => 'error'); run_like('perl' => 'error'); sub mutate_yaml { s/\Q<%CNTL-G%>\E/\007/; chomp if /msg_no_newline/; } sub check_yaml { my $yaml = shift; return $yaml unless ref($yaml); print "YAML actually loaded:\n" . Data::Dumper::Dumper($yaml); return ''; } __DATA__ === YAML_PARSE_ERR_BAD_CHARS +++ error: YAML_PARSE_ERR_BAD_CHARS +++ yaml # Test msg_bad_chars --- - foo # The next line contains an escape character - bell -><%CNTL-G%><- === YAML_PARSE_ERR_BAD_MAJOR_VERSION +++ error: YAML_PARSE_ERR_BAD_MAJOR_VERSION +++ yaml # Test msg_bad_major_version --- - one - two --- #YAML:2.0 - foo - bar === YAML_PARSE_WARN_BAD_MINOR_VERSION +++ error: YAML_PARSE_WARN_BAD_MINOR_VERSION +++ yaml # Test msg_bad_minor_version --- - one - two --- #YAML:1.5 - foo - bar === YAML_PARSE_WARN_MULTIPLE_DIRECTIVES +++ error: YAML_PARSE_WARN_MULTIPLE_DIRECTIVES +++ yaml # Test msg_multiple_directives --- #YAML:1.0 #YAML:1.0 - foo --- #FOO:2 #FOO:3 - bar === YAML_PARSE_ERR_TEXT_AFTER_INDICATOR +++ error: YAML_PARSE_ERR_TEXT_AFTER_INDICATOR +++ yaml # Test msg_text_after_indicator --- - > This is OK. - > But this is not - This is OK === YAML_PARSE_ERR_NO_ANCHOR +++ error: YAML_PARSE_ERR_NO_ANCHOR +++ yaml # Test msg_no_anchor --- - &moo foo - bar - *star - &star far === YAML_PARSE_ERR_INCONSISTENT_INDENTATION +++ error: YAML_PARSE_ERR_INCONSISTENT_INDENTATION +++ yaml --- {foo: bar} - foo - bar === YAML_PARSE_ERR_SINGLE_LINE +++ error: YAML_PARSE_ERR_SINGLE_LINE +++ yaml --- - "foo" bar === YAML_PARSE_ERR_BAD_ANCHOR +++ error: YAML_PARSE_ERR_BAD_ANCHOR +++ yaml --- - &X=y 42 === YAML_PARSE_ERR_BAD_ANCHOR +++ error: YAML_PARSE_ERR_BAD_ANCHOR +++ yaml --- - & #--- #error: YAML_PARSE_ERR_BAD_NODEX #load: | #--- #error: YAML_PARSE_ERR_BAD_EXPLICITX #load: | # I don't think this one can ever happen (yet) #--- #error: YAML_DUMP_USAGE_DUMPCODE #code: | # local $YAML::DumpCode = [0]; # Dump(sub { $foo + 42 }); === YAML_LOAD_ERR_FILE_INPUT +++ error: YAML_LOAD_ERR_FILE_INPUT +++ perl LoadFile('fooxxx'); # XXX - Causing bus error!?!? #--- #error: YAML_DUMP_ERR_FILE_CONCATENATE #code: | # DumpFile(">> YAML.pod", 42); === YAML_DUMP_ERR_FILE_OUTPUT +++ error: YAML_DUMP_ERR_FILE_OUTPUT +++ perl Test::YAML::DumpFile("x/y/z.yaml", 42); === YAML_DUMP_ERR_NO_HEADER +++ error: YAML_DUMP_ERR_NO_HEADER +++ perl local $YAML::UseHeader = 0; Test::YAML::Dump(42); === YAML_DUMP_ERR_NO_HEADER +++ error: YAML_DUMP_ERR_NO_HEADER +++ perl local $YAML::UseHeader = 0; Test::YAML::Dump([]); === YAML_DUMP_ERR_NO_HEADER +++ error: YAML_DUMP_ERR_NO_HEADER +++ perl local $YAML::UseHeader = 0; Test::YAML::Dump({}); #--- #error: xYAML_DUMP_WARN_BAD_NODE_TYPE #code: | # # #--- #error: YAML_EMIT_WARN_KEYS #code: | # # #--- #error: YAML_DUMP_WARN_DEPARSE_FAILED #code: | # # #--- #error: YAML_DUMP_WARN_CODE_DUMMY #code: | # Dump(sub{ 42 }); === YAML_PARSE_ERR_MANY_EXPLICIT +++ error: YAML_PARSE_ERR_MANY_EXPLICIT +++ yaml --- - !foo !bar 42 === YAML_PARSE_ERR_MANY_IMPLICIT +++ error: YAML_PARSE_ERR_MANY_IMPLICIT +++ yaml --- - ! ! "42" === YAML_PARSE_ERR_MANY_ANCHOR +++ error: YAML_PARSE_ERR_MANY_ANCHOR +++ yaml --- - &foo &bar 42 === YAML_PARSE_ERR_ANCHOR_ALIAS +++ error: YAML_PARSE_ERR_ANCHOR_ALIAS +++ yaml --- - &bar *foo === YAML_PARSE_ERR_BAD_ALIAS +++ error: YAML_PARSE_ERR_BAD_ALIAS +++ yaml --- - *foo=bar === YAML_PARSE_ERR_BAD_ALIAS +++ error: YAML_PARSE_ERR_BAD_ALIAS +++ yaml --- - * === YAML_PARSE_ERR_MANY_ALIAS +++ error: YAML_PARSE_ERR_MANY_ALIAS +++ yaml --- - *foo *bar === YAML_LOAD_ERR_NO_CONVERT +++ SKIP Actually this should load into a ynode... +++ error: YAML_LOAD_ERR_NO_CONVERT +++ yaml --- - !foo shoe === YAML_LOAD_ERR_NO_DEFAULT_VALUE +++ error: YAML_LOAD_ERR_NO_DEFAULT_VALUE +++ yaml --- - !perl/ref foo: bar #--- #error: YAML_LOAD_ERR_NON_EMPTY_STRING #load: | # --- # - !map foo #--- #error: YAML_LOAD_ERR_NON_EMPTY_STRING #load: | # --- # - !seq foo #--- #error: YAML_LOAD_ERR_BAD_MAP_TO_SEQ #load: | # --- !seq # 0: zero # won: one # 2: two # 3: three #--- #error: YAML_LOAD_ERR_BAD_GLOB #load: | # # #--- #error: YAML_LOAD_ERR_BAD_REGEXP #load: | # # === YAML_LOAD_ERR_BAD_MAP_ELEMENT +++ error: YAML_LOAD_ERR_BAD_MAP_ELEMENT +++ yaml --- foo: bar bar === YAML_LOAD_WARN_DUPLICATE_KEY +++ error: YAML_LOAD_WARN_DUPLICATE_KEY +++ yaml --- foo: bar bar: boo foo: baz boo: bah === Test duplicate key message +++ error: YAML Warning: Duplicate map key 'foo' found. Ignoring. +++ yaml --- foo: bar bar: boo foo: baz boo: bah === YAML_LOAD_ERR_BAD_SEQ_ELEMENT +++ error: YAML_LOAD_ERR_BAD_SEQ_ELEMENT +++ yaml --- - 42 foo === YAML_PARSE_ERR_INLINE_MAP +++ error: YAML_PARSE_ERR_INLINE_MAP +++ yaml --- - {foo:bar} === YAML_PARSE_ERR_INLINE_SEQUENCE +++ error: YAML_PARSE_ERR_INLINE_SEQUENCE +++ yaml --- - [foo bar, baz === YAML_PARSE_ERR_BAD_DOUBLE +++ error: YAML_PARSE_ERR_BAD_DOUBLE +++ yaml --- - "foo baz === YAML_PARSE_ERR_BAD_SINGLE +++ error: YAML_PARSE_ERR_BAD_SINGLE +++ yaml --- - 'foo bar === YAML_PARSE_ERR_BAD_INLINE_IMPLICIT +++ error: YAML_PARSE_ERR_BAD_INLINE_IMPLICIT +++ yaml --- - [^gold] === YAML_PARSE_ERR_BAD_IMPLICIT +++ error: YAML_PARSE_ERR_BAD_IMPLICIT +++ yaml --- ! > - 4 foo bar #--- #error: xYAML_PARSE_ERR_INDENTATION #load: | # --- === YAML_PARSE_ERR_INCONSISTENT_INDENTATION +++ error: YAML_PARSE_ERR_INCONSISTENT_INDENTATION +++ yaml --- foo: bar bar: baz #--- #error: xYAML_LOAD_WARN_UNRESOLVED_ALIAS #load: | # --- # foo: *bar # === YAML_LOAD_WARN_NO_REGEXP_IN_REGEXP # +++ error: YAML_LOAD_WARN_NO_REGEXP_IN_REGEXP # +++ yaml # --- # - !perl/regexp: # foo: bar # # === YAML_LOAD_WARN_BAD_REGEXP_ELEM # +++ error: YAML_LOAD_WARN_BAD_REGEXP_ELEM # +++ yaml # --- # - !perl/regexp: # REGEXP: foo # foo: bar === YAML_LOAD_WARN_GLOB_NAME +++ error: YAML_LOAD_WARN_GLOB_NAME +++ yaml --- - !perl/glob: foo: bar #--- #error: xYAML_LOAD_WARN_PARSE_CODE #load: | # --- #--- #error: YAML_LOAD_WARN_CODE_DEPARSE #load: | # --- # - !perl/code | # sub { "foo" } #--- #error: xYAML_EMIT_ERR_BAD_LEVEL #code: # # #--- #error: YAML_PARSE_WARN_AMBIGUOUS_TAB #load: | # --- # - | # foo # bar === YAML_LOAD_WARN_BAD_GLOB_ELEM +++ error: YAML_LOAD_WARN_BAD_GLOB_ELEM +++ yaml --- - !perl/glob: NAME: foo bar: SHAME === YAML_PARSE_ERR_ZERO_INDENT +++ error: YAML_PARSE_ERR_ZERO_INDENT +++ yaml --- - |0 foo === YAML_PARSE_ERR_NONSPACE_INDENTATION +++ error: YAML_PARSE_ERR_NONSPACE_INDENTATION +++ yaml --- some: data-preceded-with-tab: abc === YAML_PARSE_ERR_INCONSISTENT_INDENTATION +++ error: YAML_PARSE_ERR_INCONSISTENT_INDENTATION +++ yaml --- a: b: - 1 - 2 YAML-1.31/t/pugs-objects.t0000644000175000017500000000066014543037225013742 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 2; local $YAML::LoadBlessed; $YAML::LoadBlessed = 1; { no warnings 'once'; $Foo::Bar::ClassTag = '!pugs/object:Foo::Bar'; $YAML::TagClass->{'!pugs/object:Foo::Bar'} = 'Foo::Bar'; } no_diff; run_roundtrip_nyn('dumper'); __DATA__ === Turn Perl object to Pugs object +++ perl: bless { 'a'..'d' }, 'Foo::Bar'; +++ yaml --- !!pugs/object:Foo::Bar a: b c: d YAML-1.31/t/numify.t0000644000175000017500000000170114543037225012641 0ustar ingyingyuse Test::More tests => 6; use YAML (); use B; my $yaml = <<'EOM'; int: 23 float: 3.14 exp: 1e-5 EOM my $data1 = do { local $YAML::Numify = 1; YAML::Load($yaml); }; my $data2 = YAML::Load($yaml); my $int1 = B::svref_2object(\$data1->{int})->FLAGS & (B::SVp_IOK | B::SVp_NOK); my $int2 = B::svref_2object(\$data2->{int})->FLAGS & (B::SVp_IOK | B::SVp_NOK); my $float1 = B::svref_2object(\$data1->{float})->FLAGS & (B::SVp_IOK | B::SVp_NOK); my $float2 = B::svref_2object(\$data2->{float})->FLAGS & (B::SVp_IOK | B::SVp_NOK); my $exp1 = B::svref_2object(\$data1->{exp})->FLAGS & (B::SVp_IOK | B::SVp_NOK); my $exp2 = B::svref_2object(\$data2->{exp})->FLAGS & (B::SVp_IOK | B::SVp_NOK); ok($int1, "int with \$YAML::Numify"); ok(! $int2, "int without \$YAML::Numify"); ok($float1, "float with \$YAML::Numify"); ok(! $float2, "float without \$YAML::Numify"); ok($exp1, "exp with \$YAML::Numify"); ok(! $exp2, "exp without \$YAML::Numify"); done_testing; YAML-1.31/t/load-works.t0000644000175000017500000000043714543037225013421 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML; filters { perl => 'eval', yaml => 'yaml_load', }; run_is_deeply; __DATA__ === A one key hash +++ perl +{foo => 'bar'} +++ yaml --- foo: bar === empty hashes +++ perl +{foo1 => undef, foo2 => undef} +++ yaml foo1: foo2: YAML-1.31/t/rt-90593.t0000644000175000017500000000063114543037225012447 0ustar ingyingy# https://rt.cpan.org/Public/Bug/Display.html?id=90593 use Test::More; if ($] < 5.010000) { plan skip_all => "Skip old perls"; } else { plan tests => 2; } use YAML; use constant LENGTH => 1000000; $SIG{__WARN__} = sub { die @_ }; my $yaml = 'x: "' . ('x' x LENGTH) . '"' . "\n"; my $hash = Load $yaml; is ref($hash), 'HASH', 'Loaded a hash'; is length($hash->{x}), LENGTH, 'Long scalar loaded'; YAML-1.31/t/TestYAMLBase.pm0000644000175000017500000000024514543037225013702 0ustar ingyingypackage TestYAMLBase; sub new { my $self = bless {}, shift; while (my ($k, $v) = splice @_, 0, 2) { $self->{$k} = $v; } return $self; } 1; YAML-1.31/t/test.t0000644000175000017500000000014714543037225012314 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 1; pass('TestYAML framework loads'); YAML-1.31/t/regexp.t0000644000175000017500000000422414543037225012627 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 12; use YAML(); use Encode; no warnings 'once'; local $YAML::LoadBlessed = 1; my $m_xis = "m-xis"; my $_xism = "-xism"; if (qr/x/ =~ /\(\?\^/){ $m_xis = "^m"; $_xism = "^"; } my @blocks = blocks; my $block = $blocks[0]; $YAML::UseCode = 1; my $hash = YAML::Load($block->yaml); is $hash->{key}, "(?$m_xis:foo\$)", 'Regexps load'; is YAML::Dump(eval $block->perl), <<"...", 'Regexps dump'; --- key: !!perl/regexp (?$m_xis:foo\$) ... my $re = $hash->{key}; is ref($re), 'Regexp', 'The regexp is a Regexp'; like "Hello\nBarfoo", $re, 'The regexp works'; #------------------------------------------------------------------------------- $block = $blocks[1]; $hash = YAML::Load($block->yaml); is $hash->{key}, "(?$m_xis:foo\$)", 'Regexps load'; # XXX Dumper can't detect a blessed regexp # is YAML::Dump(eval $block->perl), <<"...", 'Regexps dump'; # --- # key: !!perl/regexp (?$m_xis:foo\$) # ... $re = $hash->{key}; is ref($re), 'Classy', 'The regexp is a Classy :('; # XXX Test more doesn't think a blessed regexp is a regexp (for like) # like "Hello\nBarfoo", $re, 'The regexp works'; ok(("Hello\nBarfoo" =~ $re), 'The regexp works'); #------------------------------------------------------------------------------- $block = $blocks[2]; $hash = YAML::Load($block->yaml); is $hash->{key}, "(?$_xism:foo\$)", 'Regexps load'; is YAML::Dump(eval $block->perl), <<"...", 'Regexps dump'; --- key: !!perl/regexp (?$_xism:foo\$) ... $re = $hash->{key}; is ref($re), 'Regexp', 'The regexp is a Regexp'; like "Barfoo", $re, 'The regexp works'; my $yaml = decode_utf8 q{re : !!perl/regexp OK}; $re = Load $yaml; $yaml = Dump $re; my $compare = $yaml; for (1 .. 5) { $re = Load $yaml; $yaml = Dump $re; } cmp_ok($yaml, 'eq', $compare, "Regexp multiple roundtrip does not grow"); __END__ === A regexp with flag +++ yaml --- key: !!perl/regexp (?m-xis:foo$) +++ perl +{key => qr/foo$/m} === A blessed rexexp +++ yaml --- key: !!perl/regexp:Classy (?m-xis:foo$) +++ perl +{key => bless(qr/foo$/m, 'Classy')} === A regexp with no flag +++ yaml --- key: !!perl/regexp (?-xism:foo$) +++ perl +{key => qr/foo$/} YAML-1.31/t/references.t0000644000175000017500000000126614543037225013461 0ustar ingyingyuse lib 'inc'; use Test::YAML tests => 10; no_diff; run_yaml_tests; __DATA__ === A scalar ref +++ perl: \ 42 +++ yaml --- !!perl/ref =: 42 === A ref to a scalar ref +++ perl: \\ "yellow" +++ yaml --- !!perl/ref =: !!perl/ref =: yellow === A ref to a ref to a scalar ref +++ perl: \\\ 123 +++ yaml --- !!perl/ref =: !!perl/ref =: !!perl/ref =: 123 === A blessed container reference +++ perl my $array_ref = [ 1, 3, 5]; my $container_ref = \ $array_ref; bless $container_ref, 'Wax'; +++ yaml --- !!perl/ref:Wax =: - 1 - 3 - 5 === A blessed scalar reference +++ perl my $scalar = "omg"; my $scalar_ref = \ $scalar; bless $scalar_ref, 'Wax'; +++ yaml --- !!perl/scalar:Wax omg YAML-1.31/t/dump-blessed.t0000644000175000017500000000137214543037225013722 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 2; package Foo::Bar; use TestYAMLBase; our @ISA = 'TestYAMLBase'; sub yaml_dump { my $self = shift; my $node = YAML::Node->new({ two => $self->{two} - 1, one => $self->{one} + 1, }, 'perl/Foo::Bar'); YAML::Node::ynode($node)->keys(['two', 'one']); return $node; } sub yaml_load { my $class = shift; my $node = shift; my $self = $class->new; $self->{one} = ($node->{one} - 1); $self->{two} = ($node->{two} + 1); return $self; } package main; no_diff; run_roundtrip_nyn; __END__ === Object class handles marshalling +++ perl my $fb = Foo::Bar->new(); $fb->{one} = 5; $fb->{two} = 3; $fb; +++ yaml --- !perl/Foo::Bar two: 2 one: 6 YAML-1.31/t/dump-nested.t0000644000175000017500000000756614543037225013576 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 20; no_diff(); run_roundtrip_nyn(); __DATA__ === +++ perl ['foo ' x 20] +++ yaml --- - 'foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo ' === +++ perl [q{YAML(tm) (rhymes with "camel") is a straightforward machine parsable data serialization format designed for human readability and interaction with scripting languages such as Perl and Python. YAML is optimized for data serialization, configuration settings, log files, Internet messaging and filtering. YAML(tm) is a balance of the following design goals:}] +++ yaml --- - 'YAML(tm) (rhymes with "camel") is a straightforward machine parsable data serialization format designed for human readability and interaction with scripting languages such as Perl and Python. YAML is optimized for data serialization, configuration settings, log files, Internet messaging and filtering. YAML(tm) is a balance of the following design goals:' === +++ perl [q{It reads one character at a time, with the ability to push back any number of characters up to a maximum, and with nested mark() / reset() / unmark() functions. The input of the stream reader is any java.io.Reader. The output are characters. The parser (and event generator) The input of the parser are characters. These characters are directly fed into the functions that implement the different productions. The output of the parser are events, a well defined and small set of events.}] +++ yaml --- - |- It reads one character at a time, with the ability to push back any number of characters up to a maximum, and with nested mark() / reset() / unmark() functions. The input of the stream reader is any java.io.Reader. The output are characters. The parser (and event generator) The input of the parser are characters. These characters are directly fed into the functions that implement the different productions. The output of the parser are events, a well defined and small set of events. === +++ perl < 7; # testing trailing comments which were errors before run { my $block = shift; my @result = eval { Load($block->yaml) }; my $error1 = $@ || ''; if ( $error1 ) { # $error1 =~ s{line: (\d+)}{"line: $1 ($0:".($1+$test->{lines}{yaml}-1).")"}e; } my @expect = eval $block->perl; my $error2 = $@ || ''; if (my $errors = $error1 . $error2) { fail($block->description . $errors); next; } is_deeply( \@result, \@expect, $block->description, ) or do { require Data::Dumper; diag("Wanted: ".Data::Dumper::Dumper(\@expect)); diag("Got: ".Data::Dumper::Dumper(\@result)); } }; __DATA__ === Comment after inline seq +++ yaml --- seq: [314] #comment +++ perl { seq => [314] } === Comment after inline map +++ yaml --- map: {x: y} #comment +++ perl { map => { x => 'y' }, } === Comment after literal block scalar indicator +++ yaml --- - |- #comment +++ perl [''] === Comment after folded block scalar indicator +++ yaml --- - >- #comment +++ perl [''] === Comment after top level literal block scalar indicator +++ yaml --- |- #comment +++ perl '' === Comment after double quoted string +++ yaml --- quoted: "string" #comment +++ perl { quoted => 'string' } === Comment after single quoted string +++ yaml --- quoted: 'string' #comment +++ perl { quoted => 'string' } YAML-1.31/t/global-api.t0000644000175000017500000000140414543037225013341 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use lib 'inc'; use Test::YAML(); BEGIN { @Test::YAML::EXPORT = grep { not /^(Dump|Load)(File)?$/ } @Test::YAML::EXPORT; } use TestYAML tests => 4; use YAML; { no warnings qw'once redefine'; require YAML::Dumper; local *YAML::Dumper::dump = sub { return 'got to dumper' }; require YAML::Loader; local *YAML::Loader::load = sub { return 'got to loader' }; is Dump(\%ENV), 'got to dumper', 'Dump got to the business end'; is Load(\%ENV), 'got to loader', 'Load got to the business end'; is Dump(\%ENV), 'got to dumper', 'YAML::Dump got to the business end'; is Load(\%ENV), 'got to loader', 'YAML::Load got to the business end'; } YAML-1.31/t/dump-perl-types-512.t0000644000175000017500000000077614543037225014721 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use Test::More; BEGIN { if ( qr/x/ =~ /\(\?\^/ ){ plan skip_all => "test only for perls before v5.13.5-11-gfb85c04"; } } use TestYAML tests => 2; filters { perl => ['eval', 'yaml_dump'] }; no_diff; run_is ( perl => 'yaml' ); __DATA__ === Regular Expression +++ perl: qr{perfect match}; +++ yaml --- !!perl/regexp (?-xism:perfect match) === Regular Expression with newline +++ perl qr{perfect match}x; +++ yaml --- !!perl/regexp "(?x-ism:perfect\nmatch)" YAML-1.31/t/svk.t0000644000175000017500000000106414543037225012137 0ustar ingyingyuse strict; my $t; use lib ($t = -e 't' ? 't' : 'test'); use TestYAML tests => 3; my $test_file = "$t/svk-config.yaml"; my $node = LoadFile($test_file); is ref($node), 'HASH', "loaded svk file is a hash"; open IN, $test_file or die "Can't open $test_file for input: $!"; my $yaml_from_file = do {local $/; }; like $yaml_from_file, qr{^---\ncheckout: !perl/Data::Hierarchy\n}, "at least first two lines of file are right"; my $yaml_from_node = Dump($node); is Dump(Load($yaml_from_node)), Dump(Load($yaml_from_file)), "svk data roundtrips!";; YAML-1.31/t/dump-file.t0000644000175000017500000000105014543037225013211 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; my $t = -e 't' ? 't' : 'test'; use lib 'inc'; use Test::YAML(); BEGIN { @Test::YAML::EXPORT = grep { not /^(Dump|Load)(File)?$/ } @Test::YAML::EXPORT; } use TestYAML tests => 3; use YAML 'DumpFile'; ok defined &DumpFile, 'Dumpfile exported'; my $file = "$t/dump-file-$$.yaml"; DumpFile($file, [1..3]); ok -e $file, 'Output file exists'; open IN, $file or die $!; my $yaml = join '', ; close IN; is $yaml, <<'...', 'DumpFile YAML is correct'; --- - 1 - 2 - 3 ... unlink $file; YAML-1.31/t/load-slides.t0000644000175000017500000001302714543037225013536 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; # This tests the slides I used for YAPC 2002 use TestYAML tests => 28; run_load_passes(); __DATA__ === +++ yaml YAML design goals: - YAML documents are very readable by humans. - YAML interacts well with scripting languages. - YAML uses host languages native data structures. - YAML has a consistent information model. - YAML enables stream-based processing. - YAML is expressive and extensible. - YAML is easy to implement. === +++ yaml --- scripting languages: - Perl - Python - C - Java standards: - RFC0822 (MAIL) - RFC1866 (HTML) - RFC2045 (MIME) - RFC2396 (URI) others: - SOAP - XML - SAX === +++ yaml --- name: Benjamin rank: Private serial number: 1234567890 12:34 PM: My favorite time === +++ yaml --- - red - white - blue - pinko === +++ yaml --- Fruits: - Apples - Tomatoes Veggies: - Spinach - Broccoli Meats: - Burgers - Shrimp Household: - Candles - Incense - Toilet Duck === +++ yaml --- - - 3 - 5 - 7 - - 0 - 0 - 7 - - 9 - 1 - 1 === +++ yaml - Intro - Part 1: - Up - Down - Side to Side - Part 2: - Here - There - Underwear - Part 3: - The Good - The Bad - The Ingy === +++ yaml ## comment before document #--- #DIRECTIVE # comment #foo: bar # inline comment # #phone: number #555-1234 # ### Comment #fact: fiction #--- #blue: bird ## Comment === +++ yaml --- simple: look ma, no quotes quoted: - 'Single quoted. Like Perl, no escapes' - "Double quotes.\nLike Perl, has escapes" - | A YAML block scalar. Much like Perl's here-document. === +++ yaml #--- #simple key: simple value #this value: can span multiple lines # but the key cannot. it would need quotes #stuff: # - foo # - 42 # - 3.14 # - 192.168.2.98 # - m/^(.*)\// === +++ yaml #--- #'contains: colon': '$19.99' #or: ' value has leading/trailing whitespace ' #'key spans #lines': 'double ticks \ for ''escaping''' === +++ yaml #--- #The spec says: "The double quoted style variant adds escaping to the 'single quoted' style variant." # #like this: "null->\z newline->\n bell->\a #smiley->\u263a" # #self escape: "Brian \"Ingy\" Ingerson" === +++ yaml --- what is this: | is it: a YAML mapping or just: a string chomp me: |- sub foo { print "Love me do!"; } === +++ yaml --- #YAML:1.0 old doc: | --- #YAML:1.0 tools: - XML - XSLT new doc: | --- #YAML:1.0 tools: - YAML - cYATL === +++ yaml --- - > Copyright © 2001 Brian Ingerson, Clark Evans & Oren Ben-Kiki, all rights reserved. This document may be freely copied provided that it is not modified. Next paragraph. - foo === +++ yaml --- The YAML Specification starts out by saying: > YAML(tm) (rhymes with "camel") is a straightforward machine parsable data serialization format designed for human readability and interaction with scripting languages such as Perl and Python. YAML documents are very readable by humans. YAML interacts well with scripting languages. YAML uses host languages' native data structures. Please join us, the mailing list is at SourceForge. === +++ yaml --- ? >+ Even a key can: 1) Be Folded 2) Have Wiki : cool, eh? === +++ yaml --- Hey Jude: &chorus - na, na, na, - &4 na, na, na, na, - *4 - Hey Jude. - *chorus === +++ yaml headerless: first document --- #YAML:1.0 #TAB:NONE --- > folded top level scalar --- &1 recurse: *1 --- - simple header === +++ yaml #--- #seq: [ 14, 34, 55 ] #map: {purple: rain, blue: skies} #mixed: {sizes: [9, 11], shapes: [round]} #span: {players: [who, what, I don't know], # positions: [first, second, third]} === +++ yaml ## Inline sequences make data more compact #--- #- [3, 5, 7] #- [0, 0, 7] #- [9, 1, 1] # ## Above is equal to below #--- [[3, 5, 7], [0, 0, 7], [9, 1, 1]] # ## A 3D Matrix #--- #- [[3, 5, 7], [0, 0, 7], [9, 1, 1]] #- [[0, 0, 7], [9, 1, 1], [3, 5, 7]] #- [[9, 1, 1], [3, 5, 7], [0, 0, 7]] === +++ yaml --- ? - Kane - Kudra : engaged [Damian, Dominus]: engaging === +++ yaml #same: # - 42 # - !int 42 # - !yaml.org/int 42 # - !http://yaml.org/int 42 #perl: # - !perl/Foo::Bar {} # - !perl.yaml.org/Foo::Bar {} # - !http://perl.yaml.org/Foo::Bar {} === +++ yaml #--- #- 42 # integer #- -3.14 # floating point #- 6.02e+23 # scientific notation #- 0xCAFEBABE # hexadecimal int #- 2001-09-11 # ISO8601 time #- '2001-09-11' # string #- + # boolean true #- (false) # alternate boolean #- ~ # null (undef in Perl) #- 123 Main St # string === +++ yaml #--- #- !str YAML, YAML, YAML! #- !int 42 #- !float 0.707 #- !time 2001-12-14T21:59:43.10-05:00 #- !bool 1 #- !null 0 #- !binary MWYNG84BwwEeECcgggoBADs= === +++ yaml #--- #- !perl/Foo::Bar {} # hash-based class #- !perl/@Foo::Bar [] # array-based class #- !perl/$Foo::Bar '' # scalar-based class #- !perl/glob: # typeglob #- !perl/code: # code reference #- !perl/ref: # hard reference #- !perl/regexp: # regular expression #- !perl/regexp:Foo::Bar # blessed regexp === +++ yaml --- #YAML:1.0 NAME: AddressEntry HASH: - NAME: Name HASH: - NAME: First - NAME: Last OPTIONAL: yes - NAME: EmailAddresses ARRAY: yes - NAME: Phone ARRAY: yes HASH: - NAME: Type OPTIONAL: yes - NAME: Number === +++ yaml --- #YAML:1.0 AddressEntry: Name: First: Brian EmailAddresses: - ingy@CPAN.org - ingy@ttul.org Phone: - Type: Work Number: 604-333-4567 - Number: 843-444-5678 YAML-1.31/t/TestYAML.pm0000644000175000017500000000013614543037225013106 0ustar ingyingypackage TestYAML; use lib 'inc'; use Test::YAML -Base; $Test::YAML::YAML = 'YAML'; $^W = 1; YAML-1.31/t/author-pod-syntax.t0000644000175000017500000000045414543037225014744 0ustar ingyingy#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print qq{1..0 # SKIP these tests are for testing by the author\n}; exit } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); YAML-1.31/t/freeze-thaw.t0000644000175000017500000000136614543037225013562 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use lib 'inc'; use Test::YAML(); BEGIN { @Test::YAML::EXPORT = grep { not /^(Dump|Load)(File)?$/ } @Test::YAML::EXPORT; } use TestYAML tests => 9; use YAML qw(Dump Load freeze thaw); my $hash = { foo => 42, bar => 44 }; my $ice = freeze($hash); ok defined(&Dump), 'Dump exported'; ok defined(&Load), 'Load exported'; ok defined(&freeze), 'freeze exported'; ok defined(&thaw), 'thaw exported'; like $ice, qr{bar.*foo}s, 'freeze works'; is $ice, Dump($hash), 'freeze produces same thing as Dump'; my $melt = thaw($ice); is_deeply $melt, Load($ice), 'thaw produces same thing as Load'; is_deeply $melt, $hash, 'freeze/thaw makes a clone'; is ref($melt), 'HASH', 'Melted object really is a hash'; YAML-1.31/t/trailing-comments-content.t0000644000175000017500000000252014543037225016436 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 6; run { my $block = shift; my @result = eval { Load($block->yaml) }; my $error1 = $@ || ''; if ( $error1 ) { # $error1 =~ s{line: (\d+)}{"line: $1 ($0:".($1+$test->{lines}{yaml}-1).")"}e; } my @expect = eval $block->perl; my $error2 = $@ || ''; if (my $errors = $error1 . $error2) { fail($block->description . $errors); next; } is_deeply( \@result, \@expect, $block->description, ) or do { require Data::Dumper; diag("Wanted: ".Data::Dumper::Dumper(\@expect)); diag("Got: ".Data::Dumper::Dumper(\@result)); } }; __DATA__ === Comment after simple mapping value +++ yaml --- foo: val #comment val +++ perl { foo => "val" } === Comment after simple sequence value +++ yaml --- foo: - s2 #comment s2 +++ perl { foo => ['s2'] } === Comment after simple sequence value (2) +++ yaml --- - s2 #comment s1 +++ perl ['s2'] === Comment after simple top level scalar +++ yaml --- abc # comment abc +++ perl 'abc' === Comment after empty mapping value +++ yaml --- foo: #comment foo bar: #comment bar +++ perl { foo => undef, bar => undef } === Comment after empty sequence value +++ yaml --- foo: - # empty sequence value +++ perl { foo => [''] } YAML-1.31/t/dump-tests.t0000644000175000017500000001255614543037225013451 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 57; local $YAML::LoadBlessed; $YAML::LoadBlessed = 1; no_diff(); run_roundtrip_nyn('dumper'); __DATA__ === +++ perl [ "foo\nbar", "I like pie\nYou like pie\nWe all like pie" ] +++ yaml --- - "foo\nbar" - |- I like pie You like pie We all like pie === +++ perl {name => 'Ingy dot Net', rank => 'JAPH', 'serial number' => '8675309', }; +++ yaml --- name: Ingy dot Net rank: JAPH serial number: 8675309 === +++ perl {fruits => [qw(apples oranges pears)], meats => [qw(beef pork chicken)], vegetables => [qw(carrots peas corn)], } +++ yaml --- fruits: - apples - oranges - pears meats: - beef - pork - chicken vegetables: - carrots - peas - corn === +++ perl ['42', '43', '-44', '45'] +++ yaml --- - 42 - 43 - -44 - 45 === +++ perl [ 'foo bar', 'http://www.yaml.org', '12:34' ] +++ yaml --- - foo bar - http://www.yaml.org - 12:34 === +++ perl ('1', " foo ", "bar\n", [], {}) +++ yaml --- 1 --- ' foo ' --- "bar\n" --- [] --- {} === +++ perl '8\'-0" x 24" Lightweight' +++ yaml --- 8'-0" x 24" Lightweight === +++ perl bless {}, 'Foo::Bar' +++ yaml --- !!perl/hash:Foo::Bar {} === +++ perl bless {qw(foo 42 bar 43)}, 'Foo::Bar' +++ yaml --- !!perl/hash:Foo::Bar bar: 43 foo: 42 === +++ perl bless [], 'Foo::Bar' +++ yaml --- !!perl/array:Foo::Bar [] === +++ perl bless [map "$_",42..45], 'Foo::Bar' +++ yaml --- !!perl/array:Foo::Bar - 42 - 43 - 44 - 45 === +++ perl my $yn = YAML::Node->new({}, 'foo.com/bar'); $yn->{foo} = 'bar'; $yn->{bar} = 'baz'; $yn->{baz} = 'foo'; $yn +++ yaml --- !foo.com/bar foo: bar bar: baz baz: foo === +++ perl use YAML::Node; +++ no_round_trip +++ perl my $a = ''; bless \$a, 'Foo::Bark'; +++ yaml --- !!perl/scalar:Foo::Bark '' === Strings with nulls +++ perl "foo\0bar" +++ yaml --- "foo\0bar" === +++ no_round_trip XXX: probably a YAML.pm bug +++ perl &YAML::VALUE +++ yaml --- = === +++ perl my $ref = {foo => 'bar'}; [$ref, $ref] +++ yaml --- - &1 foo: bar - *1 === +++ perl no strict; package main; $joe_random_global = 42; @joe_random_global = (43, 44); *joe_random_global +++ yaml --- !!perl/glob: PACKAGE: main NAME: joe_random_global SCALAR: 42 ARRAY: - 43 - 44 === +++ perl no strict; package main; \*joe_random_global +++ yaml --- !!perl/ref =: !!perl/glob: PACKAGE: main NAME: joe_random_global SCALAR: 42 ARRAY: - 43 - 44 === +++ no_round_trip +++ perl my $foo = {qw(apple 1 banana 2 carrot 3 date 4)}; YAML::Bless($foo)->keys([qw(banana apple date)]); $foo +++ yaml --- banana: 2 apple: 1 date: 4 === +++ no_round_trip +++ perl use YAML::Node; my $foo = {qw(apple 1 banana 2 carrot 3 date 4)}; my $yn = YAML::Node->new($foo); YAML::Bless($foo, $yn)->keys([qw(apple)]); # red herring ynode($yn)->keys([qw(banana date)]); $foo +++ yaml --- banana: 2 date: 4 === +++ no_round_trip XXX: probably a test driver bug +++ perl my $joe_random_global = {qw(apple 1 banana 2 carrot 3 date 4)}; YAML::Bless($joe_random_global, 'TestBless'); return [$joe_random_global, $joe_random_global]; package TestBless; use YAML::Node; sub yaml_dump { my $yn = YAML::Node->new($_[0]); ynode($yn)->keys([qw(apple pear carrot)]); $yn->{pear} = $yn; return $yn; } +++ yaml --- - &1 apple: 1 pear: *1 carrot: 3 - *1 === +++ no_round_trip +++ perl use YAML::Node; my $joe_random_global = {qw(apple 1 banana 2 carrot 3 date 4)}; YAML::Bless($joe_random_global); my $yn = YAML::Blessed($joe_random_global); delete $yn->{banana}; $joe_random_global +++ yaml --- apple: 1 carrot: 3 date: 4 === +++ perl my $joe_random_global = \\\\\\\'42'; [ $joe_random_global, $$$$joe_random_global, $joe_random_global, $$$$$$$joe_random_global, $$$$$$$$joe_random_global ] +++ yaml --- - &1 !!perl/ref =: !!perl/ref =: !!perl/ref =: &2 !!perl/ref =: !!perl/ref =: !!perl/ref =: &3 !!perl/ref =: 42 - *2 - *1 - *3 - 42 === +++ perl local $YAML::Indent = 1; [{qw(foo 42 bar 44)}] +++ yaml --- - bar: 44 foo: 42 === +++ perl local $YAML::Indent = 4; [{qw(foo 42 bar 44)}] +++ yaml --- - bar: 44 foo: 42 === +++ perl [undef, undef] +++ yaml --- - ~ - ~ === +++ perl my $joe_random_global = []; push @$joe_random_global, $joe_random_global; bless $joe_random_global, 'XYZ'; $joe_random_global +++ yaml --- &1 !!perl/array:XYZ - *1 === +++ perl [ '23', '3.45', '123456789012345', ] +++ yaml --- - 23 - 3.45 - 123456789012345 === +++ perl {'foo: bar' => 'baz # boo', 'foo ' => ' monkey', } +++ yaml --- 'foo ': ' monkey' 'foo: bar': 'baz # boo' === +++ no_round_trip +++ perl $a = \\\\\\\\"foo"; $b = $$$$$a; ([$a, $b], [$b, $a]) +++ yaml --- - !!perl/ref =: !!perl/ref =: !!perl/ref =: !!perl/ref =: &1 !!perl/ref =: !!perl/ref =: !!perl/ref =: !!perl/ref =: foo - *1 --- - &1 !!perl/ref =: !!perl/ref =: !!perl/ref =: !!perl/ref =: foo - !!perl/ref =: !!perl/ref =: !!perl/ref =: !!perl/ref =: *1 === +++ no_round_trip XXX an AutoBless feature could make this rt +++ perl $a = YAML::Node->new({qw(a 1 b 2 c 3 d 4)}, 'ingy.com/foo'); YAML::Node::ynode($a)->keys([qw(d b a)]); $a; +++ yaml --- !ingy.com/foo d: 4 b: 2 a: 1 === +++ no_round_trip +++ perl $a = 'bitter buffalo'; bless \$a, 'Heart'; +++ yaml --- !!perl/scalar:Heart bitter buffalo === +++ perl { 'foo[bar]' => 'baz' } +++ yaml --- 'foo[bar]': baz YAML-1.31/t/marshall.t0000644000175000017500000000422314543037225013137 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 10; use strict; use warnings; #------------------------------------------------------------------------------- package Foo::Bar; BEGIN { require TestYAMLBase; @Foo::Bar::ISA = 'TestYAMLBase'; } use YAML::Marshall; sub yaml_dump { my $self = shift; my $array = []; for my $k (sort keys %$self) { push @$array, $k, $self->{$k}; } $self->yaml_node($array, 'perl/Foo::Bar'); } sub yaml_load { my $class = shift; my $node = shift; my $self = $class->new; %$self = @$node; return $self; } #------------------------------------------------------------------------------- package Bar::Baz; BEGIN { require TestYAMLBase; @Bar::Baz::ISA = 'TestYAMLBase'; } use YAML::Marshall 'random/object:bar.baz'; #------------------------------------------------------------------------------- package Baz::Foo; BEGIN { require TestYAMLBase; @Bar::Foo::ISA = 'TestYAMLBase'; } use YAML::Marshall; sub yaml_dump { my $self = shift; my $node = $self->SUPER::yaml_dump(@_); $node->{comment} = "Hi, Mom"; return $node; } sub yaml_load { my $class = shift; my $node = $class->SUPER::yaml_load(@_); delete $node->{comment}; return $node; } #------------------------------------------------------------------------------- package main; no_diff; run_roundtrip_nyn; is $main::BazFoo->{11}, 12, 'first key exists'; is $main::BazFoo->{13}, 14, 'second key exists'; ok not($main::BazFoo->{comment}), 'extra key not added'; __DATA__ === Serialize a hash object as a sequence +++ perl my $fb = Foo::Bar->new; $fb->{x} = 5; $fb->{y} = 'che'; [$fb]; +++ yaml --- - !perl/Foo::Bar - x - 5 - y - che === Use a non-standard tag +++ perl: bless {11 .. 14}, 'Bar::Baz'; +++ yaml --- !random/object:bar.baz 11: 12 13: 14 === super calls to mixins work +++ perl: bless {11 .. 14}, 'Baz::Foo'; +++ yaml --- !perl/Baz::Foo 11: 12 13: 14 comment: 'Hi, Mom' === yaml_dump doesn't mutate original hash +++ no_round_trip +++ perl: $main::BazFoo = bless {11 .. 14}, 'Baz::Foo'; +++ yaml --- !perl/Baz::Foo 11: 12 13: 14 comment: 'Hi, Mom' YAML-1.31/t/no-load-blessed.t0000644000175000017500000000441414543037225014306 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 11; use Test::Deep; use YAML (); my $unblessed = YAML::Load(<<"EOM"); --- !!perl/array:Foo [] EOM is(ref $unblessed, 'ARRAY', "No objects by default"); $YAML::LoadBlessed = 0; run { my $block = shift; my @result = eval { Load($block->yaml) }; my $error1 = $@ || ''; if ( $error1 ) { # $error1 =~ s{line: (\d+)}{"line: $1 ($0:".($1+$test->{lines}{yaml}-1).")"}e; } my @expect = eval $block->perl; my $error2 = $@ || ''; if (my $errors = $error1 . $error2) { fail($block->description . $errors); next; } cmp_deeply( \@result, \@expect, $block->description, ) or do { require Data::Dumper; diag("Wanted: ".Data::Dumper::Dumper(\@expect)); diag("Got: ".Data::Dumper::Dumper(\@result)); } }; { local $YAML::LoadCode = 1; my $data = YAML::Load(<<'EOM'); --- !!perl/code:Foo::Bar | { return $_[0] * 2 } EOM my $ref = ref $data; cmp_ok($ref, 'eq', 'CODE', "Coderef loaded, but not blessed"); my $result = $data->(2); cmp_ok($result, 'eq', 4, "Coderef works"); } { $main::foo = 23; my $data = YAML::Load(<<'EOM'); --- !!perl/glob:moose PACKAGE: main NAME: foo SCALAR: 42 EOM my $ref = ref $data; cmp_ok($main::foo, '==', 23, "Glob did not set variable"); } __DATA__ === an array of assorted junk +++ yaml --- # a private Perl XYZ object - !perl/XYZ {small: object} # an object containing objects - !perl/ABC [!perl/@DEF [a,b,c],!perl/GHI {do: re, mi: fa, so: la,ti: do}] +++ perl my $i = {small => 'object'}; my $j = [[qw(a b c)], {do => 're', mi => 'fa', so => 'la', ti => 'do'}, ]; [ $i, $j ] === !!perl/array:moose +++ yaml --- !!perl/array:moose - 1 +++ perl [ 1 ] === !!perl/hash:moose +++ yaml --- !!perl/hash:moose foo: bar +++ perl { foo => "bar" } === !!perl/ref:moose +++ yaml --- !!perl/ref:moose =: 1 +++ perl do { my $x = 1; \$x} === !!perl/scalar:moose +++ yaml --- !!perl/scalar:moose 1 +++ perl do { my $x = 1; \$x} === !!perl/regexp:moose +++ yaml --- !!perl/regexp:moose (?-xism:foo$) +++ perl qr{foo$} === !!perl/glob:moose +++ yaml --- !!perl/glob:moose PACKAGE: main NAME: foo SCALAR: 0 +++ perl *main::foo YAML-1.31/t/load-passes.t0000644000175000017500000000106514543037225013550 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 8; run_load_passes(); __DATA__ === Bug reported by Rich Morin +++ SKIP +++ yaml foo: - > This is a test. === Bug reported by audreyt +++ SKIP +++ yaml --- "\n\ \r" === +++ yaml --- foo: bar: baz: poo: bah === +++ yaml --- 42 === +++ yaml # comment --- 42 # comment === +++ yaml --- [1, 2, 3] === +++ yaml --- {foo: bar, bar: 42} === +++ yaml --- !foo.com/bar - 2 === +++ yaml --- &1 !foo.com/bar - 42 === +++ yaml --- - 40 - 41 - foof YAML-1.31/t/dump-code.t0000644000175000017500000000303314543037225013207 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 7; use YAML (); # [CPAN #74687] must load before B::Deparse for B::Deparse < 0.71 use B::Deparse; if (new B::Deparse -> coderef2text ( sub { no strict; 1; use strict; 1; }) =~ 'refs') { local $/; (my $data = ) =~ s/use strict/use strict 'refs'/g if $] < 5.015; if ($B::Deparse::VERSION > 0.67 and $B::Deparse::VERSION < 0.71) { # [CPAN #73702] $data =~ s/use warnings;/BEGIN {\${^WARNING_BITS} = "UUUUUUUUUUUU\\001"}/g; } open DATA, '<', \$data; } no_diff; run_roundtrip_nyn('dumper'); __DATA__ === a code ref +++ config local $YAML::DumpCode = 1; +++ perl package main; return sub { 'Something at least 30 chars' }; +++ yaml --- !!perl/code | { use warnings; use strict; 'Something at least 30 chars'; } === an array of the same code ref +++ config local $YAML::DumpCode = 1; +++ perl package main; my $joe_random_global = sub { 'Something at least 30 chars' }; [$joe_random_global, $joe_random_global, $joe_random_global]; +++ yaml --- - &1 !!perl/code | { use warnings; use strict; 'Something at least 30 chars'; } - *1 - *1 === dummy code ref +++ config local $YAML::DumpCode = 0; +++ perl sub { 'Something at least 30 chars' } +++ yaml --- !!perl/code '{ "DUMMY" }' === blessed code ref +++ config local $YAML::DumpCode = 1; +++ perl package main; bless sub { 'Something at least 30 chars' }, "Foo::Bar"; +++ no_round_trip +++ yaml --- !!perl/code:Foo::Bar | { use warnings; use strict; 'Something at least 30 chars'; } YAML-1.31/t/basic-tests.t0000644000175000017500000000214514543037225013556 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 4; filters { yaml => [yaml => 'dumper'], perl => [strict => eval => 'dumper'], }; run_is yaml => 'perl'; __END__ === A simple map +++ yaml --- one: foo two: bar three: baz +++ perl +{qw(one foo two bar three baz)} === Common String Types +++ yaml --- one: simple string two: 42 three: '1 Single Quoted String' four: "YAML's Double Quoted String" five: | A block with several lines. six: |- A "chomped" block seven: > A folded string +++ perl { one => "simple string", two => '42', three => "1 Single Quoted String", four => "YAML's Double Quoted String", five => "A block\n with several\n lines.\n", six => 'A "chomped" block', seven => "A folded\n string\n", } === Multiple documents +++ yaml --- foo: bar --- bar: two +++ perl +{qw(foo bar)}, {qw(bar two)}; === Comments +++ yaml # Leading Comment --- # Preceding Comment foo: bar # Two # Comments --- # Indented comment bar: two bee: three # Intermediate comment bore: four +++ perl +{qw(foo bar)}, {qw(bar two bee three bore four)} YAML-1.31/t/preserve.t0000644000175000017500000000056714543037225013176 0ustar ingyingyuse strict; use Test::More tests => 1; use YAML; local $YAML::Preserve = 1; my $yaml = <<'...'; --- z: z y: y x: x w: w v: v u: u t: t s: s r: r q: q p: p o: o n: n m: m l: l k: k j: j i: i h: h g: g f: f e: e d: d c: c b: b a: a ... my $data = YAML::Load($yaml); my $dump = YAML::Dump($data); cmp_ok($dump, 'eq', $yaml, "Roundtrip with Preserve option"); done_testing; YAML-1.31/t/dump-tests-512.t0000644000175000017500000000074114543037225013747 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use Test::More; BEGIN { if ( qr/x/ =~ /\(\?\^/ ){ plan skip_all => "test only for perls before v5.13.5-11-gfb85c04"; } } use TestYAML tests => 1; no_diff(); run_roundtrip_nyn('dumper'); __DATA__ === +++ no_round_trip Since we don't use eval for regexp reconstitution any more (for safety sake) this test doesn't roundtrip even though the values are equivalent. +++ perl [qr{bozo$}i] +++ yaml --- - !!perl/regexp (?i-xsm:bozo$) YAML-1.31/t/000-compile-modules.t0000644000175000017500000000044114543037225014725 0ustar ingyingy# This test does a basic `use` check on all the code. use Test::More; use File::Find; sub test { s{^lib/(.*)\.pm$}{$1} or return; s{/}{::}g; use_ok $_; } $ENV{PERL_ZILD_TEST_000_COMPILE_MODULES} = 1; find { wanted => \&test, no_chdir => 1, }, 'lib'; done_testing; YAML-1.31/t/inbox.t0000644000175000017500000000112414543037225012450 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 3; SKIP: { skip 'fix this next release', 3; my $x; is(Dump(bless(\$x)), 'foo'); } __END__ 03:14 < audreyt> ingy: 03:14 < audreyt> use YAML; my $x; print Dump bless(\$x); 03:14 < audreyt> is erroneous 03:14 < audreyt> then 03:14 < audreyt> use YAML; my $x = \3; print Dump bless(\$x); 03:14 < audreyt> is fatal error 03:15 < audreyt> use YAML; my $x; $x = \$x; print Dump bless(\$x); 03:15 < audreyt> is scary fatal error 03:15 < audreyt> (YAML::Syck handles all three ^^;) 03:16 * audreyt goes back to do $job work YAML-1.31/t/dump-file-utf8.t0000644000175000017500000000150314543037225014100 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; my $t = -e 't' ? 't' : 'test'; use utf8; use lib 'inc'; use Test::YAML(); BEGIN { @Test::YAML::EXPORT = grep { not /^(Dump|Load)(File)?$/ } @Test::YAML::EXPORT; } use TestYAML tests => 6; use YAML qw/DumpFile LoadFile/; ok defined &DumpFile, 'DumpFile exported'; ok defined &LoadFile, 'LoadFile exported'; my $file = "$t/dump-file-utf8-$$.yaml"; # A scalar containing non-ASCII characters my $data = 'Olivier Mengué'; is length($data), 14, 'Test source is correctly encoded'; DumpFile($file, $data); ok -e $file, 'Output file exists'; open IN, '<:utf8', $file or die $!; my $yaml = do { local $/; }; close IN; is $yaml, "--- $data\n", 'DumpFile YAML encoding is correct'; my $read = LoadFile($file); is $read, $data, 'LoadFile is ok'; unlink $file; YAML-1.31/t/dump-synopsis.t0000644000175000017500000000060414543037225014165 0ustar ingyingyuse strict; use warnings; use Test::More tests => 1; my $success = 0; my $err; { local $@; eval { require YAML::Dumper; my $hash = {}; my $dumper = YAML::Dumper->new(); my $string = $dumper->dump($hash); $success = 1; }; $err = $@; } is( $success, 1, "Basic YAML::Dumper usage worked as expected" ) or diag( explain($err) ); YAML-1.31/t/svk-config.yaml0000644000175000017500000002360314543037225014104 0ustar ingyingy--- checkout: !perl/Data::Hierarchy hash: /home/jesse/README: depotpath: //local/rt-3.4/README encoding: ascii revision: 17371 /home/jesse/foo: depotpath: //local/foo encoding: ascii revision: 19501 /home/jesse/svk/1.0-releng: depotpath: //mirror/svk/branches/1.0-releng/ encoding: ascii revision: 20905 /home/jesse/svk/Acme-Net-OdiousPlan: depotpath: //mirror//bps-public/Acme-Net-OdiousPlan/ encoding: ascii revision: 13820 /home/jesse/svk/Business-Hours: depotpath: //local/Business-Hours encoding: iso-8859-1 revision: 17426 /home/jesse/svk/DBIx-DBSchema: depotpath: //local/DBIx-DBSchema encoding: utf-8-strict revision: 19508 /home/jesse/svk/DBIx-SearchBuilder: depotpath: //local/DBIx-SearchBuilder/ encoding: iso-8859-1 revision: 21870 /home/jesse/svk/Data-ICal: depotpath: //local/Data-ICal encoding: iso-8859-1 revision: 17222 /home/jesse/svk/Devel-ebug: depotpath: //local/Devel-ebug/ encoding: ascii revision: 15097 /home/jesse/svk/Devel-ebug-HTTP: depotpath: //local/Devel-ebug-HTTP/ encoding: ascii revision: 15099 /home/jesse/svk/HTTP-Server-Simple: depotpath: //local/HTTP-Server-Simple/ encoding: iso-8859-1 revision: 18459 /home/jesse/svk/HTTP-Server-Simple-Mason: depotpath: //local/HTTP-Server-Simple-Mason/ encoding: ascii revision: 13726 /home/jesse/svk/HTTP-Server-Simple-Recorder: depotpath: //local/HTTP-Server-Simple-Recorder encoding: ascii revision: 13245 /home/jesse/svk/Module-Install-RTx: depotpath: //local/Module-Install-RTx/ encoding: ascii revision: 19842 /home/jesse/svk/Module-Refresh: depotpath: //local/Module-Refresh encoding: iso-8859-1 revision: 20956 /home/jesse/svk/RT-Extension-ActivityReports: depotpath: //local/RT-Extension-ActivityReports/ encoding: ascii revision: 22084 /home/jesse/svk/RT-Extension-MergeUsers: depotpath: //local/RT-Extension-MergeUsers/ encoding: ascii revision: 18043 /home/jesse/svk/RT-Extension-Redacted: depotpath: //local/RT-Extension-Redacted/ encoding: ascii revision: 20453 /home/jesse/svk/RT-Integration-SVN: depotpath: //local/RT-Integration-SVN/ encoding: iso-8859-1 revision: 4915 /home/jesse/svk/RT-KeyBindings: depotpath: //local/RT-KeyBindings encoding: ascii revision: 15495 /home/jesse/svk/RT-OnlineDocs: depotpath: //local/RT-OnlineDocs/ encoding: ascii revision: 20473 /home/jesse/svk/RT-TicketWhiteboard: depotpath: //local/RT-TicketWhiteboard/ encoding: utf-8-strict revision: 20454 /home/jesse/svk/RT-Todo: depotpath: //local/RT-Todo encoding: iso-8859-1 revision: 7320 /home/jesse/svk/RT-View-Directory: depotpath: //local/RT-View-Directory/ encoding: ascii revision: 20455 /home/jesse/svk/RT-View-Tree: depotpath: //local/RT-View-Tree/ encoding: iso-8859-1 revision: 4918 /home/jesse/svk/Test-HTTP-Server-Simple: depotpath: //mirror/bps-public/Test-HTTP-Server-Simple/ encoding: ascii revision: 7358 /home/jesse/svk/WWW-Mechanize-FromRecording: depotpath: //mirror/bps-public/WWW-Mechanize-FromRecording/ encoding: ascii revision: 15347 /home/jesse/svk/chaldea: depotpath: //local/chaldea encoding: ascii revision: 19696 /home/jesse/svk/chaldea/html/Ticket/ModifyAll.html: revision: 19797 /home/jesse/svk/clkao: depotpath: //local/clkao encoding: ascii revision: 15496 /home/jesse/svk/customers: depotpath: //local/customers encoding: ascii revision: 20447 /home/jesse/svk/hiveminder-trunk: depotpath: //local/hiveminder-trunk/ encoding: ascii revision: 21802 /home/jesse/svk/jifty.org: depotpath: //local/jifty.org encoding: ascii revision: 22079 /home/jesse/svk/logo: depotpath: //mirror/bps-private/docs/logo encoding: ascii revision: 7032 /home/jesse/svk/modinstal: depotpath: //local/modinstal encoding: ascii revision: 20926 /home/jesse/svk/people: depotpath: //local/people encoding: ascii revision: 7029 /home/jesse/svk/people/kevinr: revision: 7633 /home/jesse/svk/perl6-doc: depotpath: //local/perl6-doc/ encoding: iso-8859-1 revision: 17030 /home/jesse/svk/personal: depotpath: //local/personal encoding: ascii revision: 13817 /home/jesse/svk/planetsix: depotpath: //local/planetsix encoding: ascii revision: 21020 /home/jesse/svk/private-docs: depotpath: //local/private-docs encoding: ascii revision: 18093 /home/jesse/svk/quebec: depotpath: //local/quebec encoding: ascii revision: 19693 /home/jesse/svk/rt-3.0: depotpath: //local/rt-3.0 encoding: iso-8859-1 revision: 18019 /home/jesse/svk/rt-3.2: depotpath: //local/rt-3.2 encoding: iso-8859-1 revision: 17458 /home/jesse/svk/rt-3.4: depotpath: //local/rt-3.4 encoding: iso-8859-1 revision: 20436 /home/jesse/svk/rt-3.5: depotpath: //local/rt-3.5 encoding: iso-8859-1 revision: 20493 /home/jesse/svk/rt-book: depotpath: //local/rt-book/ encoding: ascii revision: 4893 /home/jesse/svk/rt.cpan.org: depotpath: //local/rt.cpan.org encoding: ascii revision: 17911 /home/jesse/svk/rtfm-2.0: depotpath: //local/rtfm-2.0 encoding: ascii revision: 16160 /home/jesse/svk/rtfm-2.1: depotpath: //local/rtfm-2.1 encoding: ascii revision: 19705 /home/jesse/svk/rtir-1.0: depotpath: //local/rtir-1.0 encoding: iso-8859-1 revision: 17456 /home/jesse/svk/svk-trunk: depotpath: //local/svk-trunk encoding: ascii revision: 21697 /home/jesse/svk/svkbook: depotpath: //local/svkbook-trunk encoding: ascii revision: 18587 /home/jesse/svk/training: depotpath: //local/training encoding: ascii revision: 22081 /home/jesse/svk/trunk: depotpath: //local/svk/trunk encoding: ascii revision: 0 /tmp/3.5-TESTING: depotpath: //mirror/bps-public/rt/branches/3.5-TESTING/ encoding: ascii revision: 19687 /tmp/gtd: depotpath: //local/gtd encoding: ascii revision: 0 /tmp/hm/hiveminder-trunk: depotpath: //local/hiveminder-trunk encoding: ascii revision: 15375 /tmp/svl-checkous/Acme-Colour: depotpath: //_default_/acme/Acme-Colour encoding: ascii revision: 7268 /tmp/svlco/Acme-Colour: depotpath: //_default_/acme/Acme-Colour encoding: ascii revision: 7268 /tmp/trunk: depotpath: //mirror/bps-private/hiveminder/trunk encoding: utf-8-strict revision: 19754 sep: / sticky: /home/jesse/svk/1.0-releng/lib/SVK/Target.pm: .newprop: {} /home/jesse/svk/hiveminder-trunk/Jifty: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/Makefile: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/Makefile.old: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/blib: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/doc: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/doc/session: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/inc: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/jifty: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/lib: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/lib/Jifty: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/lib/Jifty/DefaultApp: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/lib/Jifty/Manual: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/lib/Jifty/Manual/ObjectModel.pod: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/pm_to_blib: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/t: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/t/Continuations: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/t/Continuations/Makefile.old: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/t/Continuations/continuations: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/t/Continuations/continuationstest: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/t/Continuations/inc: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/t/Mapper: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/t/Mapper/mapper: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/t/Mapper/mappertest: .conflict: 1 /home/jesse/svk/hiveminder-trunk/Jifty/t/utils.pl: .conflict: 1 /home/jesse/svk/jifty.org: .newprop: svk:merge: e84bef0a-9b06-0410-84ba-c4c9edb13aeb:/:428 .schedule: prop /home/jesse/svk/rt.cpan.org/rt2-existing/local/WebRT/html/NoAuth/bugs.tsv: .newprop: svn:executable: '*' .schedule: add /home/jesse/svk/training: .newprop: svk:merge: |- 6641d27c-1bcc-0310-8a77-bef5c512aa61:/training:1585 a51291e0-c2ea-0310-847b-fbb8d8170edb:/local/training:5752 .schedule: prop /home/jesse/svk/training/developer_training: .newprop: svk:merge: |- 5f29b386-91d9-0310-ba9f-d3bca794479a:/rttraining/local:1354 5f29b386-91d9-0310-ba9f-d3bca794479a:/rttraining/local-merge-9322:1032 5f88e03f-dcfa-0310-a525-a1f853655784:/rt-developer-training:1586 8d5e1d6e-e2eb-0310-9379-fb19c180b7be:/dev_training-local:1241 .schedule: prop depotmap: '': /home/jesse/.svk/local parrot: /home/jesse/.svk/parrot YAML-1.31/t/dump-tests-514.t0000644000175000017500000000074414543037225013754 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use Test::More; BEGIN { unless ( qr/x/ =~ /\(\?\^/ ){ plan skip_all => "test only for perls v5.13.5-11-gfb85c04 or later"; } } use TestYAML tests => 1; no_diff(); run_roundtrip_nyn('dumper'); __DATA__ === +++ no_round_trip Since we don't use eval for regexp reconstitution any more (for safety sake) this test doesn't roundtrip even though the values are equivalent. +++ perl [qr{bozo$}i] +++ yaml --- - !!perl/regexp (?^i:bozo$) YAML-1.31/t/roundtrip.t0000644000175000017500000000035514543037225013364 0ustar ingyingyuse strict; use warnings; use YAML; use Test::More tests => 1; use Test::Deep; my %in = ( '=' => 'value' ); my $yaml = Dump \%in; my $roundtrip = Load $yaml; cmp_deeply($roundtrip, \%in, "Roundtrip with '=' hash key"); done_testing; YAML-1.31/t/dump-basics.t0000644000175000017500000000160114543037225013540 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 7; filters { perl => [qw'eval yaml_dump'], }; run_is; __DATA__ === A map +++ perl +{ foo => 'bar', baz => 'boo' } +++ yaml --- baz: boo foo: bar === A list +++ perl [ qw'foo bar baz' ] +++ yaml --- - foo - bar - baz === A List of maps +++ perl [{ foo => 42, bar => 44}, {one => 'two', three => 'four'}] +++ yaml --- - bar: 44 foo: 42 - one: two three: four === A map of lists +++ perl +{numbers => [ 5..7 ], words => [qw'five six seven']} +++ yaml --- numbers: - 5 - 6 - 7 words: - five - six - seven === Top level scalar +++ perl: 'The eagle has landed' +++ yaml --- The eagle has landed === Top level literal scalar +++ perl <<'...' sub foo { return "Don't eat the foo"; } ... +++ yaml --- | sub foo { return "Don't eat the foo"; } === Single Dash +++ perl: {foo => '-'} +++ yaml --- foo: '-' YAML-1.31/t/load-fails.t0000644000175000017500000000120614543037225013345 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; # This simply tests that a given piece of invalid YAML fails to parse use TestYAML tests => 4; filters { msg => 'regexp', yaml => 'yaml_load_or_fail', }; run_like yaml => 'msg'; __DATA__ === +++ SKIP This test hangs YAML.pm +++ msg YAML Error: Inconsistent indentation level +++ yaml a: * === +++ msg YAML Error: Inconsistent indentation level +++ yaml --- |\ foo\zbar === +++ msg YAML Error: Unrecognized implicit value +++ yaml --- @ 42 === +++ msg YAML Error: Inconsistent indentation level +++ yaml --- - 1 -2 === +++ msg Unrecognized TAB policy +++ yaml --- #TAB:MOBY - foo YAML-1.31/t/dump-works.t0000644000175000017500000000030514543037225013441 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML; run_is; sub yaml_dump { return Dump(@_); } __DATA__ === A one key hash +++ perl eval yaml_dump +{foo => 'bar'} +++ yaml --- foo: bar YAML-1.31/t/dump-opts.t0000644000175000017500000000422414543037225013265 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 19; run_roundtrip_nyn(); __DATA__ === +++ config local $YAML::UseHeader = 0 +++ perl (['34', '45'], ['56', '67']) +++ yaml - 34 - 45 --- - 56 - 67 === +++ no_round_trip +++ config local $YAML::UseAliases = 0 +++ perl my $ref = {foo => 'bar'}; [$ref, $ref] +++ yaml --- - foo: bar - foo: bar === +++ config local $YAML::CompressSeries = 1 +++ perl [ {foo => 'bar'}, {lips => 'red', crown => 'head'}, {trix => [ 'foo', {silly => 'rabbit', bratty => 'kids', } ] }, ] +++ yaml --- - foo: bar - crown: head lips: red - trix: - foo - bratty: kids silly: rabbit === +++ config local $YAML::CompressSeries = 0; local $YAML::Indent = 5 +++ perl [ {one => 'fun', pun => 'none'}, two => 'foo', {three => [ {free => 'willy', dally => 'dilly'} ]}, ] +++ yaml --- - one: fun pun: none - two - foo - three: - dally: dilly free: willy === +++ config local $YAML::CompressSeries = 1; local $YAML::Indent = 5 +++ perl [ {one => 'fun', pun => 'none'}, two => {foo => {true => 'blue'}}, {three => [ {free => 'willy', dally => 'dilly'} ]}, ] +++ yaml --- - one: fun pun: none - two - foo: true: blue - three: - dally: dilly free: willy === +++ config local $YAML::Indent = 3 +++ perl [{ one => 'two', three => 'four' }, { foo => 'bar' }, ] +++ yaml --- - one: two three: four - foo: bar === +++ config local $YAML::CompressSeries = 1 +++ perl [ 'The', {speed => 'quick', color => 'brown', &YAML::VALUE => 'fox'}, 'jumped over the', {speed => 'lazy', &YAML::VALUE, 'dog'}, ] +++ yaml --- - The - color: brown speed: quick =: fox - jumped over the - speed: lazy =: dog === +++ config local $YAML::InlineSeries = 3 +++ perl [ ['10', '20', '30'], ['foo', 'bar'], ['thank', 'god', "it's", 'friday'], ] +++ yaml --- - [10, 20, 30] - [foo, bar] - - thank - god - it's - friday === +++ config local $YAML::SortKeys = [qw(foo bar baz)] +++ perl {foo=>'42',bar=>'99',baz=>'4'} +++ yaml --- foo: 42 bar: 99 baz: 4 === +++ perl {foo => '42', bar => 'baz'} +++ yaml --- bar: baz foo: 42 YAML-1.31/t/changes.t0000644000175000017500000000024414543037225012743 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 1; SKIP: { skip("Can't parse Changes file yet :(", 1); } # my @values = LoadFile("Changes"); YAML-1.31/t/load-spec.t0000644000175000017500000003002014543037225013175 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 52; run_load_passes(); __DATA__ === +++ yaml - Mark McGwire - Sammy Sosa - Ken Griffey === +++ yaml hr: 65 avg: 0.278 rbi: 147 === +++ yaml american: - Boston Red Sox - Detroit Tigers - New York Yankees - Texas Rangers national: - New York Mets - Chicago Cubs - Atlanta Braves - Montreal Expos === +++ yaml - name: Mark McGwire hr: 65 avg: 0.278 rbi: 147 - name: Sammy Sosa hr: 63 avg: 0.288 rbi: 141 === +++ yaml ? - New York Yankees - Atlanta Braves : - 2001-07-02 - 2001-08-12 - 2001-08-14 ? - Detroit Tigers - Chicago Cubs : - 2001-07-23 === +++ yaml invoice: 34843 date : 2001-01-23 bill-to: given : Chris family : Dumars product: - quantity: 4 desc : Basketball - quantity: 1 desc : Super Hoop === +++ yaml --- name: Mark McGwire hr: 65 avg: 0.278 rbi: 147 --- name: Sammy Sosa hr: 63 avg: 0.288 rbi: 141 === +++ yaml # Ranking of players by # season home runs. --- - Mark McGwire - Sammy Sosa - Ken Griffey === +++ yaml #hr: # Home runs # # 1998 record # - Mark McGwire # - Sammy Sosa #rbi: # Runs batted in # - Sammy Sosa # - Ken Griffey === +++ yaml hr: - Mark McGwire # Name "Sammy Sosa" scalar SS - &SS Sammy Sosa rbi: # So it can be referenced later. - *SS - Ken Griffey === +++ yaml --- > Mark McGwire's year was crippled by a knee injury. === +++ yaml --- | \/|\/| / | |_ === +++ yaml --- >- Sosa completed another fine season. === +++ yaml #name: Mark McGwire #occupation: baseball player #comments: Mark set a major # league home run # record in 1998. === +++ yaml years: "1998\t1999\t2000\n" msg: "Sosa did fine. \u263A" === +++ yaml - ' \/|\/| ' - ' / | |_ ' === +++ yaml - [ name , hr , avg ] - [ Mark McGwire , 65 , 0.278 ] - [ Sammy Sosa , 63 , 0.288 ] === +++ yaml #Mark McGwire: {hr: 65, avg: 0.278} #Sammy Sosa: {hr: 63, # avg: 0.288} === +++ yaml invoice: 34843 date : 2001-01-23 buyer: given : Chris family : Dumars product: - Basketball: 4 - Superhoop: 1 === +++ yaml #invoice: !int|dec 34843 #date : !time 2001-01-23 #buyer: !map # given : !str Chris # family : !str Dumars #product: !seq # - !str Basketball: !int 4 # - !str Superhoop: !int 1 === +++ yaml #invoice: !str 34843 #date : !str 2001-01-23 === +++ yaml #--- !clarkevans.com/schedule/^entry #who: Clark C. Evans #when: 2001-11-18 #hours: !^hours 3 #description: > # Wrote up these examples # and learned a lot about # baseball statistics. === +++ yaml #--- !clarkevans.com/graph/^shape #- !^circle # center: &ORIGIN {x: 73, y: 129} # radius: 7 #- !^line [23, 32, 300, 200] #- !^text # center: *ORIGIN # color: 0x02FDBA === +++ yaml --- !clarkevans.com/^invoice invoice: 34843 date : 2001-01-23 bill-to: &id001 given : Chris family : Dumars address: lines: | 458 Walkman Dr. Suite #292 city : Royal Oak state : MI postal : 48046 ship-to: *id001 product: - sku : BL394D quantity : 4 description : Basketball price : 450.00 - sku : BL4438H quantity : 1 description : Super Hoop price : 2392.00 tax : 251.42 total: 4443.52 comments: > Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. === +++ yaml --- Date: 2001-11-23 Time: 15:01:42 User: ed Warning: > This is an error message for the log file --- Date: 2001-11-23 Time: 15:02:31 User: ed Warning: > A slightly different error message. --- Date: 2001-11-23 Time: 15:03:17 User: ed Fatal: > Unknown variable "bar" Stack: - file: TopClass.py line: 23 code: | x = MoreObject("345\n") - file: MoreClass.py line: 58 code: | foo = bar === +++ yaml ################################### ## These are four throwaway comment # ## lines (the second line is empty). #this: | # Comments may trail lines. # contains three lines of text. # The third one starts with a # # character. This isn't a comment. # ## These are four throwaway comment ## lines (the first line is empty). ################################### === +++ yaml --- > This YAML stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end. === +++ yaml --- at: 2001-08-12T09:25:00.00 type: GET HTTP: '1.0' url: '/index.html' --- at: 2001-08-12T09:25:10.00 type: GET HTTP: '1.0' url: '/toc.html' === +++ yaml ## The following is a sequence of three documents. ## The first contains an empty mapping, the second ## an empty sequence, and the last an empty string. #--- {} #--- [ ] #--- '' === +++ yaml ## All entries in the sequence ## have the same type and value. #- 10.0 #- !float 10 #- !yaml.org/^float '10' #- !http://yaml.org/float "\ # 1\ # 0" === +++ yaml ## Private types are per-document. #--- #pool: !!ball # number: 8 # color: black #--- #bearing: !!ball # material: steel === +++ yaml ## 'http://domain.tld/invoice' is some type family. #invoice: !domain.tld/^invoice # # 'seq' is shorthand for 'http://yaml.org/seq'. # # This does not effect '^customer' below # # because it is does not specify a prefix. # customers: !seq # # '^customer' is shorthand for the full # # notation 'http://domain.tld/customer'. # - !^customer # given : Chris # family : Dumars === +++ yaml ## It is possible to use XML namespace URIs as ## YAML namespaces. Using the ancestor's URI ## allows specifying it only once. The $ separates ## between the XML namespace URI and the tag name. #doc: !http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd$^html # - !^body # - !^p This is an HTML paragraph. === +++ yaml anchor : &A001 This scalar has an anchor. override : &A001 > The alias node below is a repeated use of this value. alias : *A001 === +++ yaml #empty: [] #in-line: [ one, two, three # May span lines, # , four, # indentation is # five ] # mostly ignored. #nested: # - First item in top sequence # - # - Subordinate sequence entry # - > # A multi-line # sequence entry # - Sixth item in top sequence === +++ yaml #empty: {} #in-line: { one: 1, two: 2 } #spanning: { one: 1, # two: 2 } #nested: # first : First entry # second: # key: Subordinate mapping # third: # - Subordinate sequence # - { } # - Previous mapping is empty. # - A key: value pair in a sequence. # A second: key:value pair. # - The previous entry is equal to the following one. # - # A key: value pair in a sequence. # A second: key:value pair. # !float 12 : This key is a float. # ? > # ? # : This key had to be protected. # "\a" : This key had to be escaped. # ? > # This is a # multi-line # folded key # : Whose value is # also multi-line. # ? # - This key # - is a sequence # : # - With a sequence value. # ? # This: key # is a: mapping # : # with a: mapping value. === +++ yaml empty: | detected: | The \ ' " characters may be freely used. Leading white space is significant. All line breaks are significant, including the final one. Thus this value contains one empty line and ends with a line break, but does not start with one. # Comments may follow a nested # scalar value. They must be # less indented. # Explicit indentation must # be given in all the three # following cases. leading spaces: |2 This value starts with four spaces. It ends with one line break and an empty comment line. leading line break: |2 This value starts with a line break and ends with one. leading comment indicator: |2 # first line starts with a #. This value does not start with a line break but ends with one. # Explicit indentation may # also be given when it is # not required. redundant: |2 This value is indented 2 spaces. stripped: |- This contains no newline. kept: |+ This contains two newlines. # Comments may follow. === +++ yaml #empty: > #detected: > # Line feeds are converted # to spaces, so this value # contains no line breaks # except for the final one. # #explicit: >2 # # An empty line, either # at the start or in # the value: # # Is interpreted as a # line break. Thus this # value contains three # line breaks. # #stripped: >-1 # This starts with a space # and contains no newline. # #kept: >1+ # This starts with a space # and contains two newlines. # #indented: > # This is a folded # paragraph followed # by a list: # * first entry # * second entry # Followed by another # folded paragraph, # another list: # # * first entry # # * second entry # # And a final folded # paragraph. #block: | # Equal to above. # This is a folded paragraph followed by a list: # * first entry # * second entry # Followed by another folded paragraph and list: # # * first entry # # * second entry # # And a final folded paragraph. # ## Explicit comments may follow ## but must be less indented. === +++ yaml #empty: '' #second: '! : \ etc. can be used freely.' #third: 'a single quote '' must be escaped.' #span: 'this contains # six spaces # # and one # line break' === +++ yaml #empty: "" #second: "! : etc. can be used freely." #third: "a \" or a \\ must be escaped." #fourth: "this value ends with an LF.\n" #span: "this contains # four \ # spaces" === +++ yaml #first: There is no unquoted empty string. #second: 12 ## This is an integer. #third: !str 12 ## This is a string. #span: this contains # six spaces # # and one # line break #indicators: this has no comments. # #foo and bar# are # all text. #in-line: [ can span # lines, # comment # like # this ] #note: { one-line keys: but # multi-line values } === +++ yaml ## The following are equal seqs ## with different identities. #in-line: [ one, two ] #spanning: [ one, # two: ] #nested: # - one # - two === +++ yaml # The following are equal maps # with different identities. in-line: { one: 1, two: 2 } nested: one: 1 two: 2 === +++ yaml #- 12 # An integer ## The following scalars ## are loaded to the ## string value '1' '2'. #- !str 12 #- '12' #- "12" #- "\ # 1\ # 2\ # " === +++ yaml #canonical: ~ #verbose: (null) #sparse: # - ~ # - Second entry. # - (nil) # - This sequence has 4 entries, two with values. #three: > # This mapping has three keys, # only two with values. === +++ yaml #canonical: - #logical: (true) #informal: (no) === +++ yaml #canonical: 12345 #decimal: +12,345 #octal: 014 #hexadecimal: 0xC === +++ yaml #canonical: 1.23015e+3 #exponential: 12.3015e+02 #fixed: 1,230.15 #negative infinity: (-inf) #not a number: (NaN) === +++ yaml canonical: 2001-12-15T02:59:43.1Z valid iso8601: 2001-12-14t21:59:43.10-05:00 space separated: 2001-12-14 21:59:43.10 -05:00 date (noon UTC): 2002-12-14 === +++ yaml #canonical: !binary "\ # R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOf\ # n515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaW\ # NjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++\ # f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUg\ # d2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuN\ # AFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84Bww\ # EeECcgggoBADs=" #base64: !binary | # R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOf # n515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaW # NjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++ # f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUg # d2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuN # AFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84Bww # EeECcgggoBADs= #description: > # The binary value above is a tiny arrow # encoded as a gif image. === +++ yaml ## Old schema #--- #link with: # - library1.dll # - library2.dll # ## New schema #--- #link with: # - = : library1.dll # version: 1.2 # - = : library2.dll # version: 2.1 === +++ yaml #"!": These three keys #"&": had to be quoted #"=": and are normal strings. ## NOTE: the following encoded node ## should NOT be serialized this way. #encoded node : # !special '!' : '!type' # !special '&' : 12 # = : value ## The proper way to serialize the ## above structure is as follows: #node : !!type &12 value YAML-1.31/t/dump-stringify.t0000644000175000017500000000200614543037225014312 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 6; no_diff; package Foo; use overload '""' => \&stringy; sub stringy { 'Hello mate!' } sub new { bless { 'Hello' => 'mate!' }, shift }; package main; my $foo = Foo->new; my $stringy_dump = <<''; --- Hello mate! my $object_dump = <<''; --- !!perl/hash:Foo Hello: mate! my $yaml; $yaml = Dump($foo); is $yaml, $object_dump, "Global stringification default dump"; $YAML::Stringify = 1; $yaml = Dump($foo); is $yaml, $stringy_dump, "Global stringification enabled dump"; $YAML::Stringify = 0; $yaml = Dump($foo); is $yaml, $object_dump, "Global stringification disabled dump"; require YAML::Dumper; my $dumper = YAML::Dumper->new; $yaml = $dumper->dump($foo); is $yaml, $object_dump, "Local stringification default dump"; $dumper->stringify(1); $yaml = $dumper->dump($foo); is $yaml, $stringy_dump, "Local stringification enabled dump"; $dumper->stringify(0); $yaml = $dumper->dump($foo); is $yaml, $object_dump, "Local stringification disabled dump"; YAML-1.31/t/dump-blessed-glob.t0000644000175000017500000000336614543037225014650 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 3; package Foo::Bar; sub new { my ($class) = @_; my $ref = globref(); my $self = bless $ref, $class; return $self; } my $globnum = 0; sub globref { my $symbolname = "Foo::Glob::glob$globnum"; $globnum ++; no strict 'refs'; return \*{ $symbolname }; } package main; is(Test::YAML::Dump({ globref => Foo::Bar::globref() }), < Foo::Bar->new }), <new; ${ *$val } = 'wag'; %{ *$val } = qw( key value hash pairs ); @{ *$val } = qw( a b c ); open *$val, '>&', \*STDERR or die "Can't dup STDERR: $!"; *{$val} = sub { 2 + 2 }; my $dump_tricks = Test::YAML::Dump({ blessglob => $val }); # Redact some highly variable stuff from the IO my $changekeys = join '|', qw( fileno device inode mode links uid gid rdev size atime mtime ), qw( ctime blksize blocks tell ); $dump_tricks =~ s{($changekeys): \S+$}{$1: redact}mg; is($dump_tricks, < 16; use YAML::Dumper; package StrIngy; use overload '""', sub { 'A Stringy String' }; sub new {bless {}, shift} package main; my $object = bless {}, 'StrIngy'; # $\ = "\n"; # print ref($object); # print "$object"; # print overload::StrVal($object); # print overload::StrVal(bless {}, 'foo'); # exit; filters { node => ['eval_perl' => 'get_info'], info => ['lines' => 'make_regexp'], }; run_like node => 'info'; sub eval_perl { my $perl = shift; my $stringify = 0; $stringify = 1 if $perl =~ s/^#\s*//; my $node = eval $perl; die "Perl code failed to eval:\n$perl\n$@" if $@; return ($node, $stringify); } sub get_info { my $dumper = YAML::Dumper->new; join ';', map { defined($_) ? $_ : 'undef' } $dumper->node_info(@_); } sub make_regexp { my $string = join ';', map { chomp; s/^~$/undef/; s/^0x\d+/0x[0-9a-fA-F]+/; $_; } @_; qr/^${string}$/; } __DATA__ === Hash Ref +++ node: +{1..4}; +++ info ~ HASH 0x12345678 === Array Ref +++ node: [1..5] +++ info ~ ARRAY 0x12345678 === Scalar +++ node: 'hello'; +++ info ~ ~ 0x12345678-S === Scalar Ref +++ node: \ 'hello'; +++ info ~ SCALAR 0x12345678 === Scalar Ref Ref +++ node: \\ 'hello'; +++ info ~ REF 0x12345678 === Code Ref +++ node: sub { 42; } +++ info ~ CODE 0x12345678 === Code Ref Ref +++ node: \ sub { 42; } +++ info ~ REF 0x12345678 === Glob +++ node: $::x = 5; \ *x; +++ info ~ GLOB 0x12345678 === Regular Expression +++ node: qr{xxx}; +++ info ~ REGEXP 0x12345678 === Blessed Hash Ref +++ node: bless {}, 'ARRAY'; +++ info ARRAY HASH 0x12345678 === Blessed Array Ref +++ node: bless [], 'Foo::Bar'; +++ info Foo::Bar ARRAY 0x12345678 === Blessed Scalar Ref +++ node: my $b = 'boomboom'; bless ((\ $b), 'Foo::Barge'); +++ info Foo::Barge SCALAR 0x12345678 === Blessed Code Ref +++ node: bless sub { 43 }, 'Foo::Barbie'; +++ info Foo::Barbie CODE 0x12345678 === Blessed Glob +++ node: $::x = 5; bless \ *x, 'Che'; +++ info Che GLOB 0x12345678 === Not Stringified Hash Object +++ node: bless {}, 'StrIngy'; +++ info StrIngy HASH 0x12345678 === Stringified Hash Object +++ node: # bless {}, 'StrIngy'; +++ info ~ ~ 0x12345678-S YAML-1.31/t/issue-69.t0000644000175000017500000000042414543037225012717 0ustar ingyingyuse Test::More tests => 2; use YAML; my $seq = eval { YAML::Load("foo: [bar] "); 1 }; my $map = eval { YAML::Load("foo: {bar: 42} "); 1 }; ok($seq, "YAML inline sequence with trailing space loads"); ok($map, "YAML inline mapping with trailing space loads"); done_testing; YAML-1.31/t/export.t0000644000175000017500000000054714543037225012662 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use lib 'inc'; use Test::YAML(); BEGIN { @Test::YAML::EXPORT = grep { not /^(Dump|Load)(File)?$/ } @Test::YAML::EXPORT; } use TestYAML tests => 3; use YAML; ok defined(&Dump), 'Dump() is exported'; ok defined(&Load), 'Load() is exported'; ok not(defined &Store), 'Store() is not exported'; YAML-1.31/t/dump-stringy-numbers.t0000644000175000017500000000136314543037225015451 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 6; use YAML (); use YAML::Dumper; $YAML::QuoteNumericStrings = 1; filters { perl => [qw'eval yaml_dump'], }; ok( YAML::Dumper->is_literal_number(1), '1 is a literal number' ); ok( !YAML::Dumper->is_literal_number("1"), '"1" is not a literal number' ); ok( YAML::Dumper->is_literal_number( "1" + 1 ), '"1" +1 is a literal number' ); run_is; __DATA__ === Mixed Literal and Stringy ints +++ perl +{ foo => '2', baz => 1 } +++ yaml --- baz: 1 foo: '2' === Mixed Literal and Stringy floats +++ perl +{ foo => '2.000', baz => 1.000 } +++ yaml --- baz: 1 foo: '2.000' === Numeric Keys +++ perl +{ 10 => '2.000', 20 => 1.000, '030' => 2.000 } +++ yaml --- '030': 2 '10': '2.000' '20': 1 YAML-1.31/t/2-scalars.t0000644000175000017500000000261714543037225013130 0ustar ingyingy# This test modified from YAML::Syck suite use strict; use Test::More; use Config; require YAML; YAML->import; is(Dump(42), "--- 42\n"); is(Load("--- 42\n"), 42); is(Dump(undef), "--- ~\n"); is(Load("--- ~\n"), undef); is(Load("---\n"), undef); is(Load("--- ''\n"), ''); is(Load("--- true\n"), "true"); is(Load("--- false\n"), "false"); # $YAML::Syck::ImplicitTyping = $YAML::Syck::ImplicitTyping = 1; # # is(Load("--- true\n"), 1); # is(Load("--- false\n"), ''); my $Data = { Test => ' Test Drive D:\\', }; is_deeply(Load(Dump($Data)), $Data); if ($^V ge v5.9.0) { # see https://github.com/ingydotnet/yaml-pm/issues/186 unless ($Config{config_args} =~ / \-fsanitize \= (?: address | undefined ) \b /x) { # Large data tests. See also https://bugzilla.redhat.com/show_bug.cgi?id=192400. $Data = ' äø<> " \' " \'' x 40_000; is(Load(Dump($Data)), $Data); } } { my $yaml1 = <<'EOM'; a: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx b: 2 EOM my $yaml2 = <<'EOM'; a: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx b: 2 EOM my $error; eval { my @data = Load($yaml1); }; $error = $@; cmp_ok($error, '=~', "Can't parse single", "Single quoted without end"); eval { my @data = Load($yaml2); }; $error = $@; cmp_ok($error, '=~', "Can't parse double", "Double quoted without end"); } done_testing; YAML-1.31/t/load-tests.t0000644000175000017500000001736114543037225013422 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 38; use Test::Deep; local $YAML::LoadBlessed; $YAML::LoadBlessed = 1; run { my $block = shift; my @result = eval { Load($block->yaml) }; my $error1 = $@ || ''; if ( $error1 ) { # $error1 =~ s{line: (\d+)}{"line: $1 ($0:".($1+$test->{lines}{yaml}-1).")"}e; } my @expect = eval $block->perl; my $error2 = $@ || ''; if (my $errors = $error1 . $error2) { fail($block->description . $errors); next; } cmp_deeply( \@result, \@expect, $block->description, ) or do { require Data::Dumper; diag("Wanted: ".Data::Dumper::Dumper(\@expect)); diag("Got: ".Data::Dumper::Dumper(\@result)); } }; __DATA__ === a yaml error log +++ yaml --- date: Sun Oct 28 20:41:17 2001 error msg: Premature end of script headers --- date: Sun Oct 28 20:41:44 2001 error msg: malformed header from script. Bad header= --- date: Sun Oct 28 20:42:19 2001 error msg: malformed header from script. Bad header= +++ perl my $a = { map {split /:\s*/, $_, 2} split /\n/, < END my $c = { map {split /:\s*/, $_, 2} split /\n/, < END ($a, $b, $c) === comments and some top level documents +++ yaml # Top level documents # # Note that inline (single line) values # are not allowed at the top level. This # includes implicit values, quoted values # and inline collections. --- a: map --- - a - sequence --- > plain scalar --- | This is a block. It's kinda like a here document. --- |- A chomped block. +++ perl my $a = {a => 'map'}; my $b = ['a', 'sequence']; my $c = "plain scalar\n"; my $d = < 'bar', baz => 'too'}; my $f = []; my $g = {}; my $h = {'09:00:00' => 'Breakfast', '12:00:00' => 'lunch time'}; my $i = bless {small => 'object'}, 'XYZ'; my $j = bless [bless([qw(a b c)], 'DEF'), bless({do => 're', mi => 'fa', so => 'la', ti => 'do'}, 'GHI'), ], 'ABC'; my $k = []; push @$k, $k, $k, $k; my $l = [{name => 'Ingy'}, {name => 'Clark'}, {name => 'Oren'}, ]; [$a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l] === a bunch of small top level thingies +++ yaml --- 42 --- foo --- " bar " --- [] --- #YAML:1.0 {} --- '#YAML:9.9' --- {foo: [1, 2, 3], 12:34:56: bar} +++ perl my $a = 42; my $b = "foo"; my $c = " bar "; my $d = []; my $e = {}; my $f = "#YAML:9.9"; my $g = {foo => [1, 2, 3], '12:34:56' => 'bar'}; ($a, $b, $c, $d, $e, $f, $g) === a headerless sequence and a map +++ yaml - 2 - 3 - 4 --- #YAML:1.0 foo: bar +++ perl ([2,3,4], {foo => 'bar'}) === comments in various places +++ yaml # A pre header comment --- # comment # comment #comment - 2 # comment # comment - 3 - 4 # comment - 5 # last comment --- #YAML:1.0 boo: far # a comment foo : bar --- - > # Not a comment; # Is a comment #Another comment --- 42 #Final #Comment +++ perl ([2,3,4,5], {foo => 'bar', boo => 'far'}, ["# Not a comment;\n"], 42) === several docs, some empty +++ yaml --- - foo - bar --- --- - foo - foo --- # comment --- - bar - bar +++ perl (['foo', 'bar'],undef,['foo', 'foo'],undef,['bar', 'bar']) === a perl reference to a scalar +++ yaml --- !perl/ref: =: 42 +++ perl (\42); === date loading +++ yaml --- - 1964-03-25 - ! "1975-04-17" - !date '2001-09-11' - 12:34:00 - ! "12:00:00" - !time '01:23:45' +++ perl ['1964-03-25', '1975-04-17', '2001-09-11', '12:34:00', '12:00:00', '01:23:45', ]; === sequence with trailing comment +++ yaml --- - fee - fie - foe # no num defined +++ perl [qw(fee fie foe)] === a simple literal block +++ yaml --- - | foo bar +++ perl ["foo\nbar\n"] === an unchomped literal +++ yaml -trim --- - |+ foo bar +++ perl ["foo\nbar\n\n"] === a chomped literal +++ yaml -trim --- - |- foo bar +++ perl ["foo\nbar"] === assorted numerics +++ yaml --- #- - #- + - 44 - -45 - 4.6 - -4.7 - 3e+2 - [-4e+3, 5e-4] - -6e-10 - 2001-12-15 - 2001-12-15T02:59:43.1Z - 2001-12-14T21:59:43.25-05:00 +++ perl [44, -45, 4.6, -4.7, '3e+2', ['-4e+3', '5e-4'], '-6e-10', '2001-12-15', '2001-12-15T02:59:43.1Z', '2001-12-14T21:59:43.25-05:00', ] === an empty string top level doc +++ yaml --- +++ perl undef === an array of various undef +++ yaml --- - - - '' +++ perl [undef,undef,''] === !!perl/array +++ yaml --- !!perl/array - 1 +++ perl [ 1 ] === !!perl/array: +++ yaml --- !!perl/array: - 1 +++ perl [ 1 ] === !!perl/array:moose +++ yaml --- !!perl/array:moose - 1 +++ perl bless([ 1 ], "moose") === foo +++ yaml --- !!perl/hash foo: bar +++ perl { foo => "bar" } === foo +++ yaml --- !!perl/hash: foo: bar +++ perl { foo => "bar" } === foo +++ yaml --- !!perl/array:moose foo: bar +++ perl bless({ foo => "bar" }, "moose") === foo +++ yaml --- !!perl/ref =: 1 +++ perl \1 === foo +++ yaml --- !!perl/ref: =: 1 +++ perl \1 === foo +++ yaml --- !!perl/ref:moose =: 1 +++ perl bless(do { my $x = 1; \$x}, "moose") === foo +++ yaml --- !!perl/scalar 1 +++ perl 1 === foo +++ yaml --- !!perl/scalar: 1 +++ perl 1 === foo +++ yaml --- !!perl/scalar:moose 1 +++ perl bless(do { my $x = 1; \$x}, "moose") === ^ can start implicit +++ yaml - ^foo +++ perl ['^foo'] === Quoted keys +++ yaml - 'test - ': 23 'test '' ': 23 "test \\": 23 +++ perl [{ 'test - ' => 23, "test ' " => 23, 'test \\' => 23 }] === Plain string with multiple spaces +++ yaml --- A B +++ perl 'A B' === Plain string with multiple spaces at the beginning +++ yaml --- " ABC" +++ perl ' ABC' === Allowed characters in anchors +++ yaml --- - &a.1 a - &b/2 b - &c_3 c - &d-4 d - *a.1 - *b/2 - *c_3 - *d-4 +++ perl ['a', 'b', 'c', 'd', 'a', 'b', 'c', 'd'] === Compact nested block sequences +++ yaml - - a - b - - 1 - - 2 - 3 - - [c] +++ perl [ ['a', 'b', [1], [2,3] ], [ ['c'] ], ] === Combined block scalar indicators +++ yaml --- a: |-2 1 2 b: |2- 1 2 c: >+2 1 2 d: >2+ 1 2 +++ perl { a => " 1\n2", b => " 1\n2", c => " 1\n2\n", d => " 1\n2\n", } === Nested explicit key +++ yaml --- - ? a : b +++ perl [{ a => 'b' }] === Nested mappings with non \w keys +++ yaml --- - .: a <: b -: c - 'not: a map' - "not: a map" +++ perl [ { '.' => 'a', '<' => 'b', '-' => 'c' }, 'not: a map', 'not: a map' ] === Zero indented block sequence +++ yaml a: b: - - c: - - d: - 1 - 2 e: - 3 - 4 - f: - 5 - 6 g: 7 +++ perl { a => { b => [ undef, undef ] }, c => [undef, undef], d => [1, 2], e => [3, 4, { f => [5, 6], g => 7, }], } YAML-1.31/t/load-code.t0000644000175000017500000000104314543037225013160 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 4; run_roundtrip_nyn('dumper'); __DATA__ === Actually test LoadCode functionality, block +++ perl: $YAML::UseCode = 1; package main; no strict; sub { "really long test string that's longer than 30" } +++ yaml --- !!perl/code | { use warnings; q[really long test string that's longer than 30]; } === Actually test LoadCode functionality, line +++ perl: $YAML::UseCode = 1; package main; no strict; sub { 42 } +++ yaml --- !!perl/code "{\n use warnings;\n 42;\n}\n" YAML-1.31/t/dump-perl-types.t0000644000175000017500000000476714543037225014420 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 14; filters { perl => ['eval', 'yaml_dump'] }; use YAML (); # [CPAN #74687] must load before B::Deparse for B::Deparse < 0.71 use B::Deparse; if (new B::Deparse -> coderef2text ( sub { no strict; 1; use strict; 1; }) =~ 'refs') { local $/; (my $data = ) =~ s/use strict/use strict 'refs'/g; if ($B::Deparse::VERSION > 0.67 and $B::Deparse::VERSION < 0.71) { # [CPAN #73702] $data =~ s/use warnings;/BEGIN {\${^WARNING_BITS} = "UUUUUUUUUUUU\\001"}/g; } open DATA, '<', \$data; } no_diff; run_is perl => 'yaml'; __DATA__ === Scalar +++ perl: 'Hello' +++ yaml --- Hello === Hash +++ perl: +{bar => 'foo', foo => 'bar'} +++ yaml --- bar: foo foo: bar === Array +++ perl: [qw(W O W)] +++ yaml --- - W - O - W === Code +++ perl $YAML::DumpCode = 1; package main; sub { print "Hello, world\n"; } +++ yaml --- !!perl/code | { use warnings; use strict; print "Hello, world\n"; } === Scalar Reference +++ perl: \ 'Goodbye' +++ yaml --- !!perl/ref =: Goodbye === Scalar Glob +++ perl $::var = 'Hola'; *::var; +++ yaml --- !!perl/glob: PACKAGE: main NAME: var SCALAR: Hola === Array Glob +++ perl @::var2 = (qw(xxx yyy zzz)); *::var2; +++ yaml --- !!perl/glob: PACKAGE: main NAME: var2 ARRAY: - xxx - yyy - zzz === Code Glob +++ perl $YAML::DumpCode = 1; package main; sub main::var3 { print "Hello, world\n"; } *var3; +++ yaml --- !!perl/glob: PACKAGE: main NAME: var3 CODE: !!perl/code | { use warnings; use strict; print "Hello, world\n"; } === Blessed Empty Hash +++ perl: bless {}, 'A::B::C'; +++ yaml --- !!perl/hash:A::B::C {} === Blessed Populated Hash +++ perl: bless {qw(foo bar bar foo)}, 'A::B::C'; +++ yaml --- !!perl/hash:A::B::C bar: foo foo: bar === Blessed Empty Array +++ perl: bless [], 'A::B::C'; +++ yaml --- !!perl/array:A::B::C [] === Blessed Populated Array +++ perl: bless [qw(foo bar bar foo)], 'A::B::C'; +++ yaml --- !!perl/array:A::B::C - foo - bar - bar - foo === Blessed Empty String +++ perl: my $e = ''; bless \ $e, 'A::B::C'; +++ yaml --- !!perl/scalar:A::B::C '' === Blessed Populated String +++ perl: my $fbbf = 'foo bar bar foo'; bless \ $fbbf, 'A::B::C'; +++ yaml --- !!perl/scalar:A::B::C foo bar bar foo === Blessed Regular Expression +++ SKIP +++ perl: bless qr{perfect match}, 'A::B::C'; +++ yaml --- !!perl/regexp:A::B::C perfect match === Blessed Glob +++ SKIP +++ perl: $::x = 42; bless \ *::x, 'A::B::C'; +++ yaml --- !!perl/glob:A::B::C PACKAGE: main NAME: x SCALAR: 42 YAML-1.31/t/bugs-emailed.t0000644000175000017500000000543414543037225013677 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 25; no_diff; run_yaml_tests; __DATA__ === Date: Tue, 03 Jan 2006 18:04:56 +++ perl: { key1 => '>value1' } +++ yaml --- key1: '>value1' === Date: Wed, 04 Jan 2006 10:23:18 +++ perl: { key1 => '|value' } +++ yaml --- key1: '|value' === Date: Thu, 3 Mar 2005 14:12:10 +++ perl: { "foo,bar" => "baz"} +++ yaml --- 'foo,bar': baz === Date: Wed, 9 Mar 2005 09:16:19 +++ perl: {'a,v' => 'c'} +++ yaml --- 'a,v': c === Date: Fri, 18 Mar 2005 15:08:57 +++ perl: {'foo[bar', 'baz'} +++ yaml --- 'foo[bar': baz === Date: Sun, 20 Mar 2005 16:32:50 +++ subject: Argument "E5" isn't numeric in multiplication (*) +++ function: load_passes +++ yaml --- #YAML:1.0 !!perl/Blam::Game board: E5: R1 history: - 1E5 === Date: Sat, 26 Mar 2005 22:55:55 +++ perl: {"a - a" => 1} +++ yaml --- 'a - a': 1 === Date: Sun, 8 May 2005 15:42:04 +++ skip_this_for_now +++ perl: [{q => {any_key => { } }}] +++ yaml --- - /.*/: any_key: {} === Date: Thu, 12 May 2005 14:57:20 +++ function: load_passes +++ yaml --- #YAML:1.0 WilsonSereno1998: authors: - Wilson, Jeffrey. A - Paul C. Sereno title: Early evolution and Higher-level phylogeny of sauropod dinosaurs year: 1998 journal: Journal of Vertebrate Paleontology, memoir volume: 5 pages: 1-68 WedelEtAl2000: authors: - Wedel, M. J. - R. L. Cifelli - R. K. Sanders year: 2000 title: _Sauroposeidon proteles_, a new sauropod from the Early Cretaceous of Oklahoma. journal: Journal of Vertebrate Paleontology volume: 20 issue: 1 pages: 109-114 === Date: Thu, 09 Jun 2005 18:49:01 +++ perl: {'test' => '|testing'} +++ yaml --- test: '|testing' === Date: Mon, 22 Aug 2005 16:52:47 +++ skip_this_for_now +++ perl my $y = { ok_list_of_hashes => [ {one => 1}, {two => 2}, ], error_list_of_hashes => [ {-one => 1}, {-two => 2}, ], }; +++ yaml --- error_list_of_hashes: - -one: 1 - -two: 2 ok_list_of_hashes: - one: 1 - two: 2 === Date: Wed, 12 Oct 2005 17:16:48 +++ skip_this_for_now +++ function: load_passes +++ yaml fontsize_small: '9px' # labelsmall fontsize: '11px' # maintext, etc fontsize_big: '12px' # largetext, button fontsize_header: '13px' # sectionheaders fontsize_banner: '16px' # title === Date: Mon, 07 Nov 2005 15:49:07 +++ perl: \ '|something' +++ yaml --- !!perl/ref =: '|something' === Date: Thu, 24 Nov 2005 10:49:06 +++ perl: { url => 'http://www.test.com/product|1|2|333333', zzz => '' } +++ yaml --- url: http://www.test.com/product|1|2|333333 zzz: '' === Date: Sat, 3 Dec 2005 14:26:23 +++ perl my @keys = qw/001 002 300 400 500/; my $h = {}; map {$h->{$_} = 1} @keys; $h; +++ yaml --- 001: 1 002: 1 300: 1 400: 1 500: 1 YAML-1.31/t/io-handle.t0000644000175000017500000000264714543037225013204 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; my $t = -e 't' ? 't' : 'test'; use utf8; use lib 'inc'; use Test::YAML(); BEGIN { @Test::YAML::EXPORT = grep { not /^(Dump|Load)(File)?$/ } @Test::YAML::EXPORT; } use IO::Pipe; use IO::File; use TestYAML tests => 6; use YAML qw/DumpFile LoadFile/;; my $testdata = 'El país es medible. La patria es del tamaño del corazón de quien la quiere.'; # IO::Pipe my $pipe = new IO::Pipe; if ( fork() ) { # parent reads from IO::Pipe handle $pipe->reader(); my $recv_data = LoadFile($pipe); is length($recv_data), length($testdata), 'LoadFile from IO::Pipe read data'; is $recv_data, $testdata, 'LoadFile from IO::Pipe contents is correct'; } else { # child writes to IO::Pipe handle $pipe->writer(); DumpFile($pipe, $testdata); exit 0; } # IO::File my $file = "$t/dump-io-file-$$.yaml"; my $fh = new IO::File; # write to IO::File handle $fh->open($file, '>:utf8') or die $!; DumpFile($fh, $testdata); $fh->close; ok -e $file, 'IO::File output file exists'; # read from IO::File handle $fh->open($file, '<:utf8') or die $!; my $yaml = do { local $/; <$fh> }; is $yaml, "--- $testdata\n", 'LoadFile from IO::File contents is correct'; $fh->seek(0, 0); my $read_data = LoadFile($fh) or die $!; $fh->close; is length($read_data), length($testdata), 'LoadFile from IO::File read data'; is $read_data, $testdata, 'LoadFile from IO::File read data'; unlink $file; YAML-1.31/t/bugs-rt.t0000644000175000017500000001253314543037225012722 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use TestYAML tests => 42; run_yaml_tests; __DATA__ === Ticket #105-A YAML doesn't serialize odd objects very well +++ skip_this_for_now +++ skip_unless_modules: FileHandle +++ perl: FileHandle->new( ">/tmp/yaml_bugs_rt_$$" ); +++ yaml --- !!perl/io:FileHandle - xxx === Ticket #105-B YAML doesn't serialize odd objects very well +++ skip_unless_modules: URI +++ no_round_trip +++ perl: URI->new( "http://localhost/" ) +++ yaml --- !!perl/scalar:URI::http http://localhost/ === Ticket #105-C YAML doesn't serialize odd objects very well +++ skip_unless_modules: URI +++ perl: +{ names => ['james','alexander','duncan'], } +++ yaml --- names: - james - alexander - duncan === Ticket #105-D YAML doesn't serialize odd objects very well +++ perl # CGI->new() bless { '.charset' => 'ISO-8859-1', '.fieldnames' => {}, '.parameters' => [], escape => 1, }, 'CGI'; +++ yaml --- !!perl/hash:CGI .charset: ISO-8859-1 .fieldnames: {} .parameters: [] escape: 1 === Ticket #105-E YAML doesn't serialize odd objects very well +++ perl package MyObj::Class; sub new { return bless ['one','two','three'], $_[0]; } package main; MyObj::Class->new(); +++ yaml --- !!perl/array:MyObj::Class - one - two - three === Ticket #2957 Serializing array-elements with dashes [github #36] The problem is quoted map keys in array elements +++ perl: [ { "test - " => 23 } ]; +++ yaml --- - 'test - ': 23 === Ticket #3015 wish: folding length option for YAML +++ skip_this_for_now > YAML.pm, line 557, currently has a folding value of 50 hard-coded. > It would be great if this value became an option... for those who > prefer not to fold, or fold less. I wanted that too. The attached patch adds in the $YAML::FoldLimit config variable to achieve this. I've also got a doc patch which describes this, but 'RT' only has one file-upload field so that'll be in the next comment ... Smylers === Ticket #4066 Number vs. string heuristics for dump +++ perl: { 'version' => '1.10' }; +++ yaml --- version: 1.10 === Ticket #4784 Can't create YAML::Node from 'REF' +++ skip_this_for_now +++ perl: my $bar = 1; my $foo = \\\$bar; bless $foo, "bar" +++ yaml === Ticket #4866 Text with embedded newlines +++ perl {'text' => 'Bla: - Foo - Bar '}; +++ yaml --- text: "Bla:\n\n- Foo\n- Bar\n" === Ticket #5299 Load(Dump({"hi, world" => 1})) fails +++ perl: {"hi, world" => 1} +++ yaml --- 'hi, world': 1 === Ticket #5691 Minor doc error in YAML.pod +++ perl: "YAML:1.0" +++ yaml --- YAML:1.0 === Ticket #6095 Hash keys are not always escaped +++ perl: { 'AVE,' => { '??' => { '??' => 1 } } } +++ yaml --- 'AVE,': '??': '??': 1 === Ticket #6139 0.35 can't deserialize blessed scalars +++ perl: my $x = "abc"; bless \ $x, "ABCD"; +++ yaml --- !!perl/scalar:ABCD abc === Ticket #7146 scalar with many spaces doesn't round trip +++ skip_this_for_now Can't get this to work yet. +++ perl: "A".(" "x200)."B" +++ yaml --- 'A B' === Ticket #8795 !!perl/code blocks are evaluated in package main +++ skip_this_for_now This test passes but not sure if this totally represents what was being reported. Check back later. +++ perl: $YAML::UseCode = 1; package Food; sub { 42; } +++ no_round_trip +++ yaml --- !!perl/code | sub { package Food; use warnings; use strict 'refs'; 42; } === Ticket #8818 YAML::Load fails if the last value in the stream ends with '|' +++ perl: ['o|'] +++ yaml --- - 'o|' === Ticket #12729 < and > need to be quoted ? +++ perl: { a => q(>a), b => q( q()} +++ yaml --- a: '>a' b: ' === Ticket #12770 YAML crashes when tab used for indenting +++ skip_this_for_now Even in the latest version, 0.39, YAML fails when tabulator characters are used for indenting. This is expected since the YAML spec forbids this use of tab characters. However, there is no error message; YAML.pm just dies. Here's an example: perl -MYAML -e "Load(\"Testing:\n\t- Item1\n\")" fails with Died at U:\perl-lib\lib/YAML.pm line 1417. It should at least fail with a message like it does when there's no newline at the end: +++ perl === Ticket #12959-a bug - nested inline collections with extra blanks +++ function: load_passes +++ yaml --- { a: {k: v} } === Ticket #12959-b bug - nested inline collections with extra blanks +++ function: load_passes +++ yaml --- { a: [1] } === Ticket #12959-c bug - nested inline collections with extra blanks +++ function: load_passes +++ yaml --- [ {k: v} ] === Ticket #12959-d bug - nested inline collections with extra blanks +++ function: load_passes +++ yaml --- [ [1] ] === Ticket #13016 Plain Multiline Support +++ skip_this_for_now Fix in upcoming release +++ function: load_passes +++ yaml quoted: "So does this quoted scalar.\n" === #13500 Load(Dump("|foo")) fails +++ perl: "|foo" +++ yaml --- '|foo' === Ticket #13510 Another roundtrip fails [github #48] The problem is quoted map keys in array elements +++ perl [{'RR1 (Schloflplatz - Wannsee)'=> 1, 'm‰fliges Kopfsteinpflaster (Teilstrecke)' => 1}, undef, ] +++ yaml --- - 'RR1 (Schloflplatz - Wannsee)': 1 m‰fliges Kopfsteinpflaster (Teilstrecke): 1 - ~ === Ticket #14938 Load(Dump(">=")) fails +++ perl: ">=" +++ yaml --- '>=' YAML-1.31/t/dump-perl-types-514.t0000644000175000017500000000077514543037225014722 0ustar ingyingyuse strict; use lib -e 't' ? 't' : 'test'; use Test::More; BEGIN { unless ( qr/x/ =~ /\(\?\^/ ){ plan skip_all => "test only for perls v5.13.5-11-gfb85c04 or later"; } } use TestYAML tests => 2; filters { perl => ['eval', 'yaml_dump'] }; no_diff; run_is ( perl => 'yaml' ); __DATA__ === Regular Expression +++ perl: qr{perfect match}; +++ yaml --- !!perl/regexp (?^:perfect match) === Regular Expression with newline +++ perl qr{perfect match}x; +++ yaml --- !!perl/regexp "(?^x:perfect\nmatch)" YAML-1.31/MANIFEST0000644000175000017500000000304414543037225012035 0ustar ingyingy# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.030. CONTRIBUTING Changes LICENSE MANIFEST META.json META.yml Makefile.PL README lib/YAML.pm lib/YAML.pod lib/YAML/Any.pm lib/YAML/Any.pod lib/YAML/Dumper.pm lib/YAML/Dumper.pod lib/YAML/Dumper/Base.pm lib/YAML/Dumper/Base.pod lib/YAML/Error.pm lib/YAML/Error.pod lib/YAML/Loader.pm lib/YAML/Loader.pod lib/YAML/Loader/Base.pm lib/YAML/Loader/Base.pod lib/YAML/Marshall.pm lib/YAML/Marshall.pod lib/YAML/Mo.pm lib/YAML/Node.pm lib/YAML/Node.pod lib/YAML/Tag.pm lib/YAML/Tag.pod lib/YAML/Types.pm lib/YAML/Types.pod t/000-compile-modules.t t/2-scalars.t t/TestYAML.pm t/TestYAMLBase.pm t/author-pod-syntax.t t/basic-tests.t t/bugs-emailed.t t/bugs-rt.t t/changes.t t/dump-basics.t t/dump-blessed-glob.t t/dump-blessed.t t/dump-code.t t/dump-file-utf8.t t/dump-file.t t/dump-nested.t t/dump-opts.t t/dump-perl-types-512.t t/dump-perl-types-514.t t/dump-perl-types.t t/dump-stringify.t t/dump-stringy-numbers.t t/dump-synopsis.t t/dump-tests-512.t t/dump-tests-514.t t/dump-tests.t t/dump-works.t t/errors.t t/export.t t/freeze-thaw.t t/global-api.t t/inbox.t t/io-handle.t t/issue-149.t t/issue-69.t t/load-code.t t/load-fails.t t/load-passes.t t/load-slides.t t/load-spec.t t/load-tests.t t/load-works.t t/long-quoted-value.yaml t/marshall.t t/no-load-blessed.t t/node-info.t t/numify.t t/preserve.t t/pugs-objects.t t/references.t t/regexp.t t/roundtrip.t t/rt-90593.t t/svk-config.yaml t/svk.t t/test.t t/trailing-comments-content.t t/trailing-comments-non-content.t xt/meta.t xt/pmv.t xt/pod.t YAML-1.31/README0000644000175000017500000006124114543037225011567 0ustar ingyingyNAME YAML - YAML Ain't Markup Language™ VERSION This document describes YAML version 1.31. IMPORTANT - PLEASE READ THIS FIRST If you need to use YAML with Perl, it is likely that you will have a look at this module (YAML.pm) first. There are several YAMLmodules in Perl and they all support the simple Load() and Dump() API. Since this one has the obvious name "YAML", it may seem obvious to pick this one. As the author of this module, I humbly ask you to choose another. YAML.pm was the very first YAML implementation in the world, released in 2001. It was originally made as a prototype, over 2 years before the YAML 1.0 spec was published. Although it may work for your needs, it has numerous bugs and is barely maintained. Please consider using these first: * YAML::PP - Pure Perl, Full Featured, Well Maintained * YAML::PP::LibYAML - A libyaml Perl binding like YAML::XS but with the YAML::PP API. The rest of this documentation is left unchanged... SYNOPSIS use YAML; # Load a YAML stream of 3 YAML documents into Perl data structures. my ($hashref, $arrayref, $string) = Load(<<'...'); --- name: ingy # A Mapping age: old weight: heavy # I should comment that I also like pink, but don't tell anybody. favorite colors: - red - green - blue --- - Clark Evans # A Sequence - Oren Ben-Kiki - Ingy döt Net --- > # A Block Scalar You probably think YAML stands for "Yet Another Markup Language". It ain't! YAML is really a data serialization language. But if you want to think of it as a markup, that's OK with me. A lot of people try to use XML as a serialization format. "YAML" is catchy and fun to say. Try it. "YAML, YAML, YAML!!!" ... # Dump the Perl data structures back into YAML. print Dump($string, $arrayref, $hashref); # YAML::Dump is used the same way you'd use Data::Dumper::Dumper use Data::Dumper; print Dumper($string, $arrayref, $hashref); Since version 1.25 YAML.pm supports trailing comments. DESCRIPTION The YAML.pm module implements a YAML Loader and Dumper based on the YAML 1.0 specification. http://www.yaml.org/spec/ YAML is a generic data serialization language that is optimized for human readability. It can be used to express the data structures of most modern programming languages. (Including Perl!!!) For information on the YAML syntax, please refer to the YAML specification. WHY YAML IS COOL YAML is readable for people. It makes clear sense out of complex data structures. You should find that YAML is an exceptional data dumping tool. Structure is shown through indentation, YAML supports recursive data, and hash keys are sorted by default. In addition, YAML supports several styles of scalar formatting for different types of data. YAML is editable. YAML was designed from the ground up to be an excellent syntax for configuration files. Almost all programs need configuration files, so why invent a new syntax for each one? And why subject users to the complexities of XML or native Perl code? YAML is multilingual. Yes, YAML supports Unicode. But I'm actually referring to programming languages. YAML was designed to meet the serialization needs of Perl, Python, Ruby, Tcl, PHP, Javascript and Java. It was also designed to be interoperable between those languages. That means YAML serializations produced by Perl can be processed by Python. YAML is taint safe. Using modules like Data::Dumper for serialization is fine as long as you can be sure that nobody can tamper with your data files or transmissions. That's because you need to use Perl's eval() built-in to deserialize the data. Somebody could add a snippet of Perl to erase your files. YAML's parser does not need to eval anything. YAML is full featured. YAML can accurately serialize all of the common Perl data structures and deserialize them again without losing data relationships. Although it is not 100% perfect (no serializer is or can be perfect), it fares as well as the popular current modules: Data::Dumper, Storable, XML::Dumper and Data::Denter. YAML.pm also has the ability to handle code (subroutine) references and typeglobs. (Still experimental) These features are not found in Perl's other serialization modules. YAML is extensible. The YAML language has been designed to be flexible enough to solve it's own problems. The markup itself has 3 basic construct which resemble Perl's hash, array and scalar. By default, these map to their Perl equivalents. But each YAML node also supports a tagging mechanism (type system) which can cause that node to be interpreted in a completely different manner. That's how YAML can support object serialization and oddball structures like Perl's typeglob. YAML IMPLEMENTATIONS IN PERL This module, YAML.pm, is really just the interface module for YAML modules written in Perl. The basic interface for YAML consists of two functions: Dump and Load. The real work is done by the modules YAML::Dumper and YAML::Loader. Different YAML module distributions can be created by subclassing YAML.pm and YAML::Loader and YAML::Dumper. For example, YAML-Simple consists of YAML::Simple YAML::Dumper::Simple and YAML::Loader::Simple. Why would there be more than one implementation of YAML? Well, despite YAML's offering of being a simple data format, YAML is actually very deep and complex. Implementing the entirety of the YAML specification is a daunting task. For this reason I am currently working on 3 different YAML implementations. YAML The main YAML distribution will keeping evolving to support the entire YAML specification in pure Perl. This may not be the fastest or most stable module though. Currently, YAML.pm has lots of known bugs. It is mostly a great tool for dumping Perl data structures to a readable form. YAML::Tiny The point of YAML::Tiny is to strip YAML down to the 90% that people use most and offer that in a small, fast, stable, pure Perl form. YAML::Tiny will simply die when it is asked to do something it can't. YAML::Syck libsyck is the C based YAML processing library used by the Ruby programming language (and also Python, PHP and Pugs). YAML::Syck is the Perl binding to libsyck. It should be very fast, but may have problems of its own. It will also require C compilation. NOTE: Audrey Tang has actually completed this module and it works great and is 10 times faster than YAML.pm. In the future, there will likely be even more YAML modules. Remember, people other than Ingy are allowed to write YAML modules! FUNCTIONAL USAGE YAML is completely OO under the hood. Still it exports a few useful top level functions so that it is dead simple to use. These functions just do the OO stuff for you. If you want direct access to the OO API see the documentation for YAML::Dumper and YAML::Loader. Exported Functions The following functions are exported by YAML.pm by default. The reason they are exported is so that YAML works much like Data::Dumper. If you don't want functions to be imported, just use YAML with an empty import list: use YAML (); Dump(list-of-Perl-data-structures) Turn Perl data into YAML. This function works very much like Data::Dumper::Dumper(). It takes a list of Perl data structures and dumps them into a serialized form. It returns a string containing the YAML stream. The structures can be references or plain scalars. Load(string-containing-a-YAML-stream) Turn YAML into Perl data. This is the opposite of Dump. Just like Storable's thaw() function or the eval() function in relation to Data::Dumper. It parses a string containing a valid YAML stream into a list of Perl data structures. Exportable Functions These functions are not exported by default but you can request them in an import list like this: use YAML qw'freeze thaw Bless'; freeze() and thaw() Aliases to Dump() and Load() for Storable fans. This will also allow YAML.pm to be plugged directly into modules like POE.pm, that use the freeze/thaw API for internal serialization. DumpFile(filepath, list) Writes the YAML stream to a file instead of just returning a string. LoadFile(filepath) Reads the YAML stream from a file instead of a string. Bless(perl-node, [yaml-node | class-name]) Associate a normal Perl node, with a yaml node. A yaml node is an object tied to the YAML::Node class. The second argument is either a yaml node that you've already created or a class (package) name that supports a yaml_dump() function. A yaml_dump() function should take a perl node and return a yaml node. If no second argument is provided, Bless will create a yaml node. This node is not returned, but can be retrieved with the Blessed() function. Here's an example of how to use Bless. Say you have a hash containing three keys, but you only want to dump two of them. Furthermore the keys must be dumped in a certain order. Here's how you do that: use YAML qw(Dump Bless); $hash = {apple => 'good', banana => 'bad', cauliflower => 'ugly'}; print Dump $hash; Bless($hash)->keys(['banana', 'apple']); print Dump $hash; produces: --- apple: good banana: bad cauliflower: ugly --- banana: bad apple: good Bless returns the tied part of a yaml-node, so that you can call the YAML::Node methods. This is the same thing that YAML::Node::ynode() returns. So another way to do the above example is: use YAML qw(Dump Bless); use YAML::Node; $hash = {apple => 'good', banana => 'bad', cauliflower => 'ugly'}; print Dump $hash; Bless($hash); $ynode = ynode(Blessed($hash)); $ynode->keys(['banana', 'apple']); print Dump $hash; Note that Blessing a Perl data structure does not change it anyway. The extra information is stored separately and looked up by the Blessed node's memory address. Blessed(perl-node) Returns the yaml node that a particular perl node is associated with (see above). Returns undef if the node is not (YAML) Blessed. GLOBAL OPTIONS YAML options are set using a group of global variables in the YAML namespace. This is similar to how Data::Dumper works. For example, to change the indentation width, do something like: local $YAML::Indent = 3; The current options are: DumperClass You can override which module/class YAML uses for Dumping data. LoadBlessed (since 1.25) Default is undef (false) The default was changed in version 1.30. When set to true, YAML nodes with special tags will be automatocally blessed into objects: - !perl/hash:Foo::Bar foo: 42 When loading untrusted YAML, you should disable this option by setting it to 0. This will also disable setting typeglobs when loading them. You can create any kind of object with YAML. The creation itself is not the critical part. If the class has a DESTROY method, it will be called once the object is deleted. An example with File::Temp removing files can be found at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=862373 LoaderClass You can override which module/class YAML uses for Loading data. Indent This is the number of space characters to use for each indentation level when doing a Dump(). The default is 2. By the way, YAML can use any number of characters for indentation at any level. So if you are editing YAML by hand feel free to do it anyway that looks pleasing to you; just be consistent for a given level. SortKeys Default is 1. (true) Tells YAML.pm whether or not to sort hash keys when storing a document. YAML::Node objects can have their own sort order, which is usually what you want. To override the YAML::Node order and sort the keys anyway, set SortKeys to 2. Stringify Default is 0. (false) Objects with string overloading should honor the overloading and dump the stringification of themselves, rather than the actual object's guts. Numify Default is 0. (false) Values that look like numbers (integers, floats) will be numified when loaded. UseHeader Default is 1. (true) This tells YAML.pm whether to use a separator string for a Dump operation. This only applies to the first document in a stream. Subsequent documents must have a YAML header by definition. UseVersion Default is 0. (false) Tells YAML.pm whether to include the YAML version on the separator/header. --- %YAML:1.0 AnchorPrefix Default is ''. Anchor names are normally numeric. YAML.pm simply starts with '1' and increases by one for each new anchor. This option allows you to specify a string to be prepended to each anchor number. UseCode Setting the UseCode option is a shortcut to set both the DumpCode and LoadCode options at once. Setting UseCode to '1' tells YAML.pm to dump Perl code references as Perl (using B::Deparse) and to load them back into memory using eval(). The reason this has to be an option is that using eval() to parse untrusted code is, well, untrustworthy. DumpCode Determines if and how YAML.pm should serialize Perl code references. By default YAML.pm will dump code references as dummy placeholders (much like Data::Dumper). If DumpCode is set to '1' or 'deparse', code references will be dumped as actual Perl code. LoadCode LoadCode is the opposite of DumpCode. It tells YAML if and how to deserialize code references. When set to '1' or 'deparse' it will use eval(). Since this is potentially risky, only use this option if you know where your YAML has been. LoadCode must be enabled also to use the feature of evaluating typeglobs (because with the typeglob feature you would be able to set the variable $YAML::LoadCode from a YAML file). Preserve When set to true, this option tells the Loader to load hashes into YAML::Node objects. These are tied hashes. This has the effect of remembering the key order, thus it will be preserved when the hash is dumped again. See YAML::Node for more information. UseBlock YAML.pm uses heuristics to guess which scalar style is best for a given node. Sometimes you'll want all multiline scalars to use the 'block' style. If so, set this option to 1. NOTE: YAML's block style is akin to Perl's here-document. UseFold (Not supported anymore since v0.60) If you want to force YAML to use the 'folded' style for all multiline scalars, then set $UseFold to 1. NOTE: YAML's folded style is akin to the way HTML folds text, except smarter. UseAliases YAML has an alias mechanism such that any given structure in memory gets serialized once. Any other references to that structure are serialized only as alias markers. This is how YAML can serialize duplicate and recursive structures. Sometimes, when you KNOW that your data is nonrecursive in nature, you may want to serialize such that every node is expressed in full. (ie as a copy of the original). Setting $YAML::UseAliases to 0 will allow you to do this. This also may result in faster processing because the lookup overhead is by bypassed. THIS OPTION CAN BE DANGEROUS. If your data is recursive, this option will cause Dump() to run in an endless loop, chewing up your computers memory. You have been warned. CompressSeries Default is 1. Compresses the formatting of arrays of hashes: - foo: bar - bar: foo becomes: - foo: bar - bar: foo Since this output is usually more desirable, this option is turned on by default. QuoteNumericStrings Default is 0. (false) Adds detection mechanisms to encode strings that resemble numbers with mandatory quoting. This ensures leading that things like leading/trailing zeros and other formatting are preserved. YAML TERMINOLOGY YAML is a full featured data serialization language, and thus has its own terminology. It is important to remember that although YAML is heavily influenced by Perl and Python, it is a language in its own right, not merely just a representation of Perl structures. YAML has three constructs that are conspicuously similar to Perl's hash, array, and scalar. They are called mapping, sequence, and string respectively. By default, they do what you would expect. But each instance may have an explicit or implicit tag (type) that makes it behave differently. In this manner, YAML can be extended to represent Perl's Glob or Python's tuple, or Ruby's Bigint. stream A YAML stream is the full sequence of Unicode characters that a YAML parser would read or a YAML emitter would write. A stream may contain one or more YAML documents separated by YAML headers. --- a: mapping foo: bar --- - a - sequence document A YAML document is an independent data structure representation within a stream. It is a top level node. Each document in a YAML stream must begin with a YAML header line. Actually the header is optional on the first document. --- This: top level mapping is: - a - YAML - document header A YAML header is a line that begins a YAML document. It consists of three dashes, possibly followed by more info. Another purpose of the header line is that it serves as a place to put top level tag and anchor information. --- !recursive-sequence &001 - * 001 - * 001 node A YAML node is the representation of a particular data structure. Nodes may contain other nodes. (In Perl terms, nodes are like scalars. Strings, arrayrefs and hashrefs. But this refers to the serialized format, not the in- memory structure.) tag This is similar to a type. It indicates how a particular YAML node serialization should be transferred into or out of memory. For instance a Foo::Bar object would use the tag 'perl/Foo::Bar': - !perl/Foo::Bar foo: 42 bar: stool collection A collection is the generic term for a YAML data grouping. YAML has two types of collections: mappings and sequences. (Similar to hashes and arrays) mapping A mapping is a YAML collection defined by unordered key/value pairs with unique keys. By default YAML mappings are loaded into Perl hashes. a mapping: foo: bar two: times two is 4 sequence A sequence is a YAML collection defined by an ordered list of elements. By default YAML sequences are loaded into Perl arrays. a sequence: - one bourbon - one scotch - one beer scalar A scalar is a YAML node that is a single value. By default YAML scalars are loaded into Perl scalars. a scalar key: a scalar value YAML has many styles for representing scalars. This is important because varying data will have varying formatting requirements to retain the optimum human readability. plain scalar A plain scalar is unquoted. All plain scalars are automatic candidates for "implicit tagging". This means that their tag may be determined automatically by examination. The typical uses for this are plain alpha strings, integers, real numbers, dates, times and currency. - a plain string - -42 - 3.1415 - 12:34 - 123 this is an error single quoted scalar This is similar to Perl's use of single quotes. It means no escaping except for single quotes which are escaped by using two adjacent single quotes. - 'When I say ''\n'' I mean "backslash en"' double quoted scalar This is similar to Perl's use of double quotes. Character escaping can be used. - "This scalar\nhas two lines, and a bell -->\a" folded scalar This is a multiline scalar which begins on the next line. It is indicated by a single right angle bracket. It is unescaped like the single quoted scalar. Line folding is also performed. - > This is a multiline scalar which begins on the next line. It is indicated by a single carat. It is unescaped like the single quoted scalar. Line folding is also performed. block scalar This final multiline form is akin to Perl's here-document except that (as in all YAML data) scope is indicated by indentation. Therefore, no ending marker is required. The data is verbatim. No line folding. - | QTY DESC PRICE TOTAL --- ---- ----- ----- 1 Foo Fighters $19.95 $19.95 2 Bar Belles $29.95 $59.90 parser A YAML processor has four stages: parse, load, dump, emit. A parser parses a YAML stream. YAML.pm's Load() function contains a parser. loader The other half of the Load() function is a loader. This takes the information from the parser and loads it into a Perl data structure. dumper The Dump() function consists of a dumper and an emitter. The dumper walks through each Perl data structure and gives info to the emitter. emitter The emitter takes info from the dumper and turns it into a YAML stream. NOTE: In YAML.pm the parserloader and the dumperemitter code are currently very closely tied together. In the future they may be broken into separate stages. For more information please refer to the immensely helpful YAML specification available at http://www.yaml.org/spec/. YSH - THE YAML SHELL The YAML::Shell distribution provides script called 'ysh', the YAML shell. ysh provides a simple, interactive way to play with YAML. If you type in Perl code, it displays the result in YAML. If you type in YAML it turns it into Perl code. To run ysh, (assuming you installed it along with YAML.pm) simply type: ysh [options] Please read the ysh documentation for the full details. There are lots of options. BUGS & DEFICIENCIES If you find a bug in YAML, please try to recreate it in the YAML Shell with logging turned on ('ysh -L'). When you have successfully reproduced the bug, please mail the LOG file to the author (ingy@cpan.org). WARNING: This is still ALPHA code. Well, most of this code has been around for years... BIGGER WARNING: YAML.pm has been slow in the making, but I am committed to having top notch YAML tools in the Perl world. The YAML team is close to finalizing the YAML 1.1 spec. This version of YAML.pm is based off of a very old pre 1.0 spec. In actuality there isn't a ton of difference, and this YAML.pm is still fairly useful. Things will get much better in the future. RESOURCES http://www.yaml.org is the official YAML website. http://www.yaml.org/spec/ is the YAML 1.2 specification. SEE ALSO * YAML::PP - This is almost certainly the YAML module you are looking for. It is full-featured and well maintained. * YAML::PP::LibYAML - Same overall API as YAML::PP but uses the libyaml shared library for speed. AUTHOR Ingy döt Net COPYRIGHT AND LICENSE Copyright 2001-2023. Ingy döt Net. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html