YAML: Versionsupdate
authorSven Schöling <s.schoeling@linet-services.de>
Wed, 1 Apr 2015 16:48:47 +0000 (18:48 +0200)
committerSven Schöling <s.schoeling@linet-services.de>
Wed, 1 Apr 2015 16:48:47 +0000 (18:48 +0200)
13 files changed:
modules/override/YAML.pm
modules/override/YAML/Any.pm [new file with mode: 0644]
modules/override/YAML/Base.pm [deleted file]
modules/override/YAML/Dumper.pm
modules/override/YAML/Dumper/Base.pm
modules/override/YAML/Error.pm
modules/override/YAML/Loader.pm
modules/override/YAML/Loader/Base.pm
modules/override/YAML/Marshall.pm
modules/override/YAML/Mo.pm [new file with mode: 0644]
modules/override/YAML/Node.pm
modules/override/YAML/Tag.pm
modules/override/YAML/Types.pm

index 3b6aad5..56c3c95 100644 (file)
@@ -1,23 +1,23 @@
 package YAML;
-use strict; use warnings;
-use YAML::Base;
-use base 'YAML::Base';
-use YAML::Node;         # XXX This is a temp fix for Module::Build
-use 5.006001;
-our $VERSION = '0.62';
-our @EXPORT = qw'Dump Load';
-our @EXPORT_OK = qw'freeze thaw DumpFile LoadFile Bless Blessed';
+our $VERSION = '1.14';
+
+use YAML::Mo;
+
+use Exporter;
+push @YAML::ISA, 'Exporter';
+our @EXPORT = qw{ Dump Load };
+our @EXPORT_OK = qw{ freeze thaw DumpFile LoadFile Bless Blessed };
+
+use YAML::Node; # XXX This is a temp fix for Module::Build
 
 # XXX This VALUE nonsense needs to go.
 use constant VALUE => "\x07YAML\x07VALUE\x07";
 
 # YAML Object Properties
-field dumper_class => 'YAML::Dumper';
-field loader_class => 'YAML::Loader';
-field dumper_object =>
-    -init => '$self->init_action_object("dumper")';
-field loader_object =>
-    -init => '$self->init_action_object("loader")';
+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;
@@ -53,8 +53,9 @@ sub DumpFile {
             ($mode, $filename) = ($1, $2);
         }
         open $OUT, $mode, $filename
-          or YAML::Base->die('YAML_DUMP_ERR_FILE_OUTPUT', $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(@_);
 }
@@ -66,9 +67,10 @@ sub LoadFile {
         $IN = $filename;
     }
     else {
-        open $IN, $filename
-          or YAML::Base->die('YAML_LOAD_ERR_FILE_INPUT', $filename, $!);
+        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> });
 }
 
@@ -96,692 +98,3 @@ sub Blessed {
 sub global_object { $global }
 
 1;
-
-__END__
-
-=head1 NAME
-
-YAML - YAML Ain't Markup Language (tm)
-
-=head1 SYNOPSIS
-
-    use YAML;
-    
-    # Load a YAML stream of 3 YAML documents into Perl data structures.
-    my ($hashref, $arrayref, $string) = Load(<<'...');
-    ---
-    name: ingy
-    age: old
-    weight: heavy
-    # I should comment that I also like pink, but don't tell anybody.
-    favorite colors:
-        - red
-        - green
-        - blue
-    ---
-    - Clark Evans
-    - Oren Ben-Kiki
-    - Ingy döt Net
-    --- >
-    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); 
-
-=head1 DESCRIPTION
-
-The YAML.pm module implements a YAML Loader and Dumper based on the YAML
-1.0 specification. L<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.
-
-=head1 WHY YAML IS COOL
-
-=over 4
-
-=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<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.
-
-=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<Dump> and C<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.
-
-=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::Lite
-
-The point of YAML::Lite is to strip YAML down to the 90% that people
-use most and offer that in a small, fast, stable, pure Perl form.
-YAML::Lite will simply die when it is asked to do something it can't.
-
-=item YAML::Syck
-
-C<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 C<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.
-
-=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 4
-
-=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 strucures 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 4
-
-=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
-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.
-
-=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 4
-
-=item DumperClass
-
-You can override which module/class YAML uses for Dumping data.
-
-=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 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.
-
-DumpCode can also be set to a subroutine reference so that you can
-write your own serializing routine. YAML.pm passes you the code ref. You
-pass back the serialization (as a string) and a format indicator. The
-format indicator is a simple string like: 'deparse' or 'bytecode'.
-
-=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<eval()>. Since this is potentially risky, only use this option if you
-know where your YAML has been.
-
-LoadCode can also be set to a subroutine reference so that you can write
-your own deserializing routine. YAML.pm passes the serialization (as a
-string) and a format indicator. You pass back the code reference.
-
-=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
-
-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. *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.
-
-=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.
-
-=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 4
-
-=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 stucture. 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 sclar 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 parser/loader and the dumper/emitter 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<http://www.yaml.org/spec/>.
-
-=head1 ysh - The YAML Shell
-
-The YAML distribution ships with a 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<ysh> 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 *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.
-
-=head1 RESOURCES
-
-L<http://lists.sourceforge.net/lists/listinfo/yaml-core> is the mailing
-list. This is where the language is discussed and designed.
-
-L<http://www.yaml.org> is the official YAML website.
-
-L<http://www.yaml.org/spec/> is the YAML 1.0 specification.
-
-L<http://yaml.kwiki.org> is the official YAML wiki.
-
-=head1 SEE ALSO
-
-See YAML::Syck. Fast!
-
-=head1 AUTHOR
-
-Ingy döt Net <ingy@cpan.org>
-
-is resonsible for YAML.pm.
-
-The YAML serialization language is the result of years of collaboration
-between Oren Ben-Kiki, Clark Evans and Ingy döt Net. Several others
-have added help along the way.
-
-=head1 COPYRIGHT
-
-Copyright (c) 2005, 2006. Ingy döt Net. All rights reserved.
-Copyright (c) 2001, 2002, 2005. Brian Ingerson. All rights reserved.
-
-This program is free software; you can redistribute it and/or modify it
-under the same terms as Perl itself.
-
-See L<http://www.perl.com/perl/misc/Artistic.html>
-
-=cut
diff --git a/modules/override/YAML/Any.pm b/modules/override/YAML/Any.pm
new file mode 100644 (file)
index 0000000..c2d35ee
--- /dev/null
@@ -0,0 +1,122 @@
+use strict; use warnings;
+package YAML::Any;
+our $VERSION = '1.14';
+
+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
+);
+
+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;
diff --git a/modules/override/YAML/Base.pm b/modules/override/YAML/Base.pm
deleted file mode 100644 (file)
index f97f286..0000000
+++ /dev/null
@@ -1,200 +0,0 @@
-package YAML::Base;
-use strict; use warnings;
-use base 'Exporter';
-
-our @EXPORT = qw(field XXX);
-
-sub new {
-    my $class = shift;
-    $class = ref($class) || $class;
-    my $self = bless {}, $class;
-    while (@_) {
-        my $method = shift;
-        $self->$method(shift);
-    }
-    return $self;
-}
-
-# Use lexical subs to reduce pollution of private methods by base class.
-my ($_new_error, $_info, $_scalar_info, $parse_arguments, $default_as_code);
-
-sub XXX {
-    require Data::Dumper;
-    CORE::die(Data::Dumper::Dumper(@_));
-}
-
-my %code = (
-    sub_start =>
-      "sub {\n",
-    set_default =>
-      "  \$_[0]->{%s} = %s\n    unless exists \$_[0]->{%s};\n",
-    init =>
-      "  return \$_[0]->{%s} = do { my \$self = \$_[0]; %s }\n" .
-      "    unless \$#_ > 0 or defined \$_[0]->{%s};\n",
-    return_if_get =>
-      "  return \$_[0]->{%s} unless \$#_ > 0;\n",
-    set =>
-      "  \$_[0]->{%s} = \$_[1];\n",
-    sub_end => 
-      "  return \$_[0]->{%s};\n}\n",
-);
-
-sub field {
-    my $package = caller;
-    my ($args, @values) = &$parse_arguments(
-        [ qw(-package -init) ],
-        @_,
-    );
-    my ($field, $default) = @values;
-    $package = $args->{-package} if defined $args->{-package};
-    return if defined &{"${package}::$field"};
-    my $default_string =
-        ( ref($default) eq 'ARRAY' and not @$default )
-        ? '[]'
-        : (ref($default) eq 'HASH' and not keys %$default )
-          ? '{}'
-          : &$default_as_code($default);
-
-    my $code = $code{sub_start};
-    if ($args->{-init}) {
-        my $fragment = $code{init};
-        $code .= sprintf $fragment, $field, $args->{-init}, ($field) x 4;
-    }
-    $code .= sprintf $code{set_default}, $field, $default_string, $field
-      if defined $default;
-    $code .= sprintf $code{return_if_get}, $field;
-    $code .= sprintf $code{set}, $field;
-    $code .= sprintf $code{sub_end}, $field;
-
-    my $sub = eval $code;
-    die $@ if $@;
-    no strict 'refs';
-    *{"${package}::$field"} = $sub;
-    return $code if defined wantarray;
-}
-
-sub die {
-    my $self = shift;
-    my $error = $self->$_new_error(@_);
-    $error->type('Error');
-    Carp::croak($error->format_message);
-}
-
-sub warn {
-    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
-sub node_info {
-    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;
-};
-    
-$parse_arguments = sub {
-    my $paired_arguments = shift || []; 
-    my ($args, @values) = ({}, ());
-    my %pairs = map { ($_, 1) } @$paired_arguments;
-    while (@_) {
-        my $elem = shift;
-        if (defined $elem and defined $pairs{$elem} and @_) {
-            $args->{$elem} = shift;
-        }
-        else {
-            push @values, $elem;
-        }
-    }
-    return wantarray ? ($args, @values) : $args;        
-};
-
-$default_as_code = sub {
-    no warnings 'once';
-    require Data::Dumper;
-    local $Data::Dumper::Sortkeys = 1;
-    my $code = Data::Dumper::Dumper(shift);
-    $code =~ s/^\$VAR1 = //;
-    $code =~ s/;$//;
-    return $code;
-};
-
-1;
-
-__END__
-
-=head1 NAME
-
-YAML::Base - Base class for YAML classes
-
-=head1 SYNOPSIS
-
-    package YAML::Something;
-    use YAML::Base -base;
-
-=head1 DESCRIPTION
-
-YAML::Base is the parent of all YAML classes.
-
-=head1 AUTHOR
-
-Ingy döt Net <ingy@cpan.org>
-
-=head1 COPYRIGHT
-
-Copyright (c) 2006. Ingy döt Net. All rights reserved.
-
-This program is free software; you can redistribute it and/or modify it
-under the same terms as Perl itself.
-
-See L<http://www.perl.com/perl/misc/Artistic.html>
-
-=cut
index 5521f8c..5f75ab2 100644 (file)
@@ -1,23 +1,25 @@
 package YAML::Dumper;
-use strict; use warnings;
-use YAML::Base;
-use base 'YAML::Dumper::Base';
 
+use YAML::Mo;
+extends 'YAML::Dumper::Base';
+
+use YAML::Dumper::Base;
 use YAML::Node;
 use YAML::Types;
+use Scalar::Util qw();
 
 # Context constants
-use constant KEY => 3;
-use constant BLESSED => 4;
+use constant KEY       => 3;
+use constant BLESSED   => 4;
 use constant FROMARRAY => 5;
-use constant VALUE => "\x07YAML\x07VALUE\x07";
+use constant VALUE     => "\x07YAML\x07VALUE\x07";
 
 # Common YAML character sets
 my $ESCAPE_CHAR = '[\\x00-\\x08\\x0b-\\x0d\\x0e-\\x1f]';
-my $LIT_CHAR = '|';    
+my $LIT_CHAR    = '|';
 
 #==============================================================================
-# OO version of Dump. YAML->new->dump($foo); 
+# OO version of Dump. YAML->new->dump($foo);
 sub dump {
     my $self = shift;
     $self->stream('');
@@ -42,7 +44,7 @@ sub dump {
 sub _emit_header {
     my $self = shift;
     my ($node) = @_;
-    if (not $self->use_header and 
+    if (not $self->use_header and
         $self->document == 1
        ) {
         $self->die('YAML_DUMP_ERR_NO_HEADER')
@@ -79,9 +81,7 @@ sub _prewalk {
     }
 
     # Handle regexps
-    if (ref($_[0]) eq 'Regexp') {  
-        $self->transferred->{$node_id} =
-          YAML::Type::regexp->yaml_dump($_[0], $class, $self);
+    if (ref($_[0]) eq 'Regexp') {
         return;
     }
 
@@ -113,10 +113,10 @@ sub _prewalk {
         $self->transferred->{$node_id} = 'placeholder';
         YAML::Type::code->yaml_dump(
             $self->dump_code,
-            $_[0], 
+            $_[0],
             $self->transferred->{$node_id}
         );
-        ($class, $type, $node_id) = 
+        ($class, $type, $node_id) =
           $self->node_info(\ $self->transferred->{$node_id}, $stringify);
         $self->{id_refcnt}{$node_id}++;
         return;
@@ -144,6 +144,7 @@ sub _prewalk {
     }
 
     # 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;
@@ -164,7 +165,7 @@ sub _prewalk {
         my $ref_ynode = $self->transferred->{$node_id} =
           YAML::Type::ref->yaml_dump($value);
 
-        my $glob_ynode = $ref_ynode->{&VALUE} = 
+        my $glob_ynode = $ref_ynode->{&VALUE} =
           YAML::Type::glob->yaml_dump($$value);
 
         (undef, undef, $node_id) = $self->node_info($glob_ynode, $stringify);
@@ -209,7 +210,12 @@ sub _emit_node {
     my $self = shift;
     my ($type, $node_id);
     my $ref = ref($_[0]);
-    if ($ref and $ref ne 'Regexp') {
+    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 {
@@ -232,7 +238,7 @@ sub _emit_node {
             $ynode = ynode($self->transferred->{$node_id});
             $tag = defined $ynode ? $ynode->tag->short : '';
             $type = 'SCALAR';
-            (undef, undef, $node_id) = 
+            (undef, undef, $node_id) =
               $self->node_info(
                   \ $self->transferred->{$node_id},
                   $self->stringify
@@ -270,7 +276,7 @@ sub _emit_node {
     return $self->_emit_str("$value");
 }
 
-# A YAML mapping is akin to a Perl hash. 
+# A YAML mapping is akin to a Perl hash.
 sub _emit_mapping {
     my $self = shift;
     my ($value, $tag, $node_id, $context) = @_;
@@ -351,7 +357,7 @@ sub _emit_sequence {
     $self->{stream} .= " !$tag" if $tag;
 
     return ($self->{stream} .= " []\n") if @$value == 0;
-        
+
     $self->{stream} .= "\n"
       unless $self->headless && not($self->headless(0));
 
@@ -423,7 +429,7 @@ sub _emit_str {
     while (1) {
         $self->_emit($sf),
         $self->_emit_plain($_[0]),
-        $self->_emit($ef), last 
+        $self->_emit($ef), last
           if not defined $_[0];
         $self->_emit($sf, '=', $ef), last
           if $_[0] eq VALUE;
@@ -451,6 +457,10 @@ sub _emit_str {
             $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]);
@@ -469,10 +479,23 @@ sub _emit_str {
     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] =~ /[\{\[\]\},]/;
@@ -480,6 +503,7 @@ sub is_valid_plain {
     return 0 if $_[0] =~ /\s#/;
     return 0 if $_[0] =~ /\:(\s|$)/;
     return 0 if $_[0] =~ /[\s\|\>]$/;
+    return 0 if $_[0] eq '-';
     return 1;
 }
 
@@ -533,7 +557,7 @@ sub indent {
 }
 
 # Escapes for unprintable characters
-my @escapes = qw(\z   \x01 \x02 \x03 \x04 \x05 \x06 \a
+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
@@ -549,36 +573,3 @@ sub escape {
 }
 
 1;
-
-__END__
-
-=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 <ingy@cpan.org>
-
-=head1 COPYRIGHT
-
-Copyright (c) 2006. Ingy döt Net. All rights reserved.
-
-This program is free software; you can redistribute it and/or modify it
-under the same terms as Perl itself.
-
-See L<http://www.perl.com/perl/misc/Artistic.html>
-
-=cut
index 8e4de0c..23db7b1 100644 (file)
@@ -1,35 +1,37 @@
 package YAML::Dumper::Base;
-use strict; use warnings;
-use YAML::Base; use base 'YAML::Base';
+
+use YAML::Mo;
+
 use YAML::Node;
 
 # YAML Dumping options
-field spec_version => '1.0';
-field indent_width => 2;
-field use_header => 1;
-field use_version => 0;
-field sort_keys => 1;
-field anchor_prefix => '';
-field dump_code => 0;
-field use_block => 0;
-field use_fold => 0;
-field compress_series => 1;
-field inline_series => 0;
-field use_aliases => 1;
-field purity => 0;
-field stringify => 0;
+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
-field stream => '';
-field document => 0;
-field transferred => {};
-field id_refcnt => {};
-field id_anchor => {};
-field anchor => 1;
-field level => 0;
-field offset => [];
-field headless => 0;
-field blessed_map => {};
+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
@@ -64,6 +66,8 @@ sub set_global_options {
       if defined $YAML::Purity;
     $self->stringify($YAML::Stringify)
       if defined $YAML::Stringify;
+    $self->quote_numeric_strings($YAML::QuoteNumericStrings)
+      if defined $YAML::QuoteNumericStrings;
 }
 
 sub dump {
@@ -75,16 +79,16 @@ sub blessed {
     my $self = shift;
     my ($ref) = @_;
     $ref = \$_[0] unless ref $ref;
-    my (undef, undef, $node_id) = YAML::Base->node_info($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::Base->node_info($ref);
+    my (undef, undef, $node_id) = YAML::Mo::Object->node_info($ref);
     if (not defined $blessing) {
         $ynode = YAML::Node->new($ref);
     }
@@ -105,33 +109,3 @@ sub bless {
 }
 
 1;
-
-__END__
-
-=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 <ingy@cpan.org>
-
-=head1 COPYRIGHT
-
-Copyright (c) 2006. Ingy döt Net. All rights reserved.
-
-This program is free software; you can redistribute it and/or modify it
-under the same terms as Perl itself.
-
-See L<http://www.perl.com/perl/misc/Artistic.html>
-
-=cut
index 23b9c5c..e855092 100644 (file)
@@ -1,12 +1,12 @@
 package YAML::Error;
-use strict; use warnings;
-use YAML::Base; use base 'YAML::Base';
 
-field 'code';
-field 'type' => 'Error';
-field 'line';
-field 'document';
-field 'arguments' => [];
+use YAML::Mo;
+
+has 'code';
+has 'type' => default => sub {'Error'};
+has 'line';
+has 'document';
+has 'arguments' => default => sub {[]};
 
 my ($error_messages, %line_adjust);
 
@@ -149,11 +149,11 @@ YAML_LOAD_WARN_GLOB_IO
   Can't load an IO filehandle. Yet!!!
 ...
 
-%line_adjust = map {($_, 1)} 
+%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_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
@@ -185,36 +185,7 @@ YAML_LOAD_WARN_GLOB_IO
     );
 
 package YAML::Warning;
-use base 'YAML::Error';
-
-1;
-
-__END__
-
-=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
+our @ISA = 'YAML::Error';
 
-This module provides a C<die> and a C<warn> facility.
-
-=head1 AUTHOR
-
-Ingy döt Net <ingy@cpan.org>
-
-=head1 COPYRIGHT
-
-Copyright (c) 2006. Ingy döt Net. All rights reserved.
-
-This program is free software; you can redistribute it and/or modify it
-under the same terms as Perl itself.
-
-See L<http://www.perl.com/perl/misc/Artistic.html>
-
-=cut
+1;
index b926f55..672f412 100644 (file)
@@ -1,19 +1,21 @@
 package YAML::Loader;
-use strict; use warnings;
-use YAML::Base;
-use base 'YAML::Loader::Base';
+
+use YAML::Mo;
+extends 'YAML::Loader::Base';
+
+use YAML::Loader::Base;
 use YAML::Types;
 
 # Context constants
-use constant LEAF => 1;
+use constant LEAF       => 1;
 use constant COLLECTION => 2;
-use constant VALUE => "\x07YAML\x07VALUE\x07";
-use constant COMMENT => "\x07YAML\x07COMMENT\x07";
+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 $FOLD_CHAR   = '>';
+my $LIT_CHAR    = '|';
 my $LIT_CHAR_RX = "\\$LIT_CHAR";
 
 sub load {
@@ -32,8 +34,7 @@ sub _parse {
     $self->line(0);
     $self->die('YAML_PARSE_ERR_BAD_CHARS')
       if $self->stream =~ /$ESCAPE_CHAR/;
-    # $self->die('YAML_PARSE_ERR_NO_FINAL_NEWLINE')
-    $self->{stream} .= "\n"
+    $self->die('YAML_PARSE_ERR_NO_FINAL_NEWLINE')
       if length($self->stream) and
          $self->{stream} !~ s/(.)\n\Z/$1/s;
     $self->lines([split /\x0a/, $self->stream, -1]);
@@ -251,17 +252,31 @@ sub _parse_explicit {
     my $self = shift;
     my ($node, $explicit) = @_;
     my ($type, $class);
-    if ($explicit =~ /^\!perl\/(hash|array|scalar)\:(\w(\w|\:\:)*)?$/) {
+    if ($explicit =~ /^\!?perl\/(hash|array|ref|scalar)(?:\:(\w(\w|\:\:)*)?)?$/) {
         ($type, $class) = (($1 || ''), ($2 || ''));
-        if (ref $node) {
-            return CORE::bless $node, $class;
+
+        # 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;
         }
-        else {
-            return CORE::bless \$node, $class;
+
+        if ( $type eq "scalar" and length($class) and !ref($node) ) {
+            my $value = $node;
+            $node = \$value;
         }
+
+        if ( length($class) ) {
+            CORE::bless($node, $class);
+        }
+
+        return $node;
     }
-    if ($explicit =~
-        /^\!?perl\/(undef|glob|regexp|code|ref)\:(\w(\w|\:\:)*)?$/) {
+    if ($explicit =~ m{^!?perl/(glob|regexp|code)(?:\:(\w(\w|\:\:)*)?)?$}) {
         ($type, $class) = (($1 || ''), ($2 || ''));
         my $type_class = "YAML::Type::$type";
         no strict 'refs';
@@ -498,7 +513,8 @@ sub _parse_inline_seq {
 sub _parse_inline_double_quoted {
     my $self = shift;
     my $node;
-    if ($self->inline =~ /^"((?:\\"|[^"])*)"\s*(.*)$/) {
+    # https://rt.cpan.org/Public/Bug/Display.html?id=90593
+    if ($self->inline =~ /^"((?:(?:\\"|[^"]){0,32766}){0,32766})"\s*(.*)$/) {
         $node = $1;
         $self->inline($2);
         $node =~ s/\\"/"/g;
@@ -514,7 +530,7 @@ sub _parse_inline_double_quoted {
 sub _parse_inline_single_quoted {
     my $self = shift;
     my $node;
-    if ($self->inline =~ /^'((?:''|[^'])*)'\s*(.*)$/) {
+    if ($self->inline =~ /^'((?:(?:''|[^']){0,32766}){0,32766})'\s*(.*)$/) {
         $node = $1;
         $self->inline($2);
         $node =~ s/''/'/g;
@@ -546,7 +562,7 @@ sub _parse_implicit {
     return $value if $value eq '';
     return undef if $value =~ /^~$/;
     return $value
-      unless $value =~ /^[\@\`\^]/ or
+      unless $value =~ /^[\@\`]/ or
              $value =~ /^[\-\?]\s/;
     $self->die('YAML_PARSE_ERR_BAD_IMPLICIT', $value);
 }
@@ -630,7 +646,7 @@ sub _parse_next_line {
         else {
             # First get rid of any comments.
             while (@{$self->lines} && ($self->lines->[0] =~ /^\s*#/)) {
-                $self->lines->[0] =~ /^( *)/ or die;
+                $self->lines->[0] =~ /^( *)/;
                 last unless length($1) <= $offset;
                 shift @{$self->lines};
                 $self->{line}++;
@@ -655,7 +671,8 @@ sub _parse_next_line {
             return;
         }
         else {
-            $self->lines->[0] =~ /^( *)\S/ or die;
+            $self->lines->[0] =~ /^( *)\S/ or
+                $self->die('YAML_PARSE_ERR_NONSPACE_INDENTATION');
             if (length($1) > $offset) {
                 $self->offset->[$level+1] = length($1);
             }
@@ -714,54 +731,25 @@ sub _parse_next_line {
 #==============================================================================
 
 # Printable characters for escapes
-my %unescapes =
-  (
-   z => "\x00", a => "\x07", t => "\x09",
-   n => "\x0a", v => "\x0b", f => "\x0c",
-   r => "\x0d", e => "\x1b", '\\' => '\\',
+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\\fartz]|x([0-9a-fA-F]{2}))/
+    $node =~ s/\\([never\\fart0]|x([0-9a-fA-F]{2}))/
               (length($1)>1)?pack("H2",$2):$unescapes{$1}/gex;
     return $node;
 }
 
 1;
-
-__END__
-
-=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 <ingy@cpan.org>
-
-=head1 COPYRIGHT
-
-Copyright (c) 2006. Ingy döt Net. All rights reserved.
-
-This program is free software; you can redistribute it and/or modify it
-under the same terms as Perl itself.
-
-See L<http://www.perl.com/perl/misc/Artistic.html>
-
-=cut
index 4d5b02d..6a3504c 100644 (file)
@@ -1,25 +1,24 @@
 package YAML::Loader::Base;
-use strict; use warnings;
-use YAML::Base; use base 'YAML::Base';
 
-field load_code => 0;
-
-field stream => '';
-field document => 0;
-field line => 0;
-field documents => [];
-field lines => [];
-field eos => 0;
-field done => 0;
-field anchor2node => {};
-field level => 0;
-field offset => [];
-field preface => '';
-field content => '';
-field indent => 0;
-field major_version => 0;
-field minor_version => 0;
-field inline => '';
+use YAML::Mo;
+
+has load_code     => 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 {''};
 
 sub set_global_options {
     my $self = shift;
@@ -32,33 +31,3 @@ sub load {
 }
 
 1;
-
-__END__
-
-=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 <ingy@cpan.org>
-
-=head1 COPYRIGHT
-
-Copyright (c) 2006. Ingy döt Net. All rights reserved.
-
-This program is free software; you can redistribute it and/or modify it
-under the same terms as Perl itself.
-
-See L<http://www.perl.com/perl/misc/Artistic.html>
-
-=cut
index 5985ece..14d378b 100644 (file)
@@ -1,6 +1,7 @@
-package YAML::Marshall;
 use strict; use warnings;
-use YAML::Node();
+package YAML::Marshall;
+
+use YAML::Node ();
 
 sub import {
     my $class = shift;
@@ -11,7 +12,7 @@ sub import {
     }
 
     my $tag = shift;
-    if ($tag) {
+    if ( $tag ) {
         no warnings 'once';
         $YAML::TagClass->{$tag} = $package;
         ${$package . "::YamlTag"} = $tag;
@@ -44,34 +45,3 @@ sub yaml_ynode {
 }
 
 1;
-
-__END__
-
-=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 <ingy@cpan.org>
-
-=head1 COPYRIGHT
-
-Copyright (c) 2006. Ingy döt Net. All rights reserved.
-
-This program is free software; you can redistribute it and/or modify it
-under the same terms as Perl itself.
-
-See L<http://www.perl.com/perl/misc/Artistic.html>
-
-=cut
diff --git a/modules/override/YAML/Mo.pm b/modules/override/YAML/Mo.pm
new file mode 100644 (file)
index 0000000..c669ff0
--- /dev/null
@@ -0,0 +1,80 @@
+package YAML::Mo; $VERSION = '0.88';
+# use Mo qw[builder default import];
+#   The following line of code was produced from the previous line by
+#   Mo::Inline version 0.31
+no warnings;my$M=__PACKAGE__.'::';*{$M.Object::new}=sub{bless{@_[1..$#_]},$_[0]};*{$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}};$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;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)=@_;$a{default}or return$m;sub{$#_?$m->(@_):!exists$_[0]{$n}?$_[0]{$n}=$a{default}->(@_):$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;
index 69affcf..81c2727 100644 (file)
@@ -1,20 +1,26 @@
-package YAML::Node;
 use strict; use warnings;
-use YAML::Base; use base 'YAML::Base';
+package YAML::Node;
+
 use YAML::Tag;
+require YAML::Mo;
 
-our @EXPORT = qw(ynode);
+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]});
+        $self = tied(%{$_[0]});
     }
     elsif (ref($_[0]) eq 'ARRAY') {
-       $self = tied(@{$_[0]});
+        $self = tied(@{$_[0]});
+    }
+    elsif (ref(\$_[0]) eq 'GLOB') {
+        $self = tied(*{$_[0]});
     }
     else {
-       $self = tied($_[0]);
+        $self = tied($_[0]);
     }
     return (ref($self) =~ /^yaml_/) ? $self : undef;
 }
@@ -23,17 +29,17 @@ sub new {
     my ($class, $node, $tag) = @_;
     my $self;
     $self->{NODE} = $node;
-    my (undef, $type) = $class->node_info($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'");
+                    ($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];
+        yaml_scalar->new($self, $_[1]);
+        return \ $_[1];
     }
-    my $package = "yaml_" . $self->{KIND};    
+    my $package = "yaml_" . $self->{KIND};
     $package->new($self)
 }
 
@@ -42,8 +48,8 @@ sub kind { $_->{KIND} }
 sub tag {
     my ($self, $value) = @_;
     if (defined $value) {
-               $self->{TAG} = YAML::Tag->new($value);
-       return $self;
+               $self->{TAG} = YAML::Tag->new($value);
+        return $self;
     }
     else {
        return $self->{TAG};
@@ -52,8 +58,8 @@ sub tag {
 sub keys {
     my ($self, $value) = @_;
     if (defined $value) {
-               $self->{KEYS} = $value;
-       return $self;
+               $self->{KEYS} = $value;
+        return $self;
     }
     else {
        return $self->{KEYS};
@@ -62,6 +68,7 @@ sub keys {
 
 #==============================================================================
 package yaml_scalar;
+
 @yaml_scalar::ISA = qw(YAML::Node);
 
 sub new {
@@ -87,6 +94,7 @@ sub STORE {
 
 #==============================================================================
 package yaml_sequence;
+
 @yaml_sequence::ISA = qw(YAML::Node);
 
 sub new {
@@ -120,17 +128,18 @@ sub undone {
     die "Not implemented yet"; # XXX
 }
 
-*STORESIZE = *POP = *PUSH = *SHIFT = *UNSHIFT = *SPLICE = *DELETE = *EXISTS = 
-*STORESIZE = *POP = *PUSH = *SHIFT = *UNSHIFT = *SPLICE = *DELETE = *EXISTS = 
+*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}}; 
+    @{$self->{KEYS}} = sort keys %{$self->{NODE}};
     my $new;
     tie %$new, $class, $self;
     $new
@@ -144,8 +153,8 @@ sub TIEHASH {
 sub FETCH {
     my ($self, $key) = @_;
     if (exists $self->{NODE}{$key}) {
-       return (grep {$_ eq $key} @{$self->{KEYS}}) 
-              ? $self->{NODE}{$key} : undef;
+        return (grep {$_ eq $key} @{$self->{KEYS}})
+               ? $self->{NODE}{$key} : undef;
     }
     return $self->{HASH}{$key};
 }
@@ -153,16 +162,16 @@ sub FETCH {
 sub STORE {
     my ($self, $key, $value) = @_;
     if (exists $self->{NODE}{$key}) {
-       $self->{NODE}{$key} = $value;
+        $self->{NODE}{$key} = $value;
     }
     elsif (exists $self->{HASH}{$key}) {
-       $self->{HASH}{$key} = $value;
+        $self->{HASH}{$key} = $value;
     }
     else {
-       if (not grep {$_ eq $key} @{$self->{KEYS}}) {
-           push(@{$self->{KEYS}}, $key);
-       }
-       $self->{HASH}{$key} = $value;
+        if (not grep {$_ eq $key} @{$self->{KEYS}}) {
+            push(@{$self->{KEYS}}, $key);
+        }
+        $self->{HASH}{$key} = $value;
     }
     $value
 }
@@ -171,15 +180,15 @@ sub DELETE {
     my ($self, $key) = @_;
     my $return;
     if (exists $self->{NODE}{$key}) {
-       $return = $self->{NODE}{$key};
+        $return = $self->{NODE}{$key};
     }
     elsif (exists $self->{HASH}{$key}) {
-       $return = delete $self->{NODE}{$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);
-       }
+        if ($self->{KEYS}[$i] eq $key) {
+            splice(@{$self->{KEYS}}, $i, 1);
+        }
     }
     return $return;
 }
@@ -207,90 +216,3 @@ sub EXISTS {
 }
 
 1;
-
-__END__
-
-=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 <ingy@cpan.org>
-
-=head1 COPYRIGHT
-
-Copyright (c) 2006. Ingy döt Net. All rights reserved.
-Copyright (c) 2002. Brian Ingerson. All rights reserved.
-
-This program is free software; you can redistribute it and/or modify it
-under the same terms as Perl itself.
-
-See L<http://www.perl.com/perl/misc/Artistic.html>
-
-=cut
index a6826fd..57aef46 100644 (file)
@@ -1,5 +1,5 @@
-package YAML::Tag;
 use strict; use warnings;
+package YAML::Tag;
 
 use overload '""' => sub { ${$_[0]} };
 
@@ -17,32 +17,3 @@ sub canonical {
 }
 
 1;
-
-__END__
-
-=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 <ingy@cpan.org>
-
-=head1 COPYRIGHT
-
-Copyright (c) 2006. Ingy döt Net. All rights reserved.
-
-This program is free software; you can redistribute it and/or modify it
-under the same terms as Perl itself.
-
-See L<http://www.perl.com/perl/misc/Artistic.html>
-
-=cut
index 4d737ba..8cbbde2 100644 (file)
@@ -1,17 +1,19 @@
 package YAML::Types;
-use strict; use warnings;
-use YAML::Base; use base 'YAML::Base';
+
+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::Base; # XXX
+
+use YAML::Mo; # XXX
+
 sub yaml_dump {
     my $self = shift;
     my ($value) = @_;
-    my ($class, $type) = YAML::Base->node_info($value);
+    my ($class, $type) = YAML::Mo::Object->node_info($value);
     no strict 'refs';
     my $kind = lc($type) . ':';
     my $tag = ${$class . '::ClassTag'} ||
@@ -24,6 +26,11 @@ sub yaml_dump {
     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);
     }
@@ -31,6 +38,7 @@ sub yaml_dump {
 
 #-------------------------------------------------------------------------------
 package YAML::Type::undef;
+
 sub yaml_dump {
     my $self = shift;
 }
@@ -41,9 +49,14 @@ sub yaml_load {
 
 #-------------------------------------------------------------------------------
 package YAML::Type::glob;
+
 sub yaml_dump {
     my $self = shift;
-    my $ynode = YAML::Node->new({}, '!perl/glob:');
+    # $_[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';
@@ -53,14 +66,13 @@ sub yaml_dump {
                                atime mtime ctime blksize blocks);
                 undef $value;
                 $value->{stat} = YAML::Node->new({});
-                map {$value->{stat}{shift @stats} = $_} stat(*{$_[0]});
-                $value->{fileno} = fileno(*{$_[0]});
-                {
+                if ($value->{fileno} = fileno(*{$_[0]})) {
                     local $^W;
+                    map {$value->{stat}{shift @stats} = $_} stat(*{$_[0]});
                     $value->{tell} = tell(*{$_[0]});
                 }
             }
-            $ynode->{$type} = $value; 
+            $ynode->{$type} = $value;
         }
     }
     return $ynode;
@@ -109,15 +121,17 @@ sub yaml_load {
 
 #-------------------------------------------------------------------------------
 package YAML::Type::code;
-my $dummy_warned = 0; 
+
+my $dummy_warned = 0;
 my $default = '{ "DUMMY" }';
+
 sub yaml_dump {
     my $self = shift;
     my $code;
     my ($dumpflag, $value) = @_;
-    my ($class, $type) = YAML::Base->node_info($value);
-    $class ||= '';
-    my $tag = "!perl/code:$class";
+    my ($class, $type) = YAML::Mo::Object->node_info($value);
+    my $tag = "!perl/code";
+    $tag .= ":$class" if defined $class;
     if (not $dumpflag) {
         $code = $default;
     }
@@ -140,7 +154,7 @@ sub yaml_dump {
     }
     $_[2] = $code;
     YAML::Node->new($_[2], $tag);
-}    
+}
 
 sub yaml_load {
     my $self = shift;
@@ -157,15 +171,17 @@ sub yaml_load {
         }
     }
     else {
+        return CORE::bless sub {}, $class if $class;
         return sub {};
     }
 }
 
 #-------------------------------------------------------------------------------
 package YAML::Type::ref;
+
 sub yaml_dump {
     my $self = shift;
-    YAML::Node->new({(&YAML::VALUE, ${$_[0]})}, '!perl/ref:')
+    YAML::Node->new({(&YAML::VALUE, ${$_[0]})}, '!perl/ref')
 }
 
 sub yaml_load {
@@ -178,85 +194,42 @@ sub yaml_load {
 
 #-------------------------------------------------------------------------------
 package YAML::Type::regexp;
+
 # XXX Be sure to handle blessed regexps (if possible)
 sub yaml_dump {
-    my $self = shift;
-    my ($node, $class, $dumper) = @_;
-    my ($regexp, $modifiers);
-    if ("$node" =~ /^\(\?(\w*)(?:\-\w+)?\:(.*)\)$/) {
-        $regexp = $2;
-        $modifiers = $1 || '';
-    }
-    else {
-        $dumper->die('YAML_DUMP_ERR_BAD_REGEXP', $node);
-    }
-    my $tag = '!perl/regexp:';
-    $tag .= $class if $class;
-    my $ynode = YAML::Node->new({}, $tag);
-    $ynode->{REGEXP} = $regexp; 
-    $ynode->{MODIFIERS} = $modifiers if $modifiers; 
-    return $ynode;
+    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, $loader) = @_;
-    my ($regexp, $modifiers);
-    if (defined $node->{REGEXP}) {
-        $regexp = $node->{REGEXP};
-        delete $node->{REGEXP};
-    }
-    else {
-        $loader->warn('YAML_LOAD_WARN_NO_REGEXP_IN_REGEXP');
-        return undef;
-    }
-    if (defined $node->{MODIFIERS}) {
-        $modifiers = $node->{MODIFIERS};
-        delete $node->{MODIFIERS};
-    }
-    else {
-        $modifiers = '';
-    }
-    for my $elem (sort keys %$node) {
-        $loader->warn('YAML_LOAD_WARN_BAD_REGEXP_ELEM', $elem);
-    }
-    my $qr = $regexp;
-    $qr = "(?$modifiers:$qr)";
-    return qr{$qr};
+    my ($node, $class) = @_;
+    return qr{$node} unless $node =~ /^\(\?([\^\-xism]*):(.*)\)\z/s;
+    my ($flags, $re) = ($1, $2);
+    $flags =~ s/-.*//;
+    $flags =~ s/^\^//;
+    my $sub = _QR_TYPES->{$flags} || sub { qr{$_[0]} };
+    my $qr = &$sub($re);
+    bless $qr, $class if length $class;
+    return $qr;
 }
 
 1;
-
-__END__
-
-=head1 NAME
-
-YAML::Transfer - 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 <ingy@cpan.org>
-
-=head1 COPYRIGHT
-
-Copyright (c) 2006. Ingy döt Net. All rights reserved.
-
-This program is free software; you can redistribute it and/or modify it
-under the same terms as Perl itself.
-
-See L<http://www.perl.com/perl/misc/Artistic.html>
-
-=cut