<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package YAML::Loader;
use YAML::Mo;
extends 'YAML::Loader::Base';

our $VERSION = '0.84';

use YAML::Loader::Base;
use YAML::Types;

# Context constants
use constant LEAF       =&gt; 1;
use constant COLLECTION =&gt; 2;
use constant VALUE      =&gt; "\x07YAML\x07VALUE\x07";
use constant COMMENT    =&gt; "\x07YAML\x07COMMENT\x07";

# Common YAML character sets
my $ESCAPE_CHAR = '[\\x00-\\x08\\x0b-\\x0d\\x0e-\\x1f]';
my $FOLD_CHAR   = '&gt;';
my $LIT_CHAR    = '|';    
my $LIT_CHAR_RX = "\\$LIT_CHAR";    

sub load {
    my $self = shift;
    $self-&gt;stream($_[0] || '');
    return $self-&gt;_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-&gt;{stream} =~ s|\015\012|\012|g;
    $self-&gt;{stream} =~ s|\015|\012|g;
    $self-&gt;line(0);
    $self-&gt;die('YAML_PARSE_ERR_BAD_CHARS') 
      if $self-&gt;stream =~ /$ESCAPE_CHAR/;
    $self-&gt;die('YAML_PARSE_ERR_NO_FINAL_NEWLINE') 
      if length($self-&gt;stream) and 
         $self-&gt;{stream} !~ s/(.)\n\Z/$1/s;
    $self-&gt;lines([split /\x0a/, $self-&gt;stream, -1]);
    $self-&gt;line(1);
    # Throw away any comments or blanks before the header (or start of
    # content for headerless streams)
    $self-&gt;_parse_throwaway_comments();
    $self-&gt;document(0);
    $self-&gt;documents([]);
    # Add an "assumed" header if there is no header and the stream is
    # not empty (after initial throwaways).
    if (not $self-&gt;eos) {
        if ($self-&gt;lines-&gt;[0] !~ /^---(\s|$)/) {
            unshift @{$self-&gt;lines}, '---';
            $self-&gt;{line}--;
        }
    }

    # Main Loop. Parse out all the top level nodes and return them.
    while (not $self-&gt;eos) {
        $self-&gt;anchor2node({});
        $self-&gt;{document}++;
        $self-&gt;done(0);
        $self-&gt;level(0);
        $self-&gt;offset-&gt;[0] = -1;

        if ($self-&gt;lines-&gt;[0] =~ /^---\s*(.*)$/) {
            my @words = split /\s+/, $1;
            %directives = ();
            while (@words &amp;&amp; $words[0] =~ /^#(\w+):(\S.*)$/) {
                my ($key, $value) = ($1, $2);
                shift(@words);
                if (defined $directives{$key}) {
                    $self-&gt;warn('YAML_PARSE_WARN_MULTIPLE_DIRECTIVES',
                      $key, $self-&gt;document);
                    next;
                }
                $directives{$key} = $value;
            }
            $self-&gt;preface(join ' ', @words);
        }
        else {
            $self-&gt;die('YAML_PARSE_ERR_NO_SEPARATOR');
        }

        if (not $self-&gt;done) {
            $self-&gt;_parse_next_line(COLLECTION);
        }
        if ($self-&gt;done) {
            $self-&gt;{indent} = -1;
            $self-&gt;content('');
        }

        $directives{YAML} ||= '1.0';
        $directives{TAB} ||= 'NONE';
        ($self-&gt;{major_version}, $self-&gt;{minor_version}) = 
          split /\./, $directives{YAML}, 2;
        $self-&gt;die('YAML_PARSE_ERR_BAD_MAJOR_VERSION', $directives{YAML})
          if $self-&gt;major_version ne '1';
        $self-&gt;warn('YAML_PARSE_WARN_BAD_MINOR_VERSION', $directives{YAML})
          if $self-&gt;minor_version ne '0';
        $self-&gt;die('Unrecognized TAB policy')
          unless $directives{TAB} =~ /^(NONE|\d+)(:HARD)?$/;

        push @{$self-&gt;documents}, $self-&gt;_parse_node();
    }
    return wantarray ? @{$self-&gt;documents} : $self-&gt;documents-&gt;[-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-&gt;preface;
    $self-&gt;preface('');
    my ($node, $type, $indicator, $escape, $chomp) = ('') x 5;
    my ($anchor, $alias, $explicit, $implicit, $class) = ('') x 5;
    ($anchor, $alias, $explicit, $implicit, $preface) = 
      $self-&gt;_parse_qualifiers($preface);
    if ($anchor) {
        $self-&gt;anchor2node-&gt;{$anchor} = CORE::bless [], 'YAML-anchor2node';
    }
    $self-&gt;inline('');
    while (length $preface) {
        my $line = $self-&gt;line - 1;
        if ($preface =~ s/^($FOLD_CHAR|$LIT_CHAR_RX)(-|\+)?\d*\s*//) { 
            $indicator = $1;
            $chomp = $2 if defined($2);
        }
        else {
            $self-&gt;die('YAML_PARSE_ERR_TEXT_AFTER_INDICATOR') if $indicator;
            $self-&gt;inline($preface);
            $preface = '';
        }
    }
    if ($alias) {
        $self-&gt;die('YAML_PARSE_ERR_NO_ANCHOR', $alias)
          unless defined $self-&gt;anchor2node-&gt;{$alias};
        if (ref($self-&gt;anchor2node-&gt;{$alias}) ne 'YAML-anchor2node') {
            $node = $self-&gt;anchor2node-&gt;{$alias};
        }
        else {
            $node = do {my $sv = "*$alias"};
            push @{$self-&gt;anchor2node-&gt;{$alias}}, [\$node, $self-&gt;line]; 
        }
    }
    elsif (length $self-&gt;inline) {
        $node = $self-&gt;_parse_inline(1, $implicit, $explicit);
        if (length $self-&gt;inline) {
            $self-&gt;die('YAML_PARSE_ERR_SINGLE_LINE'); 
        }
    }
    elsif ($indicator eq $LIT_CHAR) {
        $self-&gt;{level}++;
        $node = $self-&gt;_parse_block($chomp);
        $node = $self-&gt;_parse_implicit($node) if $implicit;
        $self-&gt;{level}--; 
    }
    elsif ($indicator eq $FOLD_CHAR) {
        $self-&gt;{level}++;
        $node = $self-&gt;_parse_unfold($chomp);
        $node = $self-&gt;_parse_implicit($node) if $implicit;
        $self-&gt;{level}--;
    }
    else {
        $self-&gt;{level}++;
        $self-&gt;offset-&gt;[$self-&gt;level] ||= 0;
        if ($self-&gt;indent == $self-&gt;offset-&gt;[$self-&gt;level]) {
            if ($self-&gt;content =~ /^-( |$)/) {
                $node = $self-&gt;_parse_seq($anchor);
            }
            elsif ($self-&gt;content =~ /(^\?|\:( |$))/) {
                $node = $self-&gt;_parse_mapping($anchor);
            }
            elsif ($preface =~ /^\s*$/) {
                $node = $self-&gt;_parse_implicit('');
            }
            else {
                $self-&gt;die('YAML_PARSE_ERR_BAD_NODE');
            }
        }
        else {
            $node = undef;
        }
        $self-&gt;{level}--;
    }
    $#{$self-&gt;offset} = $self-&gt;level;

    if ($explicit) {
        if ($class) {
            if (not ref $node) {
                my $copy = $node;
                undef $node;
                $node = \$copy;
            }
            CORE::bless $node, $class;
        }
        else {
            $node = $self-&gt;_parse_explicit($node, $explicit);
        }
    }
    if ($anchor) {
        if (ref($self-&gt;anchor2node-&gt;{$anchor}) eq 'YAML-anchor2node') {
            # XXX Can't remember what this code actually does
            for my $ref (@{$self-&gt;anchor2node-&gt;{$anchor}}) {
                ${$ref-&gt;[0]} = $node;
                $self-&gt;warn('YAML_LOAD_WARN_UNRESOLVED_ALIAS',
                    $anchor, $ref-&gt;[1]);
            }
        }
        $self-&gt;anchor2node-&gt;{$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-&gt;inline('');
    while ($preface =~ /^[&amp;*!]/) {
        my $line = $self-&gt;line - 1;
        if ($preface =~ s/^\!(\S+)\s*//) {
            $self-&gt;die('YAML_PARSE_ERR_MANY_EXPLICIT') if $explicit;
            $explicit = $1;
        }
        elsif ($preface =~ s/^\!\s*//) {
            $self-&gt;die('YAML_PARSE_ERR_MANY_IMPLICIT') if $implicit;
            $implicit = 1;
        }
        elsif ($preface =~ s/^\&amp;([^ ,:]+)\s*//) {
            $token = $1;
            $self-&gt;die('YAML_PARSE_ERR_BAD_ANCHOR') 
              unless $token =~ /^[a-zA-Z0-9]+$/;
            $self-&gt;die('YAML_PARSE_ERR_MANY_ANCHOR') if $anchor;
            $self-&gt;die('YAML_PARSE_ERR_ANCHOR_ALIAS') if $alias;
            $anchor = $token;
        }
        elsif ($preface =~ s/^\*([^ ,:]+)\s*//) {
            $token = $1;
            $self-&gt;die('YAML_PARSE_ERR_BAD_ALIAS')
              unless $token =~ /^[a-zA-Z0-9]+$/;
            $self-&gt;die('YAML_PARSE_ERR_MANY_ALIAS') if $alias;
            $self-&gt;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-&gt;die('YAML_LOAD_ERR_NO_DEFAULT_VALUE', 'XXX', $explicit)
            unless exists $node-&gt;{VALUE()} and scalar(keys %$node) == 1;

            my $value = $node-&gt;{VALUE()};
            $node = \$value;
        }
        
        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 =~ m{^!?perl/(glob|regexp|code)(?:\:(\w(\w|\:\:)*)?)?$}) {
        ($type, $class) = (($1 || ''), ($2 || ''));
        my $type_class = "YAML::Type::$type";
        no strict 'refs';
        if ($type_class-&gt;can('yaml_load')) {
            return $type_class-&gt;yaml_load($node, $class, $self);
        }
        else {
            $self-&gt;die('YAML_LOAD_ERR_NO_CONVERT', 'XXX', $explicit);
        }
    }
    # This !perl/@Foo and !perl/$Foo are deprecated but still parsed
    elsif ($YAML::TagClass-&gt;{$explicit} ||
           $explicit =~ m{^perl/(\@|\$)?([a-zA-Z](\w|::)+)$}
          ) {
        $class = $YAML::TagClass-&gt;{$explicit} || $2;
        if ($class-&gt;can('yaml_load')) {
            require YAML::Node;
            return $class-&gt;yaml_load(YAML::Node-&gt;new($node, $explicit));
        }
        else {
            if (ref $node) {
                return CORE::bless $node, $class;
            }
            else {
                return CORE::bless \$node, $class;
            }
        }
    }
    elsif (ref $node) {
        require YAML::Node;
        return YAML::Node-&gt;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-&gt;anchor2node-&gt;{$anchor} = $mapping;
    my $key;
    while (not $self-&gt;done and $self-&gt;indent == $self-&gt;offset-&gt;[$self-&gt;level]) {
        # If structured key:
        if ($self-&gt;{content} =~ s/^\?\s*//) {
            $self-&gt;preface($self-&gt;content);
            $self-&gt;_parse_next_line(COLLECTION);
            $key = $self-&gt;_parse_node();
            $key = "$key";
        }
        # If "default" key (equals sign) 
        elsif ($self-&gt;{content} =~ s/^\=\s*//) {
            $key = VALUE;
        }
        # If "comment" key (slash slash)
        elsif ($self-&gt;{content} =~ s/^\=\s*//) {
            $key = COMMENT;
        }
        # Regular scalar key:
        else {
            $self-&gt;inline($self-&gt;content);
            $key = $self-&gt;_parse_inline();
            $key = "$key";
            $self-&gt;content($self-&gt;inline);
            $self-&gt;inline('');
        }
            
        unless ($self-&gt;{content} =~ s/^:\s*//) {
            $self-&gt;die('YAML_LOAD_ERR_BAD_MAP_ELEMENT');
        }
        $self-&gt;preface($self-&gt;content);
        my $line = $self-&gt;line;
        $self-&gt;_parse_next_line(COLLECTION);
        my $value = $self-&gt;_parse_node();
        if (exists $mapping-&gt;{$key}) {
            $self-&gt;warn('YAML_LOAD_WARN_DUPLICATE_KEY');
        }
        else {
            $mapping-&gt;{$key} = $value;
        }
    }
    return $mapping;
}

# Parse a YAML sequence into a Perl array
sub _parse_seq {
    my $self = shift;
    my ($anchor) = @_;
    my $seq = [];
    $self-&gt;anchor2node-&gt;{$anchor} = $seq;
    while (not $self-&gt;done and $self-&gt;indent == $self-&gt;offset-&gt;[$self-&gt;level]) {
        if ($self-&gt;content =~ /^-(?: (.*))?$/) {
            $self-&gt;preface(defined($1) ? $1 : '');
        }
        else {
            $self-&gt;die('YAML_LOAD_ERR_BAD_SEQ_ELEMENT');
        }
        if ($self-&gt;preface =~ /^(\s*)(\w.*\:(?: |$).*)$/) {
            $self-&gt;indent($self-&gt;offset-&gt;[$self-&gt;level] + 2 + length($1));
            $self-&gt;content($2);
            $self-&gt;level($self-&gt;level + 1);
            $self-&gt;offset-&gt;[$self-&gt;level] = $self-&gt;indent;
            $self-&gt;preface('');
            push @$seq, $self-&gt;_parse_mapping('');
            $self-&gt;{level}--;
            $#{$self-&gt;offset} = $self-&gt;level;
        }
        else {
            $self-&gt;_parse_next_line(COLLECTION);
            push @$seq, $self-&gt;_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-&gt;{inline} =~ s/^\s*(.*)\s*$/$1/; # OUCH - mugwump
    my ($node, $anchor, $alias, $explicit, $implicit) = ('') x 5;
    ($anchor, $alias, $explicit, $implicit, $self-&gt;{inline}) = 
      $self-&gt;_parse_qualifiers($self-&gt;inline);
    if ($anchor) {
        $self-&gt;anchor2node-&gt;{$anchor} = CORE::bless [], 'YAML-anchor2node';
    }
    $implicit ||= $top_implicit;
    $explicit ||= $top_explicit;
    ($top_implicit, $top_explicit) = ('', '');
    if ($alias) {
        $self-&gt;die('YAML_PARSE_ERR_NO_ANCHOR', $alias)
          unless defined $self-&gt;anchor2node-&gt;{$alias};
        if (ref($self-&gt;anchor2node-&gt;{$alias}) ne 'YAML-anchor2node') {
            $node = $self-&gt;anchor2node-&gt;{$alias};
        }
        else {
            $node = do {my $sv = "*$alias"};
            push @{$self-&gt;anchor2node-&gt;{$alias}}, [\$node, $self-&gt;line]; 
        }
    }
    elsif ($self-&gt;inline =~ /^\{/) {
        $node = $self-&gt;_parse_inline_mapping($anchor);
    }
    elsif ($self-&gt;inline =~ /^\[/) {
        $node = $self-&gt;_parse_inline_seq($anchor);
    }
    elsif ($self-&gt;inline =~ /^"/) {
        $node = $self-&gt;_parse_inline_double_quoted();
        $node = $self-&gt;_unescape($node);
        $node = $self-&gt;_parse_implicit($node) if $implicit;
    }
    elsif ($self-&gt;inline =~ /^'/) {
        $node = $self-&gt;_parse_inline_single_quoted();
        $node = $self-&gt;_parse_implicit($node) if $implicit;
    }
    else {
        if ($top) {
            $node = $self-&gt;inline;
            $self-&gt;inline('');
        }
        else {
            $node = $self-&gt;_parse_inline_simple();
        }
        $node = $self-&gt;_parse_implicit($node) unless $explicit;
    }
    if ($explicit) {
        $node = $self-&gt;_parse_explicit($node, $explicit);
    }
    if ($anchor) {
        if (ref($self-&gt;anchor2node-&gt;{$anchor}) eq 'YAML-anchor2node') {
            for my $ref (@{$self-&gt;anchor2node-&gt;{$anchor}}) {
                ${$ref-&gt;[0]} = $node;
                $self-&gt;warn('YAML_LOAD_WARN_UNRESOLVED_ALIAS',
                    $anchor, $ref-&gt;[1]);
            }
        }
        $self-&gt;anchor2node-&gt;{$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-&gt;anchor2node-&gt;{$anchor} = $node;

    $self-&gt;die('YAML_PARSE_ERR_INLINE_MAP')
      unless $self-&gt;{inline} =~ s/^\{\s*//;
    while (not $self-&gt;{inline} =~ s/^\s*\}//) {
        my $key = $self-&gt;_parse_inline();
        $self-&gt;die('YAML_PARSE_ERR_INLINE_MAP')
          unless $self-&gt;{inline} =~ s/^\: \s*//;
        my $value = $self-&gt;_parse_inline();
        if (exists $node-&gt;{$key}) {
            $self-&gt;warn('YAML_LOAD_WARN_DUPLICATE_KEY');
        }
        else {
            $node-&gt;{$key} = $value;
        }
        next if $self-&gt;inline =~ /^\s*\}/;
        $self-&gt;die('YAML_PARSE_ERR_INLINE_MAP')
          unless $self-&gt;{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-&gt;anchor2node-&gt;{$anchor} = $node;

    $self-&gt;die('YAML_PARSE_ERR_INLINE_SEQUENCE')
      unless $self-&gt;{inline} =~ s/^\[\s*//;
    while (not $self-&gt;{inline} =~ s/^\s*\]//) {
        my $value = $self-&gt;_parse_inline();
        push @$node, $value;
        next if $self-&gt;inline =~ /^\s*\]/;
        $self-&gt;die('YAML_PARSE_ERR_INLINE_SEQUENCE') 
          unless $self-&gt;{inline} =~ s/^\,\s*//;
    }
    return $node;
}

# Parse the inline double quoted string.
sub _parse_inline_double_quoted {
    my $self = shift;
    my $node;
    if ($self-&gt;inline =~ /^"((?:\\"|[^"])*)"\s*(.*)$/) {
        $node = $1;
        $self-&gt;inline($2);
        $node =~ s/\\"/"/g;
    }
    else {
        $self-&gt;die('YAML_PARSE_ERR_BAD_DOUBLE');
    }
    return $node;
}


# Parse the inline single quoted string.
sub _parse_inline_single_quoted {
    my $self = shift;
    my $node;
    if ($self-&gt;inline =~ /^'((?:''|[^'])*)'\s*(.*)$/) {
        $node = $1;
        $self-&gt;inline($2);
        $node =~ s/''/'/g;
    }
    else {
        $self-&gt;die('YAML_PARSE_ERR_BAD_SINGLE');
    }
    return $node;
}

# Parse the inline unquoted string and do implicit typing.
sub _parse_inline_simple {
    my $self = shift;
    my $value;
    if ($self-&gt;inline =~ /^(|[^!@#%^&amp;*].*?)(?=[\[\]\{\},]|, |: |- |:\s*$|$)/) {
        $value = $1;
        substr($self-&gt;{inline}, 0, length($1)) = '';
    }
    else {
        $self-&gt;die('YAML_PARSE_ERR_BAD_INLINE_IMPLICIT', $value);
    }
    return $value;
}

sub _parse_implicit {
    my $self = shift;
    my ($value) = @_;
    $value =~ s/\s*$//;
    return $value if $value eq '';
    return undef if $value =~ /^~$/;
    return $value
      unless $value =~ /^[\@\`\^]/ or
             $value =~ /^[\-\?]\s/;
    $self-&gt;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-&gt;done and $self-&gt;indent == $self-&gt;offset-&gt;[$self-&gt;level]) {
        $node .= $self-&gt;content. "\n";
        $self-&gt;_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-&gt;done and $self-&gt;indent == $self-&gt;offset-&gt;[$self-&gt;level]) {
        $node .= $self-&gt;content . "\n";
        $self-&gt;_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-&gt;lines} and
           $self-&gt;lines-&gt;[0] =~ m{^\s*(\#|$)}
          ) {
        shift @{$self-&gt;lines};
        $self-&gt;{line}++;
    }
    $self-&gt;eos($self-&gt;{done} = not @{$self-&gt;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-&gt;indent, $self-&gt;content, $self-&gt;line
# 4) Expand tabs appropriately  
sub _parse_next_line {
    my $self = shift;
    my ($type) = @_;
    my $level = $self-&gt;level;
    my $offset = $self-&gt;offset-&gt;[$level];
    $self-&gt;die('YAML_EMIT_ERR_BAD_LEVEL') unless defined $offset;
    shift @{$self-&gt;lines};
    $self-&gt;eos($self-&gt;{done} = not @{$self-&gt;lines});
    return if $self-&gt;eos;
    $self-&gt;{line}++;

    # Determine the offset for a new leaf node
    if ($self-&gt;preface =~
        qr/(?:^|\s)(?:$FOLD_CHAR|$LIT_CHAR_RX)(?:-|\+)?(\d*)\s*$/
       ) {
        $self-&gt;die('YAML_PARSE_ERR_ZERO_INDENT')
          if length($1) and $1 == 0;
        $type = LEAF;
        if (length($1)) {
            $self-&gt;offset-&gt;[$level + 1] = $offset + $1;
        }
        else {
            # First get rid of any comments.
            while (@{$self-&gt;lines} &amp;&amp; ($self-&gt;lines-&gt;[0] =~ /^\s*#/)) {
                $self-&gt;lines-&gt;[0] =~ /^( *)/ or die;
                last unless length($1) &lt;= $offset;
                shift @{$self-&gt;lines};
                $self-&gt;{line}++;
            }
            $self-&gt;eos($self-&gt;{done} = not @{$self-&gt;lines});
            return if $self-&gt;eos;
            if ($self-&gt;lines-&gt;[0] =~ /^( *)\S/ and length($1) &gt; $offset) {
                $self-&gt;offset-&gt;[$level+1] = length($1);
            }
            else {
                $self-&gt;offset-&gt;[$level+1] = $offset + 1;
            }
        }
        $offset = $self-&gt;offset-&gt;[++$level];
    }
    # Determine the offset for a new collection level
    elsif ($type == COLLECTION and 
           $self-&gt;preface =~ /^(\s*(\!\S*|\&amp;\S+))*\s*$/) {
        $self-&gt;_parse_throwaway_comments();
        if ($self-&gt;eos) {
            $self-&gt;offset-&gt;[$level+1] = $offset + 1;
            return;
        }
        else {
            $self-&gt;lines-&gt;[0] =~ /^( *)\S/ or die;
            if (length($1) &gt; $offset) {
                $self-&gt;offset-&gt;[$level+1] = length($1);
            }
            else {
                $self-&gt;offset-&gt;[$level+1] = $offset + 1;
            }
        }
        $offset = $self-&gt;offset-&gt;[++$level];
    }
        
    if ($type == LEAF) {
        while (@{$self-&gt;lines} and
               $self-&gt;lines-&gt;[0] =~ m{^( *)(\#)} and
               length($1) &lt; $offset
              ) {
            shift @{$self-&gt;lines};
            $self-&gt;{line}++;
        }
        $self-&gt;eos($self-&gt;{done} = not @{$self-&gt;lines});
    }
    else {
        $self-&gt;_parse_throwaway_comments();
    }
    return if $self-&gt;eos; 
    
    if ($self-&gt;lines-&gt;[0] =~ /^---(\s|$)/) {
        $self-&gt;done(1);
        return;
    }
    if ($type == LEAF and 
        $self-&gt;lines-&gt;[0] =~ /^ {$offset}(.*)$/
       ) {
        $self-&gt;indent($offset);
        $self-&gt;content($1);
    }
    elsif ($self-&gt;lines-&gt;[0] =~ /^\s*$/) {
        $self-&gt;indent($offset);
        $self-&gt;content('');
    }
    else {
        $self-&gt;lines-&gt;[0] =~ /^( *)(\S.*)$/;
        while ($self-&gt;offset-&gt;[$level] &gt; length($1)) {
            $level--;
        }
        $self-&gt;die('YAML_PARSE_ERR_INCONSISTENT_INDENTATION') 
          if $self-&gt;offset-&gt;[$level] != length($1);
        $self-&gt;indent(length($1));
        $self-&gt;content($2);
    }
    $self-&gt;die('YAML_PARSE_ERR_INDENTATION')
      if $self-&gt;indent - $offset &gt; 1;
}

#==============================================================================
# Utility subroutines.
#==============================================================================

# Printable characters for escapes
my %unescapes = (
   0 =&gt; "\x00",
   a =&gt; "\x07",
   t =&gt; "\x09",
   n =&gt; "\x0a",
   'v' =&gt; "\x0b", # Potential v-string error on 5.6.2 if not quoted
   f =&gt; "\x0c",
   r =&gt; "\x0d",
   e =&gt; "\x1b",
   '\\' =&gt; '\\',
  );
   
# 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)&gt;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-&gt;new;
    my $hash = $loader-&gt;load(&lt;&lt;'...');
    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 &lt;ingy@cpan.org&gt;

=head1 COPYRIGHT

Copyright (c) 2006, 2011-2012. 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&lt;http://www.perl.com/perl/misc/Artistic.html&gt;

=cut
</pre></body></html>