1YAML::Node(3)         User Contributed Perl Documentation        YAML::Node(3)
2
3
4

NAME

6       YAML::Node - A generic data node that encapsulates YAML information
7

SYNOPSIS

9           use YAML;
10           use YAML::Node;
11
12           my $ynode = YAML::Node->new({}, 'ingerson.com/fruit');
13           %$ynode = qw(orange orange apple red grape green);
14           print Dump $ynode;
15
16       yields:
17
18           --- !ingerson.com/fruit
19           orange: orange
20           apple: red
21           grape: green
22

DESCRIPTION

24       A generic node in YAML is similar to a plain hash, array, or scalar
25       node in Perl except that it must also keep track of its type. The type
26       is a URI called the YAML type tag.
27
28       YAML::Node is a class for generating and manipulating these containers.
29       A YAML node (or ynode) is a tied hash, array or scalar. In most ways it
30       behaves just like the plain thing. But you can assign and retrieve and
31       YAML type tag URI to it. For the hash flavor, you can also assign the
32       order that the keys will be retrieved in. By default a ynode will offer
33       its keys in the same order that they were assigned.
34
35       YAML::Node has a class method call new() that will return a ynode. You
36       pass it a regular node and an optional type tag. After that you can use
37       it like a normal Perl node, but when you YAML::Dump it, the magical
38       properties will be honored.
39
40       This is how you can control the sort order of hash keys during a YAML
41       serialization. By default, YAML sorts keys alphabetically. But notice
42       in the above example that the keys were Dumped in the same order they
43       were assigned.
44
45       YAML::Node exports a function called ynode(). This function returns the
46       tied object so that you can call special methods on it like ->keys().
47
48       keys() works like this:
49
50           use YAML;
51           use YAML::Node;
52
53           %$node = qw(orange orange apple red grape green);
54           $ynode = YAML::Node->new($node);
55           ynode($ynode)->keys(['grape', 'apple']);
56           print Dump $ynode;
57
58       produces:
59
60           ---
61           grape: green
62           apple: red
63
64       It tells the ynode which keys and what order to use.
65
66       ynodes will play a very important role in how programs use YAML. They
67       are the foundation of how a Perl class can marshall the Loading and
68       Dumping of its objects.
69
70       The upcoming versions of YAML.pm will have much more information on
71       this.
72

AUTHOR

74       Ingy döt Net <ingy@cpan.org>
75
77       Copyright 2001-2014. Ingy döt Net
78
79       This program is free software; you can redistribute it and/or modify it
80       under the same terms as Perl itself.
81
82       See <http://www.perl.com/perl/misc/Artistic.html>
83
84
85
86perl v5.36.0                      2023-01-20                     YAML::Node(3)
Impressum