1 |
argrath |
1.1 |
=head1 NAME |
2 |
|
|
|
3 |
|
|
=begin original |
4 |
|
|
|
5 |
|
|
YAML::Node - A generic data node that encapsulates YAML information |
6 |
|
|
|
7 |
|
|
=end original |
8 |
|
|
|
9 |
ktats |
1.2 |
YAML::Node - YAML 情報をカプセル化する汎用データノード |
10 |
argrath |
1.1 |
|
11 |
|
|
=head1 SYNOPSIS |
12 |
|
|
|
13 |
|
|
use YAML; |
14 |
|
|
use YAML::Node; |
15 |
|
|
|
16 |
|
|
my $ynode = YAML::Node->new({}, 'ingerson.com/fruit'); |
17 |
|
|
%$ynode = qw(orange orange apple red grape green); |
18 |
|
|
print Dump $ynode; |
19 |
|
|
|
20 |
|
|
=begin original |
21 |
|
|
|
22 |
|
|
yields: |
23 |
|
|
|
24 |
|
|
=end original |
25 |
|
|
|
26 |
ktats |
1.2 |
とすると: |
27 |
argrath |
1.1 |
|
28 |
|
|
--- #YAML:1.0 !ingerson.com/fruit |
29 |
|
|
orange: orange |
30 |
|
|
apple: red |
31 |
|
|
grape: green |
32 |
|
|
|
33 |
|
|
=head1 DESCRIPTION |
34 |
|
|
|
35 |
|
|
=begin original |
36 |
|
|
|
37 |
|
|
A generic node in YAML is similar to a plain hash, array, or scalar node |
38 |
|
|
in Perl except that it must also keep track of its type. The type is a |
39 |
|
|
URI called the YAML type family. |
40 |
|
|
|
41 |
|
|
=end original |
42 |
|
|
|
43 |
ktats |
1.2 |
YAML の汎用ノードは Perl での普通のハッシュ、配列、スカラノードと |
44 |
|
|
似ていますが、型を保存しているところが違います。 |
45 |
|
|
この型は YAML 型ファミリと呼ばれる URI です。 |
46 |
argrath |
1.1 |
|
47 |
|
|
=begin original |
48 |
|
|
|
49 |
|
|
YAML::Node is a class for generating and manipulating these containers. |
50 |
|
|
A YAML node (or ynode) is a tied hash, array or scalar. In most ways it |
51 |
|
|
behaves just like the plain thing. But you can assign and retrieve and |
52 |
|
|
YAML type family URI to it. For the hash flavor, you can also assign the |
53 |
|
|
order that the keys will be retrieved in. By default a ynode will offer |
54 |
|
|
its keys in the same order that they were assigned. |
55 |
|
|
|
56 |
|
|
=end original |
57 |
|
|
|
58 |
ktats |
1.2 |
YAML::Node はこれらのコンテナを生成、操作するためのクラスです。 |
59 |
|
|
YAML ノード(ynode)はハッシュ、配列、スカラのいずれかと結び付けられます。 |
60 |
|
|
ほとんどの場合これは普通のものと同じように振る舞います。 |
61 |
|
|
しかし、YAML 型ファミリ URI を割り当てたり所得したりできます。 |
62 |
|
|
ハッシュ用には、キーを取り出す順番を割り当てることもできます。 |
63 |
|
|
デフォルトでは ynode は割り当てられたのと同じ順番で提供されます。 |
64 |
argrath |
1.1 |
|
65 |
|
|
=begin original |
66 |
|
|
|
67 |
|
|
YAML::Node has a class method call new() that will return a ynode. You |
68 |
|
|
pass it a regular node and an optional type family. After that you can |
69 |
|
|
use it like a normal Perl node, but when you YAML::Dump it, the magical |
70 |
|
|
properties will be honored. |
71 |
|
|
|
72 |
|
|
=end original |
73 |
|
|
|
74 |
ktats |
1.2 |
YAML::Node は ynode を返す new() クラスメソッド呼び出しを持ちます。 |
75 |
|
|
引数として通常のノードと、オプションの型ファミリを渡します。 |
76 |
|
|
その後、これを通常の Perl ノードとどう夜につかうことができますが、 |
77 |
|
|
YAML::Dump を使ったときに、秘密のプロパティが効力をもちます。 |
78 |
argrath |
1.1 |
|
79 |
|
|
=begin original |
80 |
|
|
|
81 |
|
|
This is how you can control the sort order of hash keys during a YAML |
82 |
|
|
serialization. By default, YAML sorts keys alphabetically. But notice |
83 |
|
|
in the above example that the keys were Dumped in the same order they |
84 |
|
|
were assigned. |
85 |
|
|
|
86 |
|
|
=end original |
87 |
|
|
|
88 |
ktats |
1.2 |
これが YAML 直列化でハッシュキーのソート順を制御する方法です。 |
89 |
|
|
デフォルトでは、YAML はキーをアルファベット順にソートします。 |
90 |
|
|
しかし、上記の例では、割り当てられたのと同じ順番で Dump されています。 |
91 |
argrath |
1.1 |
|
92 |
|
|
=begin original |
93 |
|
|
|
94 |
|
|
YAML::Node exports a function called ynode(). This function returns the tied object so that you can call special methods on it like ->keys(). |
95 |
|
|
|
96 |
|
|
=end original |
97 |
|
|
|
98 |
ktats |
1.2 |
YAML::Node は ynode() 関数をエクスポートします。 |
99 |
|
|
この関数は結び付けられたオブジェクトを返すので、 |
100 |
|
|
返り値に対して ->keys() のような特別なメソッドを呼び出せます。 |
101 |
argrath |
1.1 |
|
102 |
|
|
=begin original |
103 |
|
|
|
104 |
|
|
keys() works like this: |
105 |
|
|
|
106 |
|
|
=end original |
107 |
|
|
|
108 |
ktats |
1.2 |
keys() は以下のように動作します: |
109 |
argrath |
1.1 |
|
110 |
|
|
use YAML; |
111 |
|
|
use YAML::Node; |
112 |
|
|
|
113 |
|
|
%$node = qw(orange orange apple red grape green); |
114 |
|
|
$ynode = YAML::Node->new($node); |
115 |
|
|
ynode($ynode)->keys(['grape', 'apple']); |
116 |
|
|
print Dump $ynode; |
117 |
|
|
|
118 |
|
|
=begin original |
119 |
|
|
|
120 |
|
|
produces: |
121 |
|
|
|
122 |
|
|
=end original |
123 |
|
|
|
124 |
ktats |
1.2 |
出力は以下のようになります: |
125 |
argrath |
1.1 |
|
126 |
|
|
--- #YAML:1.0 |
127 |
|
|
grape: green |
128 |
|
|
apple: red |
129 |
|
|
|
130 |
|
|
=begin original |
131 |
|
|
|
132 |
|
|
It tells the ynode which keys and what order to use. |
133 |
|
|
|
134 |
|
|
=end original |
135 |
|
|
|
136 |
ktats |
1.2 |
これにより、ynode が どのキーをどのような順番で使うのかがわかります。 |
137 |
argrath |
1.1 |
|
138 |
|
|
=begin original |
139 |
|
|
|
140 |
|
|
ynodes will play a very important role in how programs use YAML. They |
141 |
|
|
are the foundation of how a Perl class can marshall the Loading and |
142 |
|
|
Dumping of its objects. |
143 |
|
|
|
144 |
|
|
=end original |
145 |
|
|
|
146 |
ktats |
1.2 |
ynode は プログラムがどのように YAML を使うかにおいて重要な |
147 |
|
|
役割を演じます。これはオブジェクトを Load したり Dump したりするときに |
148 |
|
|
Perl クラスがどのように整列させるかの基礎となります。 |
149 |
argrath |
1.1 |
|
150 |
|
|
=begin original |
151 |
|
|
|
152 |
|
|
The upcoming versions of YAML.pm will have much more information on this. |
153 |
|
|
|
154 |
|
|
=end original |
155 |
|
|
|
156 |
ktats |
1.2 |
YAML.pm の将来のバージョンではより多くの情報を持つ予定です。 |
157 |
argrath |
1.1 |
|
158 |
|
|
=head1 AUTHOR |
159 |
|
|
|
160 |
|
|
Brian Ingerson <INGY@cpan.org> |
161 |
|
|
|
162 |
|
|
=head1 COPYRIGHT |
163 |
|
|
|
164 |
|
|
Copyright (c) 2002. Brian Ingerson. All rights reserved. |
165 |
|
|
|
166 |
|
|
This program is free software; you can redistribute it and/or modify it |
167 |
|
|
under the same terms as Perl itself. |
168 |
|
|
|
169 |
|
|
See L<http://www.perl.com/perl/misc/Artistic.html> |
170 |
|
|
|